Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[TwigBridge] fixes TranslationDefaultDomainNodeVisitor #7281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

jfsimon
Copy link
Contributor

@jfsimon jfsimon commented Mar 6, 2013

... by adding scope management.

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #6747

*/
public function get($key, $default = null)
{
if (isset($this->data[$key])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be array_key_exists as the value could be null as in TranslationDefaultDomainNodeVisitor below

@vicb
Copy link
Contributor

vicb commented Mar 6, 2013

Are open and close good names ? I would prefer addChild and getParent as there is nothing that is really opened or closed ?

Edit: by looking at the code a second time, I think open & close make sense .

@jfsimon
Copy link
Contributor Author

jfsimon commented Mar 7, 2013

@vicb I know this is not consistent with the rest of the framework.
I dont think @fabpot will like them.

@stof
Copy link
Member

stof commented Mar 7, 2013

what about enter and leave ? It would be consistent with the naming used for scopes in the DI component


return new \Twig_Node_Set(false, new \Twig_Node(array($name)), new \Twig_Node(array($node->getNode('expr'))), $node->getLine());
}
}

if (null === $this->domain) {
$domain = $this->scope->get('domain');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

->has ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why has?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for @vicb

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@francisbesset I'll change it just for you <3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jfsimon ❤️

@vicb
Copy link
Contributor

vicb commented Mar 7, 2013

@stof I like your proposal. My main concern being "leave" (former "close"), @jfsimon could you throw when a scope is used after it has been left ?

@jfsimon
Copy link
Contributor Author

jfsimon commented Mar 7, 2013

go for enter/leave, but why throwing an exception on using a leaved scope?

@vicb
Copy link
Contributor

vicb commented Mar 7, 2013

because if you have a ref to a left scope, you can still use it which is bad

fabpot added a commit that referenced this pull request Mar 12, 2013
This PR was squashed before being merged into the 2.1 branch (closes #7281).

Commits
-------

e3547c6 [TwigBridge] fixes

Discussion
----------

[TwigBridge] fixes `TranslationDefaultDomainNodeVisitor`

... by adding scope management.

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #6747

---------------------------------------------------------------------------

by vicb at 2013-03-06T15:14:57Z

Are `open` and `close` good names ? I would prefer `addChild` and `getParent` as there is nothing that is really opened or closed ?

Edit: by looking at the code a second time, I think open & close make sense .

---------------------------------------------------------------------------

by jfsimon at 2013-03-07T13:46:13Z

@vicb I know this is not consistent with the rest of the framework.
I dont think @fabpot will like them.

---------------------------------------------------------------------------

by stof at 2013-03-07T13:53:14Z

what about enter and leave ? It would be consistent with the naming used for scopes in the DI component

---------------------------------------------------------------------------

by vicb at 2013-03-07T13:59:35Z

@stof I like your proposal. My main concern being "leave" (former "close"), @jfsimon could you throw when a scope is used after it has been left ?

---------------------------------------------------------------------------

by jfsimon at 2013-03-07T14:01:56Z

go for enter/leave, but why throwing an exception on using a leaved scope?

---------------------------------------------------------------------------

by vicb at 2013-03-07T14:05:22Z

because if you have a ref to a left scope, you can still use it which is bad
@fabpot fabpot closed this Mar 12, 2013
@lenardpalko
Copy link

I'm getting this error after upgrading to latest version. Seems that this pull request is doing harm. Am I missing something?

ErrorException: Warning: array_key_exists() expects parameter 2 to be array, null given in /home/lpalko/sites/itg/www/vendor/symfony/symfony/src/Symfony/Bridge/Twig/NodeVisitor/Scope.php line 94

@stof
Copy link
Member

stof commented Mar 12, 2013

@lenardpalko there is already a pending PR fixing the issue

@lenardpalko
Copy link

Thanks. I've added the patch manually until it will be merged.
But now the default domain for translations is not working, I have to manually specify the translation domain for twig "trans".
Do I have to configure something needed by this PR?

@lenardpalko
Copy link

This is the error I get if I don't add explicitly a domain for trans:

Argument 1 passed to Twig_Compiler::subcompile() must implement interface Twig_NodeInterface, null given, called in .../vendor/twig/twig/lib/Twig/Node/Expression/Call.php on line 85 and defined in .../vendor/twig/twig/lib/Twig/Compiler.php on line 91

@jfsimon
Copy link
Contributor Author

jfsimon commented Mar 12, 2013

@lenardpalko could you open a new issue and add some info (the stack trace or a reproductible scenario)?

if ($node instanceof \Twig_Node_Module) {
$this->domain = null;
$this->scope->set('domain', null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jfsimon I think the issue might be here: you are setting it to null, but then, the corresponding code was previously null === $this->domain and is now replaced by !$this->scope->has('domain') (which is false as it has a null value)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof exact, thanks!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But array_key_exists() used by Scope::has($key) also returns true if the value is null? I thought that this is the reason for not using isset()?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have read it twice. Sorry. Is somebody working on this? Otherwise I would build a PR for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lennerd the problem was here: jfsimon@fe4cc24#L0R37 ;)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. With the new scope, every variable in the scope defaults to null. Thanks for the hint. ;)

@tammyd
Copy link
Contributor

tammyd commented Mar 12, 2013

Just a note that I'm also having this issue, and had to set my version of Symfony to 2.1.8 (vs 2.1.*) until this is accepted.

fabpot added a commit that referenced this pull request Mar 12, 2013
This PR was merged into the 2.1 branch.

Commits
-------

5ad4bd1 [TwigBridge] now enter/leave scope on Twig_Node_Module
fe4cc24 [TwigBridge] fixed fixed scope & trans_default_domain node visitor
c5e999a [TwigBridge] fixed non probant tests & added new one

Discussion
----------

[TwigBundle] fixes errors with the default domain node visitor & scope

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #7281

---------------------------------------------------------------------------

by Julien-Webgenery at 2013-03-12T16:35:58Z

:+1:

---------------------------------------------------------------------------

by lennerd at 2013-03-12T16:38:40Z

:+1:

---------------------------------------------------------------------------

by rc2c at 2013-03-12T16:53:04Z

:+1:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants