Hostnet\Component\Webpack\Asset\TwigParser::findSplitPoints PHP 메소드

findSplitPoints() 공개 메소드

Returns an array of split points from the given template file.
public findSplitPoints ( string $template_file ) : array
$template_file string
리턴 array
    public function findSplitPoints($template_file)
    {
        $inline_blocks = 0;
        $source = new \Twig_Source(file_get_contents($template_file), $template_file);
        $stream = $this->twig->tokenize($source);
        $points = [];
        while (!$stream->isEOF() && ($token = $stream->next())) {
            // {{ webpack_asset(...) }}
            if ($token->test(\Twig_Token::NAME_TYPE, 'webpack_asset')) {
                // We found the webpack function!
                $asset = $this->getAssetFromStream($template_file, $stream);
                $points[$asset] = $this->resolveAssetPath($asset, $template_file, $token);
            }
            // {% webpack_javascripts %} and {% webpack_stylesheets %}
            if ($token->test(\Twig_Token::BLOCK_START_TYPE) && $stream->getCurrent()->test(WebpackTokenParser::TAG_NAME)) {
                $stream->next();
                if ($stream->getCurrent()->getValue() === 'inline') {
                    $stream->next();
                    $token = $stream->next();
                    $file_name = TwigParser::hashInlineFileName($template_file, $inline_blocks);
                    // Are we dealing with a custom extension? If not, fallback to javascript.
                    $extension = 'js';
                    // Default
                    if ($token->test(\Twig_Token::NAME_TYPE)) {
                        $extension = $token->getValue();
                        $stream->next();
                    }
                    file_put_contents($this->cache_dir . '/' . $file_name . '.' . $extension, $this->stripScript($stream->getCurrent()->getValue()));
                    $asset = $file_name . '.' . $extension;
                    $id = 'cache/' . $asset;
                    $points[$id] = $this->resolveAssetPath($this->cache_dir . '/' . $asset, $template_file, $token);
                    $inline_blocks++;
                } else {
                    $stream->next();
                    while (!$stream->isEOF() && !$stream->getCurrent()->test(\Twig_Token::BLOCK_END_TYPE)) {
                        $asset = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
                        $points[$asset] = $this->resolveAssetPath($asset, $template_file, $token);
                    }
                }
            }
        }
        return $points;
    }