Пример #1
0
    /**
     * @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);
        }
    }
    /**
     * @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);
    }