mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 20:43:25 +00:00
initial import
This commit is contained in:
41
lib/classes/Twig/Node/Expression/Array.php
Executable file
41
lib/classes/Twig/Node/Expression/Array.php
Executable file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Array extends Twig_Node_Expression
|
||||
{
|
||||
public function __construct(array $elements, $lineno)
|
||||
{
|
||||
parent::__construct($elements, array(), $lineno);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles the node to PHP.
|
||||
*
|
||||
* @param Twig_Compiler A Twig_Compiler instance
|
||||
*/
|
||||
public function compile($compiler)
|
||||
{
|
||||
$compiler->raw('array(');
|
||||
$first = true;
|
||||
foreach ($this->nodes as $name => $node) {
|
||||
if (!$first) {
|
||||
$compiler->raw(', ');
|
||||
}
|
||||
$first = false;
|
||||
|
||||
$compiler
|
||||
->repr($name)
|
||||
->raw(' => ')
|
||||
->subcompile($node)
|
||||
;
|
||||
}
|
||||
$compiler->raw(')');
|
||||
}
|
||||
}
|
24
lib/classes/Twig/Node/Expression/AssignName.php
Executable file
24
lib/classes/Twig/Node/Expression/AssignName.php
Executable file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Node_Expression_AssignName extends Twig_Node_Expression_Name
|
||||
{
|
||||
/**
|
||||
* Compiles the node to PHP.
|
||||
*
|
||||
* @param Twig_Compiler A Twig_Compiler instance
|
||||
*/
|
||||
public function compile($compiler)
|
||||
{
|
||||
$compiler->raw(sprintf('$context[\'%s\']', $this->getAttribute('name')));
|
||||
}
|
||||
}
|
40
lib/classes/Twig/Node/Expression/Binary.php
Executable file
40
lib/classes/Twig/Node/Expression/Binary.php
Executable file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
abstract class Twig_Node_Expression_Binary extends Twig_Node_Expression
|
||||
{
|
||||
public function __construct(Twig_NodeInterface $left, Twig_NodeInterface $right, $lineno)
|
||||
{
|
||||
parent::__construct(array('left' => $left, 'right' => $right), array(), $lineno);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles the node to PHP.
|
||||
*
|
||||
* @param Twig_Compiler A Twig_Compiler instance
|
||||
*/
|
||||
public function compile($compiler)
|
||||
{
|
||||
$compiler
|
||||
->raw('(')
|
||||
->subcompile($this->getNode('left'))
|
||||
->raw(' ')
|
||||
;
|
||||
$this->operator($compiler);
|
||||
$compiler
|
||||
->raw(' ')
|
||||
->subcompile($this->getNode('right'))
|
||||
->raw(')')
|
||||
;
|
||||
}
|
||||
|
||||
abstract public function operator($compiler);
|
||||
}
|
18
lib/classes/Twig/Node/Expression/Binary/Add.php
Executable file
18
lib/classes/Twig/Node/Expression/Binary/Add.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Binary_Add extends Twig_Node_Expression_Binary
|
||||
{
|
||||
public function operator($compiler)
|
||||
{
|
||||
return $compiler->raw('+');
|
||||
}
|
||||
}
|
18
lib/classes/Twig/Node/Expression/Binary/And.php
Executable file
18
lib/classes/Twig/Node/Expression/Binary/And.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Binary_And extends Twig_Node_Expression_Binary
|
||||
{
|
||||
public function operator($compiler)
|
||||
{
|
||||
return $compiler->raw('&&');
|
||||
}
|
||||
}
|
18
lib/classes/Twig/Node/Expression/Binary/Concat.php
Executable file
18
lib/classes/Twig/Node/Expression/Binary/Concat.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Binary_Concat extends Twig_Node_Expression_Binary
|
||||
{
|
||||
public function operator($compiler)
|
||||
{
|
||||
return $compiler->raw('.');
|
||||
}
|
||||
}
|
18
lib/classes/Twig/Node/Expression/Binary/Div.php
Executable file
18
lib/classes/Twig/Node/Expression/Binary/Div.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Binary_Div extends Twig_Node_Expression_Binary
|
||||
{
|
||||
public function operator($compiler)
|
||||
{
|
||||
return $compiler->raw('/');
|
||||
}
|
||||
}
|
29
lib/classes/Twig/Node/Expression/Binary/FloorDiv.php
Executable file
29
lib/classes/Twig/Node/Expression/Binary/FloorDiv.php
Executable file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Binary_FloorDiv extends Twig_Node_Expression_Binary
|
||||
{
|
||||
/**
|
||||
* Compiles the node to PHP.
|
||||
*
|
||||
* @param Twig_Compiler A Twig_Compiler instance
|
||||
*/
|
||||
public function compile($compiler)
|
||||
{
|
||||
$compiler->raw('floor(');
|
||||
parent::compile($compiler);
|
||||
$compiler->raw(')');
|
||||
}
|
||||
|
||||
public function operator($compiler)
|
||||
{
|
||||
return $compiler->raw('/');
|
||||
}
|
||||
}
|
18
lib/classes/Twig/Node/Expression/Binary/Mod.php
Executable file
18
lib/classes/Twig/Node/Expression/Binary/Mod.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Binary_Mod extends Twig_Node_Expression_Binary
|
||||
{
|
||||
public function operator($compiler)
|
||||
{
|
||||
return $compiler->raw('%');
|
||||
}
|
||||
}
|
18
lib/classes/Twig/Node/Expression/Binary/Mul.php
Executable file
18
lib/classes/Twig/Node/Expression/Binary/Mul.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Binary_Mul extends Twig_Node_Expression_Binary
|
||||
{
|
||||
public function operator($compiler)
|
||||
{
|
||||
return $compiler->raw('*');
|
||||
}
|
||||
}
|
18
lib/classes/Twig/Node/Expression/Binary/Or.php
Executable file
18
lib/classes/Twig/Node/Expression/Binary/Or.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Binary_Or extends Twig_Node_Expression_Binary
|
||||
{
|
||||
public function operator($compiler)
|
||||
{
|
||||
return $compiler->raw('||');
|
||||
}
|
||||
}
|
18
lib/classes/Twig/Node/Expression/Binary/Sub.php
Executable file
18
lib/classes/Twig/Node/Expression/Binary/Sub.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Binary_Sub extends Twig_Node_Expression_Binary
|
||||
{
|
||||
public function operator($compiler)
|
||||
{
|
||||
return $compiler->raw('-');
|
||||
}
|
||||
}
|
61
lib/classes/Twig/Node/Expression/Compare.php
Executable file
61
lib/classes/Twig/Node/Expression/Compare.php
Executable file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Compare extends Twig_Node_Expression
|
||||
{
|
||||
public function __construct(Twig_Node_Expression $expr, Twig_NodeInterface $ops, $lineno)
|
||||
{
|
||||
parent::__construct(array('expr' => $expr, 'ops' => $ops), array(), $lineno);
|
||||
}
|
||||
|
||||
public function compile($compiler)
|
||||
{
|
||||
if ('in' === $this->getNode('ops')->getNode('0')->getAttribute('value')) {
|
||||
return $this->compileIn($compiler);
|
||||
}
|
||||
|
||||
$this->getNode('expr')->compile($compiler);
|
||||
|
||||
$nbOps = count($this->getNode('ops'));
|
||||
for ($i = 0; $i < $nbOps; $i += 2) {
|
||||
if ($i > 0) {
|
||||
$compiler->raw(' && ($tmp'.($i / 2));
|
||||
}
|
||||
|
||||
$compiler->raw(' '.$this->getNode('ops')->getNode($i)->getAttribute('value').' ');
|
||||
|
||||
if ($i != $nbOps - 2) {
|
||||
$compiler
|
||||
->raw('($tmp'.(($i / 2) + 1).' = ')
|
||||
->subcompile($this->getNode('ops')->getNode($i + 1))
|
||||
->raw(')')
|
||||
;
|
||||
} else {
|
||||
$compiler->subcompile($this->getNode('ops')->getNode($i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
for ($j = 1; $j < $i / 2; $j++) {
|
||||
$compiler->raw(')');
|
||||
}
|
||||
}
|
||||
|
||||
protected function compileIn($compiler)
|
||||
{
|
||||
$compiler
|
||||
->raw('twig_in_filter(')
|
||||
->subcompile($this->getNode('expr'))
|
||||
->raw(', ')
|
||||
->subcompile($this->getNode('ops')->getNode(1))
|
||||
->raw(')')
|
||||
;
|
||||
}
|
||||
}
|
31
lib/classes/Twig/Node/Expression/Conditional.php
Executable file
31
lib/classes/Twig/Node/Expression/Conditional.php
Executable file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Conditional extends Twig_Node_Expression
|
||||
{
|
||||
public function __construct(Twig_Node_Expression $expr1, Twig_Node_Expression $expr2, Twig_Node_Expression $expr3, $lineno)
|
||||
{
|
||||
parent::__construct(array('expr1' => $expr1, 'expr2' => $expr2, 'expr3' => $expr3), array(), $lineno);
|
||||
}
|
||||
|
||||
public function compile($compiler)
|
||||
{
|
||||
$compiler
|
||||
->raw('(')
|
||||
->subcompile($this->getNode('expr1'))
|
||||
->raw(') ? (')
|
||||
->subcompile($this->getNode('expr2'))
|
||||
->raw(') : (')
|
||||
->subcompile($this->getNode('expr3'))
|
||||
->raw(')')
|
||||
;
|
||||
}
|
||||
}
|
23
lib/classes/Twig/Node/Expression/Constant.php
Executable file
23
lib/classes/Twig/Node/Expression/Constant.php
Executable file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Constant extends Twig_Node_Expression
|
||||
{
|
||||
public function __construct($value, $lineno)
|
||||
{
|
||||
parent::__construct(array(), array('value' => $value), $lineno);
|
||||
}
|
||||
|
||||
public function compile($compiler)
|
||||
{
|
||||
$compiler->repr($this->getAttribute('value'));
|
||||
}
|
||||
}
|
34
lib/classes/Twig/Node/Expression/ExtensionReference.php
Normal file
34
lib/classes/Twig/Node/Expression/ExtensionReference.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents an extension call node.
|
||||
*
|
||||
* @package twig
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class Twig_Node_Expression_ExtensionReference extends Twig_Node_Expression
|
||||
{
|
||||
public function __construct($name, $lineno, $tag = null)
|
||||
{
|
||||
parent::__construct(array(), array('name' => $name), $lineno, $tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles the node to PHP.
|
||||
*
|
||||
* @param Twig_Compiler A Twig_Compiler instance
|
||||
*/
|
||||
public function compile($compiler)
|
||||
{
|
||||
$compiler->raw(sprintf("\$this->env->getExtension('%s')", $this->getAttribute('name')));
|
||||
}
|
||||
}
|
43
lib/classes/Twig/Node/Expression/Filter.php
Executable file
43
lib/classes/Twig/Node/Expression/Filter.php
Executable file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Filter extends Twig_Node_Expression
|
||||
{
|
||||
public function __construct(Twig_NodeInterface $node, Twig_Node_Expression_Constant $filter_name, Twig_NodeInterface $arguments, $lineno, $tag = null)
|
||||
{
|
||||
parent::__construct(array('node' => $node, 'filter' => $filter_name, 'arguments' => $arguments), array(), $lineno, $tag);
|
||||
}
|
||||
|
||||
public function compile($compiler)
|
||||
{
|
||||
$filterMap = $compiler->getEnvironment()->getFilters();
|
||||
|
||||
$name = $this->getNode('filter')->getAttribute('value');
|
||||
$attrs = $this->getNode('arguments');
|
||||
|
||||
if (!isset($filterMap[$name])) {
|
||||
throw new Twig_Error_Syntax(sprintf('The filter "%s" does not exist', $name), $this->getLine());
|
||||
} else {
|
||||
$compiler->raw($filterMap[$name]->compile().($filterMap[$name]->needsEnvironment() ? '($this->env, ' : '('));
|
||||
}
|
||||
|
||||
$this->getNode('node')->compile($compiler);
|
||||
|
||||
foreach ($attrs as $node) {
|
||||
$compiler
|
||||
->raw(', ')
|
||||
->subcompile($node)
|
||||
;
|
||||
}
|
||||
|
||||
$compiler->raw(')');
|
||||
}
|
||||
}
|
45
lib/classes/Twig/Node/Expression/GetAttr.php
Executable file
45
lib/classes/Twig/Node/Expression/GetAttr.php
Executable file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_GetAttr extends Twig_Node_Expression
|
||||
{
|
||||
const TYPE_ANY = 'any';
|
||||
const TYPE_ARRAY = 'array';
|
||||
const TYPE_METHOD = 'method';
|
||||
|
||||
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), $lineno);
|
||||
}
|
||||
|
||||
public function compile($compiler)
|
||||
{
|
||||
$compiler
|
||||
->raw('$this->getAttribute(')
|
||||
->subcompile($this->getNode('node'))
|
||||
->raw(', ')
|
||||
->subcompile($this->getNode('attribute'))
|
||||
->raw(', array(')
|
||||
;
|
||||
|
||||
foreach ($this->getNode('arguments') as $node) {
|
||||
$compiler
|
||||
->subcompile($node)
|
||||
->raw(', ')
|
||||
;
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw('), ')
|
||||
->repr($this->getAttribute('type'))
|
||||
->raw(')');
|
||||
}
|
||||
}
|
33
lib/classes/Twig/Node/Expression/Name.php
Executable file
33
lib/classes/Twig/Node/Expression/Name.php
Executable file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Name extends Twig_Node_Expression
|
||||
{
|
||||
public function __construct($name, $lineno)
|
||||
{
|
||||
parent::__construct(array(), array('name' => $name), $lineno);
|
||||
}
|
||||
|
||||
public function compile($compiler)
|
||||
{
|
||||
if ('_self' === $this->getAttribute('name')) {
|
||||
$compiler->raw('$this');
|
||||
} elseif ('_context' === $this->getAttribute('name')) {
|
||||
$compiler->raw('$context');
|
||||
} elseif ('_charset' === $this->getAttribute('name')) {
|
||||
$compiler->raw('$this->getEnvironment()->getCharset()');
|
||||
} elseif ($compiler->getEnvironment()->isStrictVariables()) {
|
||||
$compiler->raw(sprintf('$this->getContext($context, \'%s\')', $this->getAttribute('name'), $this->getAttribute('name')));
|
||||
} else {
|
||||
$compiler->raw(sprintf('(isset($context[\'%s\']) ? $context[\'%s\'] : null)', $this->getAttribute('name'), $this->getAttribute('name')));
|
||||
}
|
||||
}
|
||||
}
|
60
lib/classes/Twig/Node/Expression/Test.php
Executable file
60
lib/classes/Twig/Node/Expression/Test.php
Executable file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Test extends Twig_Node_Expression
|
||||
{
|
||||
public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno)
|
||||
{
|
||||
parent::__construct(array('node' => $node, 'arguments' => $arguments), array('name' => $name), $lineno);
|
||||
}
|
||||
|
||||
public function compile($compiler)
|
||||
{
|
||||
$testMap = $compiler->getEnvironment()->getTests();
|
||||
if (!isset($testMap[$this->getAttribute('name')])) {
|
||||
throw new Twig_Error_Syntax(sprintf('The test "%s" does not exist', $this->getAttribute('name')), $this->getLine());
|
||||
}
|
||||
|
||||
// defined is a special case
|
||||
if ('defined' === $this->getAttribute('name')) {
|
||||
if (!$this->getNode('node') instanceof Twig_Node_Expression_Name){
|
||||
throw new Twig_Error_Syntax('The "defined" test only works with simple variables', $this->getLine());
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw($testMap[$this->getAttribute('name')]->compile().'(')
|
||||
->repr($this->getNode('node')->getAttribute('name'))
|
||||
->raw(', $context)')
|
||||
;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw($testMap[$this->getAttribute('name')]->compile().'(')
|
||||
->subcompile($this->getNode('node'))
|
||||
;
|
||||
|
||||
if (null !== $this->getNode('arguments')) {
|
||||
$compiler->raw(', ');
|
||||
|
||||
$max = count($this->getNode('arguments')) - 1;
|
||||
foreach ($this->getNode('arguments') as $i => $node) {
|
||||
$compiler->subcompile($node);
|
||||
|
||||
if ($i != $max) {
|
||||
$compiler->raw(', ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$compiler->raw(')');
|
||||
}
|
||||
}
|
30
lib/classes/Twig/Node/Expression/Unary.php
Executable file
30
lib/classes/Twig/Node/Expression/Unary.php
Executable file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
abstract class Twig_Node_Expression_Unary extends Twig_Node_Expression
|
||||
{
|
||||
public function __construct(Twig_NodeInterface $node, $lineno)
|
||||
{
|
||||
parent::__construct(array('node' => $node), array(), $lineno);
|
||||
}
|
||||
|
||||
public function compile($compiler)
|
||||
{
|
||||
$compiler->raw('(');
|
||||
$this->operator($compiler);
|
||||
$compiler
|
||||
->subcompile($this->getNode('node'))
|
||||
->raw(')')
|
||||
;
|
||||
}
|
||||
|
||||
abstract public function operator($compiler);
|
||||
}
|
18
lib/classes/Twig/Node/Expression/Unary/Neg.php
Executable file
18
lib/classes/Twig/Node/Expression/Unary/Neg.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Unary_Neg extends Twig_Node_Expression_Unary
|
||||
{
|
||||
public function operator($compiler)
|
||||
{
|
||||
$compiler->raw('-');
|
||||
}
|
||||
}
|
18
lib/classes/Twig/Node/Expression/Unary/Not.php
Executable file
18
lib/classes/Twig/Node/Expression/Unary/Not.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Unary_Not extends Twig_Node_Expression_Unary
|
||||
{
|
||||
public function operator($compiler)
|
||||
{
|
||||
$compiler->raw('!');
|
||||
}
|
||||
}
|
18
lib/classes/Twig/Node/Expression/Unary/Pos.php
Executable file
18
lib/classes/Twig/Node/Expression/Unary/Pos.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Node_Expression_Unary_Pos extends Twig_Node_Expression_Unary
|
||||
{
|
||||
public function operator($compiler)
|
||||
{
|
||||
$compiler->raw('+');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user