4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Bridge\Twig\NodeVisitor
;
15 * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
40 * @param Scope $parent
42 public function __construct(Scope
$parent = null)
44 $this->parent
= $parent;
46 $this->data
= array();
50 * Opens a new child scope.
54 public function enter()
56 $child = new self($this);
57 $this->children
[] = $child;
63 * Closes current scope and returns parent one.
67 public function leave()
75 * Stores data into current scope.
80 * @throws \LogicException
82 * @return Scope Current scope
84 public function set($key, $value)
87 throw new \
LogicException('Left scope is not mutable.');
90 $this->data
[$key] = $value;
96 * Tests if a data is visible from current scope.
102 public function has($key)
104 if (array_key_exists($key, $this->data
)) {
108 if (null === $this->parent
) {
112 return $this->parent
->has($key);
116 * Returns data visible from current scope.
119 * @param mixed $default
123 public function get($key, $default = null)
125 if (array_key_exists($key, $this->data
)) {
126 return $this->data
[$key];
129 if (null === $this->parent
) {
133 return $this->parent
->get($key, $default);