/**
  * Check if $value is valid. If it is not valid, needs to add an error
  * to Result.
  *
  * @param mixed $value
  * @return void
  */
 protected function isValid($value)
 {
     try {
         $this->parser->parse($value);
     } catch (\Exception $e) {
         $this->addError("Could not parse fluid template: " . $e->getMessage(), 1418149684);
     }
 }
Ejemplo n.º 2
0
 /**
  * Renders a partial.
  *
  * @param string $partialName
  * @param string $sectionName
  * @param array $variables
  * @param \TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer $viewHelperVariableContainer the View Helper Variable container to use.
  * @return string
  */
 public function renderPartial($partialName, $sectionName, array $variables)
 {
     $partialNameWithFormat = $partialName . '.' . $this->controllerContext->getRequest()->getFormat();
     if (!isset($this->partialIdentifierCache[$partialNameWithFormat])) {
         $this->partialIdentifierCache[$partialNameWithFormat] = $this->getPartialIdentifier($partialName);
     }
     $partialIdentifier = $this->partialIdentifierCache[$partialNameWithFormat];
     if ($this->templateCompiler->has($partialIdentifier)) {
         $parsedPartial = $this->templateCompiler->get($partialIdentifier);
     } else {
         $parsedPartial = $this->templateParser->parse($this->getPartialSource($partialName));
         if ($parsedPartial->isCompilable()) {
             $this->templateCompiler->store($partialIdentifier, $parsedPartial);
         }
     }
     $variableContainer = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer', $variables);
     $renderingContext = clone $this->getCurrentRenderingContext();
     $renderingContext->injectTemplateVariableContainer($variableContainer);
     $this->startRendering(self::RENDERING_PARTIAL, $parsedPartial, $renderingContext);
     if ($sectionName !== NULL) {
         $output = $this->renderSection($sectionName, $variables);
     } else {
         $output = $parsedPartial->render($renderingContext);
     }
     $this->stopRendering();
     return $output;
 }
Ejemplo n.º 3
0
 /**
  * @test
  */
 public function renderLoadsSpecifiedTemplateFileAndPassesSourceToTemplateParser()
 {
     $templatePathAndFilename = __DIR__ . '/Fixtures/StandaloneViewFixture.html';
     $expectedResult = file_get_contents($templatePathAndFilename);
     $this->view->setTemplatePathAndFilename($templatePathAndFilename);
     $this->mockTemplateParser->expects($this->once())->method('parse')->with($expectedResult);
     $this->view->render();
 }
Ejemplo n.º 4
0
 /**
  * Syntax checks a Fluid template file by attempting
  * to load the file and retrieve a parsed template, which
  * will cause traversal of the entire syntax node tree
  * and report any errors about missing or unknown arguments.
  *
  * Will NOT, however, report errors which are caused by
  * variables assigned to the template (there will be no
  * variables while building the syntax tree and listening
  * for errors).
  *
  * @param string $filePathAndFilename
  * @return FluidParserResult
  * @throws \Exception
  */
 public function syntaxCheckFluidTemplateFile($filePathAndFilename)
 {
     /** @var FluidParserResult $result */
     $result = $this->objectManager->get('FluidTYPO3\\Builder\\Result\\FluidParserResult');
     /** @var RenderingContext $context */
     $context = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContext');
     try {
         $parsedTemplate = $this->templateParser->parse(file_get_contents($filePathAndFilename));
         $result->setLayoutName($parsedTemplate->getLayoutName($context));
         $result->setNamespaces($this->templateParser->getNamespaces());
         $result->setCompilable($parsedTemplate->isCompilable());
     } catch (\Exception $error) {
         $result->setError($error);
         $result->setValid(FALSE);
     }
     return $result;
 }
Ejemplo n.º 5
0
 /**
  * @test
  */
 public function renderLoadsSpecifiedTemplateFileAndPassesSourceToTemplateParser()
 {
     $templatePathAndFilename = GeneralUtility::fixWindowsFilePath(__DIR__) . '/Fixtures/StandaloneViewFixture.html';
     $expectedResult = file_get_contents($templatePathAndFilename);
     $this->view->setTemplatePathAndFilename($templatePathAndFilename);
     $this->view->expects($this->once())->method('testFileExistence')->with($templatePathAndFilename)->will($this->returnValue(true));
     $this->mockTemplateParser->expects($this->once())->method('parse')->with($expectedResult);
     $this->view->render();
 }
 /**
  * Extracts namespace definitions out of the given template string and sets
  * $this->namespaces.
  *
  * @param string $templateString Template string to extract the namespaces from
  * @return string The updated template string without namespace declarations inside
  * @throws \TYPO3\CMS\Fluid\Core\Parser\Exception if a namespace can't be resolved or has been declared already
  */
 protected function extractNamespaceDefinitions($templateString)
 {
     $templateString = parent::extractNamespaceDefinitions($templateString);
     foreach ($this->namespaces as $identifier => $phpNamespace) {
         if ($phpNamespace == 'Tx_ExtbaseHijax_ViewHelpers') {
             $this->namespaces[$identifier] = 'EssentialDots\\ExtbaseHijax\\ViewHelpers';
         }
     }
     return $templateString;
 }
