Neos\Fusion\Core\Parser::parseInclude PHP Method

parseInclude() protected method

Parse an include file. Currently, we start a new parser object; but we could as well re-use the given one.
protected parseInclude ( string $include ) : void
$include string The include value, for example " FooBar" or " resource://....". Can also include wildcard mask for TypoScript globbing.
return void
    protected function parseInclude($include)
    {
        $include = trim($include);
        $parser = clone $this;
        if (strpos($include, 'resource://') !== 0) {
            // Resolve relative paths
            if ($this->contextPathAndFilename !== null) {
                $include = dirname($this->contextPathAndFilename) . '/' . $include;
            } else {
                throw new Fusion\Exception('Relative file inclusions are only possible if a context path and filename has been passed as second argument to parse()', 1329806940);
            }
        }
        // Match recursive wildcard globbing "**/*"
        if (preg_match('#([^\\*]*)\\*\\*/\\*#', $include, $matches) === 1) {
            $basePath = $matches['1'];
            if (!is_dir($basePath)) {
                throw new Fusion\Exception(sprintf('The path %s does not point to a directory.', $basePath), 1415033179);
            }
            $recursiveDirectoryIterator = new \RecursiveDirectoryIterator($basePath);
            $iterator = new \RecursiveIteratorIterator($recursiveDirectoryIterator);
            // Match simple wildcard globbing "*"
        } elseif (preg_match('#([^\\*]*)\\*#', $include, $matches) === 1) {
            $basePath = $matches['1'];
            if (!is_dir($basePath)) {
                throw new Fusion\Exception(sprintf('The path %s does not point to a directory.', $basePath), 1415033180);
            }
            $iterator = new \DirectoryIterator($basePath);
        }
        // If iterator is set it means we're doing globbing
        if (isset($iterator)) {
            foreach ($iterator as $fileInfo) {
                $pathAndFilename = $fileInfo->getPathname();
                // Only work on .fusion files and .ts2 files. The support for .ts2 is deprecated a fallback and will be dropped with 4.0
                if ($fileInfo->getExtension() === 'fusion' || $fileInfo->getExtension() === 'ts2') {
                    // Check if not trying to recursively include the current file via globbing
                    if (stat($pathAndFilename) !== stat($this->contextPathAndFilename)) {
                        if (!is_readable($pathAndFilename)) {
                            throw new Fusion\Exception(sprintf('Could not include TypoScript file "%s"', $pathAndFilename), 1347977018);
                        }
                        $this->objectTree = $parser->parse(file_get_contents($pathAndFilename), $pathAndFilename, $this->objectTree, false);
                    }
                }
            }
        } else {
            if (!is_readable($include)) {
                throw new Fusion\Exception(sprintf('Could not include TypoScript file "%s"', $include), 1347977017);
            }
            $this->objectTree = $parser->parse(file_get_contents($include), $include, $this->objectTree, false);
        }
    }