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

parse() public method

Parses the given TypoScript source code and returns an object tree as the result.
public parse ( string $sourceCode, string $contextPathAndFilename = null, array $objectTreeUntilNow = [], boolean $buildPrototypeHierarchy = true ) : array
$sourceCode string The TypoScript source code to parse
$contextPathAndFilename string An optional path and filename to use as a prefix for inclusion of further TypoScript files
$objectTreeUntilNow array Used internally for keeping track of the built object tree
$buildPrototypeHierarchy boolean Merge prototype configurations or not. Will be FALSE for includes to only do that once at the end.
return array A TypoScript object tree, generated from the source code
    public function parse($sourceCode, $contextPathAndFilename = null, array $objectTreeUntilNow = array(), $buildPrototypeHierarchy = true)
    {
        if (!is_string($sourceCode)) {
            throw new Fusion\Exception('Cannot parse TypoScript - $sourceCode must be of type string!', 1180203775);
        }
        $this->initialize();
        $this->objectTree = $objectTreeUntilNow;
        $this->contextPathAndFilename = $contextPathAndFilename;
        $this->currentSourceCodeLines = explode(chr(10), $sourceCode);
        while (($typoScriptLine = $this->getNextTypoScriptLine()) !== false) {
            $this->parseTypoScriptLine($typoScriptLine);
        }
        if ($buildPrototypeHierarchy) {
            $this->buildPrototypeHierarchy();
        }
        return $this->objectTree;
    }

Usage Example

 /**
  * Checks if comments in comments are parsed correctly
  *
  * @test
  */
 public function parserCorrectlyParsesComments01()
 {
     $sourceCode = $this->readTypoScriptFixture('ParserTestTypoScriptComments01');
     $expected = array();
     // Fixture contains only comments, so expect empty parse tree
     $actualParseTree = $this->parser->parse($sourceCode);
     $this->assertEquals($expected, $actualParseTree, 'The parse tree was not as expected after parsing fixture `ParserTestTypoScriptComments01.fusion`');
 }
All Usage Examples Of Neos\Fusion\Core\Parser::parse