* 1.4.0
+ * fixed the "defined" test and the "default" filter (now works with more than one call (foo.bar.foo) and for both values of the strict_variables option)
* changed the way extensions are loaded (addFilter/addFunction/addGlobal/addTest/addNodeVisitor/addTokenParser/addExtension can now be called in any order)
* added Twig_Environment::display()
* made the escape filter smarter when the encoding is not supported by PHP
{
public function __construct(Twig_Node_Expression $node, Twig_Node_Expression $attribute, Twig_NodeInterface $arguments, $type, $lineno)
{
- parent::__construct(array('node' => $node, 'attribute' => $attribute, 'arguments' => $arguments), array('type' => $type, 'is_defined_test' => false), $lineno);
+ parent::__construct(array('node' => $node, 'attribute' => $attribute, 'arguments' => $arguments), array('type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false), $lineno);
}
public function compile(Twig_Compiler $compiler)
{
$compiler->raw('$this->getAttribute(');
- if ($this->getAttribute('is_defined_test')) {
+ if ($this->getAttribute('ignore_strict_check')) {
$this->getNode('node')->setAttribute('ignore_strict_check', true);
}
$compiler->raw(', ')->subcompile($this->getNode('attribute'));
- if (count($this->getNode('arguments')) || Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test')) {
+ if (count($this->getNode('arguments')) || Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
$compiler->raw(', array(');
foreach ($this->getNode('arguments') as $node) {
$compiler->raw(')');
- if (Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test')) {
+ if (Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
$compiler->raw(', ')->repr($this->getAttribute('type'));
}
- if ($this->getAttribute('is_defined_test')) {
- $compiler->raw(', true');
+ if ($this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
+ $compiler->raw(', '.($this->getAttribute('is_defined_test') ? 'true' : 'false'));
+ }
+
+ if ($this->getAttribute('ignore_strict_check')) {
+ $compiler->raw(', '.($this->getAttribute('ignore_strict_check') ? 'true' : 'false'));
}
}
if ($node instanceof Twig_Node_Expression_Name) {
$node->setAttribute('is_defined_test', true);
} elseif ($node instanceof Twig_Node_Expression_GetAttr) {
- $this->changeIsDefined($node);
+ $node->setAttribute('is_defined_test', true);
+
+ $this->changeIgnoreStrictCheck($node);
} else {
throw new Twig_Error_Syntax('The "defined" test only works with simple variables', $this->getLine());
}
}
}
- protected function changeIsDefined(Twig_Node_Expression_GetAttr $node)
+ protected function changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node)
{
- $node->setAttribute('is_defined_test', true);
+ $node->setAttribute('ignore_strict_check', true);
if ($node->getNode('node') instanceof Twig_Node_Expression_GetAttr) {
- $this->changeIsDefined($node->getNode('node'));
+ $this->changeIgnoreStrictCheck($node->getNode('node'));
+ }
+
+ if (count($node->getNode('arguments'))) {
+ throw new Twig_Error_Syntax('The "defined" test only works with simple variables', $this->getLine());
}
}
* @param string $type The type of attribute (@see Twig_TemplateInterface)
* @param Boolean $isDefinedTest Whether this is only a defined check
*/
- protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $isDefinedTest = false)
+ protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
{
// array
if (Twig_TemplateInterface::METHOD_CALL !== $type) {
return false;
}
- if (!$this->env->isStrictVariables()) {
+ if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
return null;
}
return false;
}
- if (!$this->env->isStrictVariables()) {
+ if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
return null;
}
return false;
}
- if (!$this->env->isStrictVariables()) {
+ if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
return null;
}
{
}
- public function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $isDefinedTest = false)
+ public function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
{
- return parent::getAttribute($object, $item, $arguments, $type, $isDefinedTest);
+ return parent::getAttribute($object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck);
}
}