-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
*/ | ||
public function get($key, $default = null) | ||
{ | ||
if (isset($this->data[$key])) { |
There was a problem hiding this comment.
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
Are Edit: by looking at the code a second time, I think open & close make sense . |
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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
->has ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why has
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for @vicb
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jfsimon ❤️
go for enter/leave, but why throwing an exception on using a leaved scope? |
because if you have a ref to a left scope, you can still use it which is bad |
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
I'm getting this error after upgrading to latest version. Seems that this pull request is doing harm. Am I missing something?
|
@lenardpalko there is already a pending PR fixing the issue |
Thanks. I've added the patch manually until it will be merged. |
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 |
@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); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stof exact, thanks!
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ;)
There was a problem hiding this comment.
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. ;)
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. |
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:
... by adding scope management.