/** * @test */ public function testGetNodeConverterReturnsNodeConverterInstance() { $instance = new TemplateCompiler(); $this->assertInstanceOf('TYPO3Fluid\\Fluid\\Core\\Compiler\\NodeConverter', $instance->getNodeConverter()); }
/** * @test */ public function testGetNodeConverterReturnsNodeConverterInstance() { $instance = new TemplateCompiler(); $this->assertInstanceOf(NodeConverter::class, $instance->getNodeConverter()); }
/** * 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; }