Exemplo n.º 1
0
 /**
  * @test
  */
 public function testGetNodeConverterReturnsNodeConverterInstance()
 {
     $instance = new TemplateCompiler();
     $this->assertInstanceOf('TYPO3Fluid\\Fluid\\Core\\Compiler\\NodeConverter', $instance->getNodeConverter());
 }
Exemplo n.º 2
0
 /**
  * @test
  */
 public function testGetNodeConverterReturnsNodeConverterInstance()
 {
     $instance = new TemplateCompiler();
     $this->assertInstanceOf(NodeConverter::class, $instance->getNodeConverter());
 }
Exemplo n.º 3
0
 /**
  * Compiles the node structure to a native switch
  * statement which evaluates closures for each
  * case comparison and renders child node closures
  * only when value matches.
  *
  * @param string $argumentsName
  * @param string $closureName
  * @param string $initializationPhpCode
  * @param ViewHelperNode $node
  * @param TemplateCompiler $compiler
  * @return string
  */
 public function compile($argumentsName, $closureName, &$initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler)
 {
     $phpCode = 'call_user_func_array(function($arguments) use ($renderingContext, $self) {' . PHP_EOL . 'switch ($arguments[\'expression\']) {' . PHP_EOL;
     foreach ($node->getChildNodes() as $childNode) {
         if ($this->isDefaultCaseNode($childNode)) {
             $childrenClosure = $compiler->wrapChildNodesInClosure($childNode);
             $phpCode .= sprintf('default: return call_user_func(%s);', $childrenClosure) . PHP_EOL;
         } elseif ($this->isCaseNode($childNode)) {
             /** @var ViewHelperNode $childNode */
             $valueClosure = $compiler->wrapViewHelperNodeArgumentEvaluationInClosure($childNode, 'value');
             $childrenClosure = $compiler->wrapChildNodesInClosure($childNode);
             $phpCode .= sprintf('case call_user_func(%s): return call_user_func(%s);', $valueClosure, $childrenClosure, $compiler->getNodeConverter()->convert($childNode)) . PHP_EOL;
         }
     }
     $phpCode .= '}' . PHP_EOL;
     $phpCode .= sprintf('}, array(%s))', $argumentsName);
     return $phpCode;
 }