Ejemplo n.º 7
0
 public function parse($templateString)
 {
     if (substr($templateString, 0, 7) === 'smarty:') {
         $templateString = substr($templateString, 7);
         $state = $this->objectManager->get(\TYPO3\CMS\Fluid\Core\Parser\ParsingState::class);
         $rootNode = $this->objectManager->get(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode::class);
         $state->setRootNode($rootNode);
         $state->pushNodeToStack($rootNode);
         $viewHelper = $this->objectManager->get(\Vierwd\VierwdSmarty\ViewHelper\SmartyViewHelper::class);
         $node = $this->objectManager->get(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode::class, $viewHelper, []);
         $state->getNodeFromStack()->addChildNode($node);
         $textNode = $this->objectManager->get(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode::class, $templateString);
         $node->addChildNode($textNode);
         return $state;
     }
     return parent::parse($templateString);
 }
Ejemplo n.º 8
0
 /**
  * Extracts namespace definitions out of the given template string and sets
  * $this->namespaces.
  *
  * @param string $templateString Template string to extract the namespaces from
  * @return string The updated template string without namespace declarations inside
  * @throws \TYPO3\CMS\Fluid\Core\Parser\Exception if a namespace can't be resolved or has been declared already
  * @override
  */
 protected function extractNamespaceDefinitions($templateString)
 {
     // ADDED STUFF HERE
     if (!$this->hasCustomNamespaces()) {
         return parent::extractNamespaceDefinitions($templateString);
     }
     $matches = array();
     preg_match_all(self::$SCAN_PATTERN_XMLNSDECLARATION, $templateString, $matches, PREG_SET_ORDER);
     foreach ($matches as $match) {
         // skip reserved "f" namespace identifier
         if ($match['identifier'] === 'f') {
             continue;
         }
         if (array_key_exists($match['identifier'], $this->namespaces)) {
             throw new \TYPO3\CMS\Fluid\Core\Parser\Exception(sprintf('Namespace identifier "%s" is already registered. Do not re-declare namespaces!', $match['identifier']), 1331135889);
         }
         if (isset($this->settings['namespaces'][$match['xmlNamespace']])) {
             $phpNamespace = $this->settings['namespaces'][$match['xmlNamespace']];
         } else {
             $matchedPhpNamespace = array();
             if (preg_match(self::$SCAN_PATTERN_DEFAULT_XML_NAMESPACE, $match['xmlNamespace'], $matchedPhpNamespace) === 0) {
                 continue;
             }
             $phpNamespace = str_replace('/', '\\', $matchedPhpNamespace['PhpNamespace']);
         }
         $this->namespaces[$match['identifier']] = $phpNamespace;
     }
     $matches = array();
     preg_match_all(self::$SCAN_PATTERN_NAMESPACEDECLARATION, $templateString, $matches, PREG_SET_ORDER);
     foreach ($matches as $match) {
         if (array_key_exists($match['identifier'], $this->namespaces)) {
             // ADDED STUFF HERE -- You can now specify a different value for a namespace
             $existingPhpNamespace = $this->namespaces[$match['identifier']];
             if ($existingPhpNamespace != $match['phpNamespace']) {
                 throw new \TYPO3\CMS\Fluid\Core\Parser\Exception(sprintf('Namespace identifier "%s" is already registered. Do not re-declare namespaces!', $match['identifier']), 1224241246);
             }
         } else {
             $this->namespaces[$match['identifier']] = $match['phpNamespace'];
         }
     }
     if ($matches !== array()) {
         $templateString = preg_replace(self::$SCAN_PATTERN_NAMESPACEDECLARATION, '', $templateString);
     }
     return $templateString;
 }
Ejemplo n.º 9
0
 /**
  * @test
  * @expectedException \TYPO3\CMS\Fluid\Core\Parser\Exception
  */
 public function parseThrowsExceptionWhenStringArgumentMissing()
 {
     $templateParser = new \TYPO3\CMS\Fluid\Core\Parser\TemplateParser();
     $templateParser->parse(123);
 }
 /**
  * @param array $splitTemplate
  * @param integer $context
  * @return ParsingState
  */
 public function buildObjectTree($splitTemplate, $context = self::CONTEXT_OUTSIDE_VIEWHELPER_ARGUMENTS)
 {
     return parent::buildObjectTree($splitTemplate, $context);
 }