Dotclear


Ignore:
Timestamp:
02/15/13 08:35:19 (13 years ago)
Author:
Dsls <dsls@…>
Branch:
twig
Children:
1106:a4487f3ca4b4, 1147:2e5cb79e4782
Message:

Twig 1.12.2

Location:
inc/libs/twig/Node
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • inc/libs/twig/Node/Expression/Filter.php

    r991 r1101  
    1010 * file that was distributed with this source code. 
    1111 */ 
    12 class Twig_Node_Expression_Filter extends Twig_Node_Expression 
     12class Twig_Node_Expression_Filter extends Twig_Node_Expression_Call 
    1313{ 
    1414    public function __construct(Twig_NodeInterface $node, Twig_Node_Expression_Constant $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null) 
     
    2020    { 
    2121        $name = $this->getNode('filter')->getAttribute('value'); 
     22        $filter = $compiler->getEnvironment()->getFilter($name); 
    2223 
    23         if (false === $filter = $compiler->getEnvironment()->getFilter($name)) { 
    24             $message = sprintf('The filter "%s" does not exist', $name); 
    25             if ($alternatives = $compiler->getEnvironment()->computeAlternatives($name, array_keys($compiler->getEnvironment()->getFilters()))) { 
    26                 $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives)); 
    27             } 
    28  
    29             throw new Twig_Error_Syntax($message, $this->getLine(), $compiler->getFilename()); 
     24        $this->setAttribute('name', $name); 
     25        $this->setAttribute('type', 'filter'); 
     26        $this->setAttribute('thing', $filter); 
     27        $this->setAttribute('needs_environment', $filter->needsEnvironment()); 
     28        $this->setAttribute('needs_context', $filter->needsContext()); 
     29        $this->setAttribute('arguments', $filter->getArguments()); 
     30        if ($filter instanceof Twig_FilterCallableInterface || $filter instanceof Twig_SimpleFilter) { 
     31            $this->setAttribute('callable', $filter->getCallable()); 
    3032        } 
    3133 
    32         $this->compileFilter($compiler, $filter); 
    33     } 
    34  
    35     protected function compileFilter(Twig_Compiler $compiler, Twig_FilterInterface $filter) 
    36     { 
    37         $compiler 
    38             ->raw($filter->compile().'(') 
    39             ->raw($filter->needsEnvironment() ? '$this->env, ' : '') 
    40             ->raw($filter->needsContext() ? '$context, ' : '') 
    41         ; 
    42  
    43         foreach ($filter->getArguments() as $argument) { 
    44             $compiler 
    45                 ->string($argument) 
    46                 ->raw(', ') 
    47             ; 
    48         } 
    49  
    50         $compiler->subcompile($this->getNode('node')); 
    51  
    52         foreach ($this->getNode('arguments') as $node) { 
    53             $compiler 
    54                 ->raw(', ') 
    55                 ->subcompile($node) 
    56             ; 
    57         } 
    58  
    59         $compiler->raw(')'); 
     34        $this->compileCallable($compiler); 
    6035    } 
    6136} 
  • inc/libs/twig/Node/Expression/Filter/Default.php

    r991 r1101  
    2424    public function __construct(Twig_NodeInterface $node, Twig_Node_Expression_Constant $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null) 
    2525    { 
    26         $default = new Twig_Node_Expression_Filter($node, new Twig_Node_Expression_Constant('_default', $node->getLine()), $arguments, $node->getLine()); 
     26        $default = new Twig_Node_Expression_Filter($node, new Twig_Node_Expression_Constant('default', $node->getLine()), $arguments, $node->getLine()); 
    2727 
    2828        if ('default' === $filterName->getAttribute('value') && ($node instanceof Twig_Node_Expression_Name || $node instanceof Twig_Node_Expression_GetAttr)) { 
  • inc/libs/twig/Node/Expression/Function.php

    r991 r1101  
    99 * file that was distributed with this source code. 
    1010 */ 
    11 class Twig_Node_Expression_Function extends Twig_Node_Expression 
     11class Twig_Node_Expression_Function extends Twig_Node_Expression_Call 
    1212{ 
    1313    public function __construct($name, Twig_NodeInterface $arguments, $lineno) 
     
    1919    { 
    2020        $name = $this->getAttribute('name'); 
     21        $function = $compiler->getEnvironment()->getFunction($name); 
    2122 
    22         if (false === $function = $compiler->getEnvironment()->getFunction($name)) { 
    23             $message = sprintf('The function "%s" does not exist', $name); 
    24             if ($alternatives = $compiler->getEnvironment()->computeAlternatives($name, array_keys($compiler->getEnvironment()->getFunctions()))) { 
    25                 $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives)); 
    26             } 
    27  
    28             throw new Twig_Error_Syntax($message, $this->getLine(), $compiler->getFilename()); 
     23        $this->setAttribute('name', $name); 
     24        $this->setAttribute('type', 'function'); 
     25        $this->setAttribute('thing', $function); 
     26        $this->setAttribute('needs_environment', $function->needsEnvironment()); 
     27        $this->setAttribute('needs_context', $function->needsContext()); 
     28        $this->setAttribute('arguments', $function->getArguments()); 
     29        if ($function instanceof Twig_FunctionCallableInterface || $function instanceof Twig_SimpleFunction) { 
     30            $this->setAttribute('callable', $function->getCallable()); 
    2931        } 
    3032 
    31         $compiler->raw($function->compile().'('); 
    32  
    33         $first = true; 
    34  
    35         if ($function->needsEnvironment()) { 
    36             $compiler->raw('$this->env'); 
    37             $first = false; 
    38         } 
    39  
    40         if ($function->needsContext()) { 
    41             if (!$first) { 
    42                 $compiler->raw(', '); 
    43             } 
    44             $compiler->raw('$context'); 
    45             $first = false; 
    46         } 
    47  
    48         foreach ($function->getArguments() as $argument) { 
    49             if (!$first) { 
    50                 $compiler->raw(', '); 
    51             } 
    52             $compiler->string($argument); 
    53             $first = false; 
    54         } 
    55  
    56         foreach ($this->getNode('arguments') as $node) { 
    57             if (!$first) { 
    58                 $compiler->raw(', '); 
    59             } 
    60             $compiler->subcompile($node); 
    61             $first = false; 
    62         } 
    63  
    64         $compiler->raw(')'); 
     33        $this->compileCallable($compiler); 
    6534    } 
    6635} 
  • inc/libs/twig/Node/Expression/Test.php

    r991 r1101  
    99 * file that was distributed with this source code. 
    1010 */ 
    11 class Twig_Node_Expression_Test extends Twig_Node_Expression 
     11class Twig_Node_Expression_Test extends Twig_Node_Expression_Call 
    1212{ 
    1313    public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno) 
     
    1919    { 
    2020        $name = $this->getAttribute('name'); 
    21         $testMap = $compiler->getEnvironment()->getTests(); 
    22         if (!isset($testMap[$name])) { 
    23             $message = sprintf('The test "%s" does not exist', $name); 
    24             if ($alternatives = $compiler->getEnvironment()->computeAlternatives($name, array_keys($compiler->getEnvironment()->getTests()))) { 
    25                 $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives)); 
    26             } 
     21        $test = $compiler->getEnvironment()->getTest($name); 
    2722 
    28             throw new Twig_Error_Syntax($message, $this->getLine(), $compiler->getFilename()); 
     23        $this->setAttribute('name', $name); 
     24        $this->setAttribute('type', 'test'); 
     25        $this->setAttribute('thing', $test); 
     26        if ($test instanceof Twig_TestCallableInterface || $test instanceof Twig_SimpleTest) { 
     27            $this->setAttribute('callable', $test->getCallable()); 
    2928        } 
    3029 
    31         $name = $this->getAttribute('name'); 
    32         $node = $this->getNode('node'); 
    33  
    34         $compiler 
    35             ->raw($testMap[$name]->compile().'(') 
    36             ->subcompile($node) 
    37         ; 
    38  
    39         if (null !== $this->getNode('arguments')) { 
    40             $compiler->raw(', '); 
    41  
    42             $max = count($this->getNode('arguments')) - 1; 
    43             foreach ($this->getNode('arguments') as $i => $arg) { 
    44                 $compiler->subcompile($arg); 
    45  
    46                 if ($i != $max) { 
    47                     $compiler->raw(', '); 
    48                 } 
    49             } 
    50         } 
    51  
    52         $compiler->raw(')'); 
     30        $this->compileCallable($compiler); 
    5331    } 
    5432} 
  • inc/libs/twig/Node/Macro.php

    r991 r1101  
    3030    public function compile(Twig_Compiler $compiler) 
    3131    { 
    32         $arguments = array(); 
    33         foreach ($this->getNode('arguments') as $argument) { 
    34             $arguments[] = '$_'.$argument->getAttribute('name').' = null'; 
     32        $compiler 
     33            ->addDebugInfo($this) 
     34            ->write(sprintf("public function get%s(", $this->getAttribute('name'))) 
     35        ; 
     36 
     37        $count = count($this->getNode('arguments')); 
     38        $pos = 0; 
     39        foreach ($this->getNode('arguments') as $name => $default) { 
     40            $compiler 
     41                ->raw('$_'.$name.' = ') 
     42                ->subcompile($default) 
     43            ; 
     44 
     45            if (++$pos < $count) { 
     46                $compiler->raw(', '); 
     47            } 
    3548        } 
    3649 
    3750        $compiler 
    38             ->addDebugInfo($this) 
    39             ->write(sprintf("public function get%s(%s)\n", $this->getAttribute('name'), implode(', ', $arguments)), "{\n") 
     51            ->raw(")\n") 
     52            ->write("{\n") 
    4053            ->indent() 
    4154        ; 
     
    4962            ; 
    5063 
    51             foreach ($this->getNode('arguments') as $argument) { 
     64            foreach ($this->getNode('arguments') as $name => $default) { 
    5265                $compiler 
    5366                    ->write('') 
    54                     ->string($argument->getAttribute('name')) 
    55                     ->raw(' => $_'.$argument->getAttribute('name')) 
     67                    ->string($name) 
     68                    ->raw(' => $_'.$name) 
    5669                    ->raw(",\n") 
    5770                ; 
Note: See TracChangeset for help on using the changeset viewer.

Sites map