/** * @test */ public function renderCallsTheRightMethodsOnTheRootNode() { $renderingContext = $this->getMock('TYPO3\\Fluid\\Core\\Rendering\\RenderingContextInterface'); $rootNode = $this->getMock('TYPO3\\Fluid\\Core\\Parser\\SyntaxTree\\RootNode'); $rootNode->expects($this->once())->method('evaluate')->with($renderingContext)->will($this->returnValue('T3DD09 Rock!')); $this->parsingState->setRootNode($rootNode); $renderedValue = $this->parsingState->render($renderingContext); $this->assertEquals($renderedValue, 'T3DD09 Rock!', 'The rendered value of the Root Node is not returned by the ParsingState.'); }
/** * @param string $identifier * @param ParsingState $parsingState * @return void */ public function store($identifier, ParsingState $parsingState) { if (!$this->templateCache instanceof FrontendInterface) { return; } $identifier = $this->sanitizeIdentifier($identifier); $this->variableCounter = 0; $generatedRenderFunctions = ''; if ($parsingState->getVariableContainer()->exists('sections')) { $sections = $parsingState->getVariableContainer()->get('sections'); // TODO: refactor to $parsedTemplate->getSections() foreach ($sections as $sectionName => $sectionRootNode) { $generatedRenderFunctions .= $this->generateCodeForSection($this->convertListOfSubNodes($sectionRootNode), 'section_' . sha1($sectionName), 'section ' . $sectionName); } } $generatedRenderFunctions .= $this->generateCodeForSection($this->convertListOfSubNodes($parsingState->getRootNode()), 'render', 'Main Render function'); $convertedLayoutNameNode = $parsingState->hasLayout() ? $this->convert($parsingState->getLayoutNameNode()) : array('initialization' => '', 'execution' => 'NULL'); $classDefinition = 'class FluidCache_' . $identifier . ' extends \\TYPO3\\Fluid\\Core\\Compiler\\AbstractCompiledTemplate'; $templateCode = <<<EOD %s { public function getVariableContainer() { \t// TODO \treturn new \\TYPO3\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer(); } public function getLayoutName(\\TYPO3\\Fluid\\Core\\Rendering\\RenderingContextInterface \$renderingContext) { \$self = \$this; %s return %s; } public function hasLayout() { return %s; } %s } EOD; $templateCode = sprintf($templateCode, $classDefinition, $convertedLayoutNameNode['initialization'], $convertedLayoutNameNode['execution'], $parsingState->hasLayout() ? 'TRUE' : 'FALSE', $generatedRenderFunctions); $this->templateCache->set($identifier, $templateCode); }
/** * @param string $identifier * @param \TYPO3\Fluid\Core\Parser\ParsingState $parsingState * @return void */ public function store($identifier, \TYPO3\Fluid\Core\Parser\ParsingState $parsingState) { $identifier = $this->sanitizeIdentifier($identifier); $this->variableCounter = 0; $generatedRenderFunctions = ''; if ($parsingState->getVariableContainer()->exists('sections')) { $sections = $parsingState->getVariableContainer()->get('sections'); // TODO: refactor to $parsedTemplate->getSections() foreach ($sections as $sectionName => $sectionRootNode) { $generatedRenderFunctions .= $this->generateCodeForSection($this->convertListOfSubNodes($sectionRootNode), 'section_' . sha1($sectionName), 'section ' . $sectionName); } } $generatedRenderFunctions .= $this->generateCodeForSection($this->convertListOfSubNodes($parsingState->getRootNode()), 'render', 'Main Render function'); $convertedLayoutNameNode = $parsingState->hasLayout() ? $this->convert($parsingState->getLayoutNameNode()) : array('initialization' => '', 'execution' => 'NULL'); $classDefinition = 'class FluidCache_' . $identifier . ' extends TYPO3\\Fluid\\Core\\Compiler\\AbstractCompiledTemplate'; $templateCode = '%s { public function getVariableContainer() { // TODO return new TYPO3\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer(); } public function getLayoutName(TYPO3\\Fluid\\Core\\Rendering\\RenderingContextInterface $renderingContext) { %s return %s; } public function hasLayout() { return %s; } %s }'; $templateCode = sprintf($templateCode, $classDefinition, $convertedLayoutNameNode['initialization'], $convertedLayoutNameNode['execution'], $parsingState->hasLayout() ? 'TRUE' : 'FALSE', $generatedRenderFunctions); $templateCode = '<?php ' . $templateCode; if ($this->templateCacheDir !== NULL) { file_put_contents($this->templateCacheDir . $identifier . '.php', $templateCode); } }
/** * Handler for array syntax. This creates the array object recursively and * adds it to the current node. * * @param ParsingState $state The current parsing state * @param string $arrayText The array as string. * @return void */ protected function arrayHandler(ParsingState $state, $arrayText) { /** @var $arrayNode ArrayNode */ $arrayNode = $this->objectManager->get(\TYPO3\Fluid\Core\Parser\SyntaxTree\ArrayNode::class, $this->recursiveArrayHandler($arrayText)); $state->getNodeFromStack()->addChildNode($arrayNode); }
/** * Handler for array syntax. This creates the array object recursively and * adds it to the current node. * * @param \TYPO3\Fluid\Core\Parser\ParsingState $state The current parsing state * @param string $arrayText The array as string. * @return void */ protected function arrayHandler(\TYPO3\Fluid\Core\Parser\ParsingState $state, $arrayText) { $state->getNodeFromStack()->addChildNode($this->objectManager->create('TYPO3\\Fluid\\Core\\Parser\\SyntaxTree\\ArrayNode', $this->recursiveArrayHandler($arrayText))); }
/** * Handler for array syntax. This creates the array object recursively and * adds it to the current node. * * @param \TYPO3\Fluid\Core\Parser\ParsingState $state The current parsing state * @param string $arrayText The array as string. * @return void */ protected function arrayHandler(\TYPO3\Fluid\Core\Parser\ParsingState $state, $arrayText) { $state->getNodeFromStack()->addChildNode(new \TYPO3\Fluid\Core\Parser\SyntaxTree\ArrayNode($this->recursiveArrayHandler($arrayText))); }