-
-
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
|
||
namespace Symfony\Bridge\Twig\NodeVisitor; | ||
|
||
/** | ||
* @author Jean-François Simon <[email protected]> | ||
*/ | ||
class Scope | ||
{ | ||
/** | ||
* @var Scope|null | ||
*/ | ||
private $parent; | ||
|
||
/** | ||
* @var Scope[] | ||
*/ | ||
private $children; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $data; | ||
|
||
/** | ||
* @var boolean | ||
*/ | ||
private $left; | ||
|
||
/** | ||
* @param Scope $parent | ||
*/ | ||
public function __construct(Scope $parent = null) | ||
{ | ||
$this->parent = $parent; | ||
$this->left = false; | ||
} | ||
|
||
/** | ||
* Opens a new child scope. | ||
* | ||
* @return Scope | ||
*/ | ||
public function enter() | ||
{ | ||
$child = new self($this); | ||
$this->children[] = $child; | ||
|
||
return $child; | ||
} | ||
|
||
/** | ||
* Closes current scope and returns parent one. | ||
* | ||
* @return Scope|null | ||
*/ | ||
public function leave() | ||
{ | ||
$this->left = true; | ||
|
||
return $this->parent; | ||
} | ||
|
||
/** | ||
* Stores data into current scope. | ||
* | ||
* @param string $key | ||
* @param mixed $value | ||
* | ||
* @throws \LogicException | ||
* | ||
* @return Scope Current scope | ||
*/ | ||
public function set($key, $value) | ||
{ | ||
if ($this->left) { | ||
throw new \LogicException('Left scope is not mutable.'); | ||
} | ||
|
||
$this->data[$key] = $value; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Tests if a data is visible from current scope. | ||
* | ||
* @param string $key | ||
* | ||
* @return boolean | ||
*/ | ||
public function has($key) | ||
{ | ||
if (array_key_exists($key, $this->data)) { | ||
return true; | ||
} | ||
|
||
if (null === $this->parent) { | ||
return false; | ||
} | ||
|
||
return $this->parent->has($key); | ||
} | ||
|
||
/** | ||
* Returns data visible from current scope. | ||
* | ||
* @param string $key | ||
* @param mixed $default | ||
* | ||
* @return mixed | ||
*/ | ||
public function get($key, $default = null) | ||
{ | ||
if (array_key_exists($key, $this->data)) { | ||
return $this->data[$key]; | ||
} | ||
|
||
if (null === $this->parent) { | ||
return $default; | ||
} | ||
|
||
return $this->parent->get($key, $default); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 previouslynull === $this->domain
and is now replaced by!$this->scope->has('domain')
(which is false as it has anull
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 byScope::has($key)
also returns true if the value is null? I thought that this is the reason for not usingisset()
?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. ;)