/** * @param string $identifier * @param ParsingState $parsingState * @return void */ public function store($identifier, ParsingState $parsingState) { if (!$this->templateCache instanceof FluidCacheInterface) { return; } if ($this->disabled) { $parsingState->setCompilable(FALSE); $this->templateCache->flush($identifier); return; } $identifier = $this->sanitizeIdentifier($identifier); $this->nodeConverter->setVariableCounter(0); $generatedRenderFunctions = $this->generateSectionCodeFromParsingState($parsingState); $generatedRenderFunctions .= $this->generateCodeForSection($this->nodeConverter->convertListOfSubNodes($parsingState->getRootNode()), 'render', 'Main Render function'); $classDefinition = 'class ' . $identifier . ' extends \\TYPO3Fluid\\Fluid\\Core\\Compiler\\AbstractCompiledTemplate'; $templateCode = <<<EOD <?php %s { public function getLayoutName(\\TYPO3Fluid\\Fluid\\Core\\Rendering\\RenderingContextInterface \$renderingContext) { \$layout = %s; if (!\$layout) { \$layout = '%s'; } return \$layout; } public function hasLayout() { return %s; } public function addCompiledNamespaces(\\TYPO3Fluid\\Fluid\\Core\\Rendering\\RenderingContextInterface \$renderingContext) { \$namespaces = %s; \$resolver = \$renderingContext->getViewHelperResolver(); foreach (\$namespaces as \$namespace => \$phpNamespace) { \$resolver->registerNamespace(\$namespace, \$phpNamespace); } } %s } EOD; $templateCode = sprintf($templateCode, $classDefinition, '$renderingContext->getVariableProvider()->get(\'layoutName\')', $parsingState->getVariableContainer()->get('layoutName'), $parsingState->hasLayout() ? 'TRUE' : 'FALSE', var_export($parsingState->getViewHelperResolver()->getNamespaces(), TRUE), $generatedRenderFunctions); $this->templateCache->set($identifier, $templateCode); }
/** * @param string $identifier * @param ParsingState $parsingState * @return void */ public function store($identifier, ParsingState $parsingState) { if ($this->isDisabled()) { if ($this->renderingContext->isCacheEnabled()) { // Compiler is disabled but cache is enabled. Flush cache to make sure. $this->renderingContext->getCache()->flush($identifier); } $parsingState->setCompilable(false); return; } $this->currentlyProcessingState = $parsingState; $identifier = $this->sanitizeIdentifier($identifier); $this->nodeConverter->setVariableCounter(0); $generatedRenderFunctions = $this->generateSectionCodeFromParsingState($parsingState); $generatedRenderFunctions .= $this->generateCodeForSection($this->nodeConverter->convertListOfSubNodes($parsingState->getRootNode()), 'render', 'Main Render function'); $classDefinition = 'class ' . $identifier . ' extends \\TYPO3Fluid\\Fluid\\Core\\Compiler\\AbstractCompiledTemplate'; $templateCode = <<<EOD <?php %s { public function getLayoutName(\\TYPO3Fluid\\Fluid\\Core\\Rendering\\RenderingContextInterface \$renderingContext) { \$self = \$this; %s; } public function hasLayout() { return %s; } public function addCompiledNamespaces(\\TYPO3Fluid\\Fluid\\Core\\Rendering\\RenderingContextInterface \$renderingContext) { \$renderingContext->getViewHelperResolver()->addNamespaces(%s); } %s } EOD; $storedLayoutName = $parsingState->getVariableContainer()->get('layoutName'); $templateCode = sprintf($templateCode, $classDefinition, $this->generateCodeForLayoutName($storedLayoutName), $parsingState->hasLayout() ? 'TRUE' : 'FALSE', var_export($this->renderingContext->getViewHelperResolver()->getNamespaces(), true), $generatedRenderFunctions); $this->renderingContext->getCache()->set($identifier, $templateCode); }
/** * @test */ public function testSetVariableCounter() { $instance = new NodeConverter(new TemplateCompiler()); $instance->setVariableCounter(10); $this->assertAttributeEquals(10, 'variableCounter', $instance); }