Neos\FluidAdaptor\Core\Parser\Interceptor\ResourceInterceptor::process PHP Method

process() public method

Looks for URIs pointing to package resources and in place of those adds ViewHelperNode instances using the ResourceViewHelper.
public process ( TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\NodeInterface $node, integer $interceptorPosition, TYPO3Fluid\Fluid\Core\Parser\ParsingState $parsingState ) : TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\NodeInterface
$node TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\NodeInterface
$interceptorPosition integer One of the INTERCEPT_* constants for the current interception point
$parsingState TYPO3Fluid\Fluid\Core\Parser\ParsingState the current parsing state. Not needed in this interceptor.
return TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\NodeInterface the modified node
    public function process(NodeInterface $node, $interceptorPosition, ParsingState $parsingState)
    {
        /** @var $node TextNode */
        if (strpos($node->getText(), 'Public/') === false) {
            return $node;
        }
        $textParts = preg_split(self::PATTERN_SPLIT_AT_RESOURCE_URIS, $node->getText(), -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
        $node = new RootNode();
        foreach ($textParts as $part) {
            $matches = [];
            if (preg_match(self::PATTERN_MATCH_RESOURCE_URI, $part, $matches)) {
                $arguments = ['path' => new TextNode($matches['Path'])];
                if ($this->defaultPackageKey !== null) {
                    $arguments['package'] = new TextNode($this->defaultPackageKey);
                }
                if (isset($matches['Package']) && preg_match(Package::PATTERN_MATCH_PACKAGEKEY, $matches['Package'])) {
                    $arguments['package'] = new TextNode($matches['Package']);
                }
                $resourceUriNode = new ResourceUriNode($arguments, $parsingState);
                $node->addChildNode($resourceUriNode);
            } else {
                $textNode = new TextNode($part);
                $node->addChildNode($textNode);
            }
        }
        return $node;
    }

Usage Example

コード例 #1
0
 /**
  * @dataProvider supportedUrls
  * @test
  */
 public function supportedUrlsAreDetected($part1, $part2, $part3, $expectedPath, $expectedPackageKey)
 {
     $originalText = $part1 . $part2 . $part3;
     $mockTextNode = $this->getMockBuilder(TextNode::class)->setMethods(array('evaluateChildNodes'))->setConstructorArgs(array($originalText))->getMock();
     $this->assertEquals($originalText, $mockTextNode->evaluate($this->createMock(RenderingContextInterface::class)));
     $interceptor = new ResourceInterceptor();
     $interceptor->setDefaultPackageKey('Acme.Demo');
     $resultingNodeTree = $interceptor->process($mockTextNode, InterceptorInterface::INTERCEPT_TEXT, $this->createMock(ParsingState::class));
     $this->assertInstanceOf(RootNode::class, $resultingNodeTree);
     $this->assertCount(3, $resultingNodeTree->getChildNodes());
     foreach ($resultingNodeTree->getChildNodes() as $parserNode) {
         if ($parserNode instanceof ResourceUriNode) {
             $this->assertEquals(['path' => $expectedPath, 'package' => $expectedPackageKey], $parserNode->getArguments());
         }
     }
 }