Beispiel #1
0
 /**
  * @param Compiler $compiler
  * @param Twig_Node $node
  * @return Segment|string
  */
 private function getIncludeData(Compiler $compiler, Twig_Node $node)
 {
     if ($child = $node->getNode('variables')) {
         return $compiler->compileNode($child);
     }
     return '[]';
 }
Beispiel #2
0
 /**
  * @param Compiler $compiler
  * @param Twig_Node $node
  * @param string $name
  * @return null|Segment|Segment[]
  * @throws NotImplementedException
  * @throws UnknownStructureException
  */
 protected function getOptionalCompiledNode(Compiler $compiler, Twig_Node $node, $name)
 {
     if (($child = $node->getNode($name)) !== null) {
         return $compiler->compileNode($child);
     }
     return null;
 }
Beispiel #3
0
 /**
  * @param Compiler $compiler
  * @param Twig_Node $node
  * @return array
  */
 private function getValues(Compiler $compiler, Twig_Node $node)
 {
     $values = [];
     for ($i = 0; $i < $node->count(); $i += 2) {
         $key = $compiler->compileNode($node->getNode($i));
         $value = $compiler->compileNode($node->getNode($i + 1));
         $values[strval($key)] = strval($value);
     }
     return $values;
 }
Beispiel #4
0
 /**
  * @param Compiler $compiler
  * @param Twig_Node $node
  * @return Segment[]
  * @throws NotImplementedException
  * @throws UnknownStructureException
  */
 private function getFilterArguments(Compiler $compiler, Twig_Node $node)
 {
     if (!$node->hasNode('arguments')) {
         return [];
     }
     $arguments = [];
     foreach ($node->getNode('arguments') as $argument) {
         $arguments[] = $compiler->compileNode($argument);
     }
     return $arguments;
 }
Beispiel #5
0
 /**
  * @param Compiler $compiler
  * @param Twig_Node $node
  * @return Segment[]
  * @throws NotImplementedException
  * @throws UnknownStructureException
  */
 public function compile(Compiler $compiler, Twig_Node $node)
 {
     $commands = [];
     foreach ($node as $child) {
         $compilation = $compiler->compileNode($child);
         if (!is_array($compilation)) {
             $compilation = [$compilation];
         }
         $commands = array_merge($commands, $compilation);
     }
     return $commands;
 }
Beispiel #6
0
 /**
  * @param Compiler $compiler
  * @param Twig_Node $body
  * @return array
  */
 private function getIfCommands(Compiler $compiler, Twig_Node $body)
 {
     $test = $compiler->compileNode($body->getNode(0));
     $cmd = $compiler->compileNode($body->getNode(1));
     $commands = [];
     $commands[] = new Command("if ({$test}) {");
     $commands = array_merge($commands, $cmd);
     $commands[] = new Command('}');
     for ($i = 2; $i < count($body); $i += 2) {
         $test = $compiler->compileNode($body->getNode($i + 0));
         $cmd = $compiler->compileNode($body->getNode($i + 1));
         $commands[] = new Command("else if ({$test}) {");
         $commands = array_merge($commands, $cmd);
         $commands[] = new Command('}');
     }
     return $commands;
 }
Beispiel #7
0
 /**
  * @param string $filename
  * @param string $source
  * @return string
  */
 public function convertSource($filename, $source)
 {
     $compiler = new Compiler($this->twigEnvironment);
     $code = $compiler->compileSource($source);
     return $this->exportHandler->export($filename, $code);
 }