示例#1
0
 /**
  * @param ExposedTemplateParser $parser
  * @param ParsedTemplateInterface $parsedTemplate
  * @return Metric[]
  */
 public function count(ExposedTemplateParser $parser, ParsedTemplateInterface $parsedTemplate)
 {
     $splitTemplate = $parser->getSplitTemplate();
     $parsingState = $parser->buildObjectTree($splitTemplate);
     $objectTree = $parsingState->getRootNode()->getChildNodes();
     if (FALSE === $parsedTemplate->isCompilable()) {
         $this->get(self::METRIC_CACHED_SIZE)->setValue(0)->addMessage(new UncompilableMessage());
     } else {
         /** @var ExposedTemplateCompiler $compiler */
         $compiler = $this->objectManager->get('FluidTYPO3\\Builder\\Parser\\ExposedTemplateCompiler');
         $code = $compiler->compile($parsingState);
         $this->set(self::METRIC_CACHED_SIZE, round(mb_strlen($code) / 1024, 1));
     }
     // traversals, cumulatively increments $this->nodeCounter values.
     $this->determineTotalNodeCount($objectTree);
     $this->determineMaximumArgumentCount($objectTree);
     $this->determineMaximumNestingLevel($objectTree);
     $this->analyzePossibleSectionNodes($objectTree);
     // counting, integers which we set directly into $this->nodeCounter values.
     $this->set(self::METRIC_TOTAL_SPLITS, count($splitTemplate));
     $this->evaluate();
     return $this->metrics;
 }
示例#2
0
 /**
  * @param ExposedTemplateParser $parser
  * @param mixed $parsedTemplate
  * @return Metric[]
  */
 public function count(ExposedTemplateParser $parser, $parsedTemplate)
 {
     $method = new \ReflectionMethod($parser, 'buildObjectTree');
     $method->setAccessible(true);
     $splitTemplate = $parser->getSplitTemplate();
     $parsingState = $method->invokeArgs($parser, [$splitTemplate, new RenderingContext()]);
     $objectTree = $parsingState->getRootNode()->getChildNodes();
     try {
         if (false === $parsedTemplate->isCompilable()) {
             $this->get(self::METRIC_CACHED_SIZE)->setValue(0)->addMessage(new UncompilableMessage());
         } else {
             /** @var ExposedTemplateCompiler $compiler */
             $compiler = $this->getTemplateCompiler();
             if (method_exists($compiler, 'store')) {
                 $code = $compiler->store('testcompile_' . sha1(microtime(true)), $parsingState);
             } else {
                 $code = $compiler->compile($parsingState);
             }
             $this->set(self::METRIC_CACHED_SIZE, round(mb_strlen($code) / 1024, 1));
         }
     } catch (\TYPO3Fluid\Fluid\Core\StopCompilingException $error) {
         $this->get(self::METRIC_CACHED_SIZE)->setValue(0)->addMessage(new UncompilableMessage());
     }
     // traversals, cumulatively increments $this->nodeCounter values.
     $this->determineTotalNodeCount($objectTree);
     $this->determineMaximumArgumentCount($objectTree);
     $this->determineMaximumNestingLevel($objectTree);
     $this->analyzePossibleSectionNodes($objectTree);
     // counting, integers which we set directly into $this->nodeCounter values.
     $this->set(self::METRIC_TOTAL_SPLITS, count($splitTemplate));
     $this->evaluate();
     return $this->metrics;
 }
 /**
  * @param string $input
  * @test
  * @dataProvider getInvalidTemplateStringTestValues
  */
 public function testParseThrowsExceptionOnInvalidTemplateString($input)
 {
     $parser = new ExposedTemplateParser();
     $this->setExpectedException('TYPO3\\CMS\\Fluid\\Core\\Parser\\Exception');
     $parser->parse($input);
 }
示例#4
0
 /**
  * @return ExposedTemplateParser
  */
 protected function getTemplateParser()
 {
     if (VersionUtility::assertExtensionVersionIsAtLeastVersion('core', 8)) {
         $exposedTemplateParser = new ExposedTemplateParser();
         $exposedTemplateParser->setRenderingContext(new RenderingContext());
     } else {
         $exposedTemplateParser = new ExposedTemplateParserLegacy();
     }
     return $exposedTemplateParser;
 }