Exemple #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);
        }
    }
 /**
  * Initialize the given ViewHelper and adds it to the current node and to
  * the stack.
  *
  * @param ParsingState $state Current parsing state
  * @param string $namespaceIdentifier Namespace identifier - being looked up in $this->namespaces
  * @param string $methodIdentifier Method identifier
  * @param array $argumentsObjectTree Arguments object tree
  * @return void
  * @throws Exception
  */
 protected function initializeViewHelperAndAddItToStack(ParsingState $state, $namespaceIdentifier, $methodIdentifier, $argumentsObjectTree)
 {
     if (!array_key_exists($namespaceIdentifier, $this->namespaces)) {
         throw new Exception('Namespace could not be resolved. This exception should never be thrown!', 1224254792);
     }
     $resolvedViewHelperClassName = $this->resolveViewHelperName($namespaceIdentifier, $methodIdentifier);
     $actualViewHelperClassName = $this->objectManager->getCaseSensitiveObjectName($resolvedViewHelperClassName);
     if ($actualViewHelperClassName === FALSE) {
         throw new Exception(sprintf('The ViewHelper "<%s:%s>" could not be resolved.' . chr(10) . 'Based on your spelling, the system would load the class "%s", however this class does not exist.', $namespaceIdentifier, $methodIdentifier, $resolvedViewHelperClassName), 1407060572);
     } elseif ($actualViewHelperClassName !== $resolvedViewHelperClassName) {
         throw new Exception(sprintf('The ViewHelper "<%s:%s>" inside your template is not written correctly upper/lowercased.' . chr(10) . 'Based on your spelling, the system would load the (non-existant) class "%s", however the real class name is "%s".' . chr(10) . 'This error can be fixed by making sure the ViewHelper is written in the correct upper/lowercase form.', $namespaceIdentifier, $methodIdentifier, $resolvedViewHelperClassName, $actualViewHelperClassName), 1407060573);
     }
     $viewHelper = $this->objectManager->get($actualViewHelperClassName);
     // The following three checks are only done *in an uncached template*, and not needed anymore in the cached version
     $expectedViewHelperArguments = $viewHelper->prepareArguments();
     $this->abortIfUnregisteredArgumentsExist($expectedViewHelperArguments, $argumentsObjectTree);
     $this->abortIfRequiredArgumentsAreMissing($expectedViewHelperArguments, $argumentsObjectTree);
     $this->rewriteBooleanNodesInArgumentsObjectTree($expectedViewHelperArguments, $argumentsObjectTree);
     /** @var $currentViewHelperNode ViewHelperNode */
     $currentViewHelperNode = $this->objectManager->get('TYPO3\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode', $viewHelper, $argumentsObjectTree);
     $state->getNodeFromStack()->addChildNode($currentViewHelperNode);
     if ($viewHelper instanceof ChildNodeAccessInterface && !$viewHelper instanceof CompilableInterface) {
         $state->setCompilable(FALSE);
     }
     // PostParse Facet
     if ($viewHelper instanceof PostParseInterface) {
         // Don't just use $viewHelper::postParseEvent(...),
         // as this will break with PHP < 5.3.
         call_user_func(array($viewHelper, 'postParseEvent'), $currentViewHelperNode, $argumentsObjectTree, $state->getVariableContainer());
     }
     $this->callInterceptor($currentViewHelperNode, InterceptorInterface::INTERCEPT_OPENING_VIEWHELPER, $state);
     $state->pushNodeToStack($currentViewHelperNode);
 }
    /**
     * @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);
    }
Exemple #4
0
 /**
  * Initialize the given ViewHelper and adds it to the current node and to
  * the stack.
  *
  * @param \TYPO3\Fluid\Core\Parser\ParsingState $state Current parsing state
  * @param string $namespaceIdentifier Namespace identifier - being looked up in $this->namespaces
  * @param string $methodIdentifier Method identifier
  * @param array $argumentsObjectTree Arguments object tree
  * @return void
  */
 protected function initializeViewHelperAndAddItToStack(\TYPO3\Fluid\Core\Parser\ParsingState $state, $namespaceIdentifier, $methodIdentifier, $argumentsObjectTree)
 {
     if (!array_key_exists($namespaceIdentifier, $this->namespaces)) {
         throw new \TYPO3\Fluid\Core\Parser\Exception('Namespace could not be resolved. This exception should never be thrown!', 1224254792);
     }
     $viewHelper = $this->objectManager->get($this->resolveViewHelperName($namespaceIdentifier, $methodIdentifier));
     // The following three checks are only done *in an uncached template*, and not needed anymore in the cached version
     $expectedViewHelperArguments = $viewHelper->prepareArguments();
     $this->abortIfUnregisteredArgumentsExist($expectedViewHelperArguments, $argumentsObjectTree);
     $this->abortIfRequiredArgumentsAreMissing($expectedViewHelperArguments, $argumentsObjectTree);
     $this->rewriteBooleanNodesInArgumentsObjectTree($expectedViewHelperArguments, $argumentsObjectTree);
     $currentViewHelperNode = $this->objectManager->create('TYPO3\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode', $viewHelper, $argumentsObjectTree);
     $state->getNodeFromStack()->addChildNode($currentViewHelperNode);
     if ($viewHelper instanceof \TYPO3\Fluid\Core\ViewHelper\Facets\ChildNodeAccessInterface && !$viewHelper instanceof \TYPO3\Fluid\Core\ViewHelper\Facets\CompilableInterface) {
         $state->setCompilable(FALSE);
     }
     // PostParse Facet
     if ($viewHelper instanceof \TYPO3\Fluid\Core\ViewHelper\Facets\PostParseInterface) {
         // Don't just use $viewHelper::postParseEvent(...),
         // as this will break with PHP < 5.3.
         call_user_func(array($viewHelper, 'postParseEvent'), $currentViewHelperNode, $argumentsObjectTree, $state->getVariableContainer());
     }
     $this->callInterceptor($currentViewHelperNode, \TYPO3\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_OPENING_VIEWHELPER, $state);
     $state->pushNodeToStack($currentViewHelperNode);
 }