parse() public method

public parse ( $code, PhpParser\ErrorHandler $errorHandler = null )
$errorHandler PhpParser\ErrorHandler
コード例 #1
0
ファイル: MultipleTest.php プロジェクト: nikic/php-parser
 public function testThrownError()
 {
     $this->setExpectedException('PhpParser\\Error', 'FAIL A');
     $parserA = $this->getMockBuilder('PhpParser\\Parser')->getMock();
     $parserA->expects($this->at(0))->method('parse')->will($this->throwException(new Error('FAIL A')));
     $parserB = $this->getMockBuilder('PhpParser\\Parser')->getMock();
     $parserB->expects($this->at(0))->method('parse')->will($this->throwException(new Error('FAIL B')));
     $parser = new Multiple([$parserA, $parserB]);
     $parser->parse('dummy');
 }
コード例 #2
0
ファイル: MultipleTest.php プロジェクト: saj696/pipe
 public function testGetErrors()
 {
     $errorsA = [new Error('A1'), new Error('A2')];
     $parserA = $this->getMockBuilder('PhpParser\\Parser')->getMock();
     $parserA->expects($this->at(0))->method('parse');
     $parserA->expects($this->at(1))->method('getErrors')->will($this->returnValue($errorsA));
     $errorsB = [new Error('B1'), new Error('B2')];
     $parserB = $this->getMockBuilder('PhpParser\\Parser')->getMock();
     $parserB->expects($this->at(0))->method('parse');
     $parserB->expects($this->at(1))->method('getErrors')->will($this->returnValue($errorsB));
     $parser = new Multiple([$parserA, $parserB]);
     $parser->parse('dummy');
     $this->assertSame($errorsA, $parser->getErrors());
 }
コード例 #3
0
ファイル: PHP.php プロジェクト: bazo/nette-translation
 /**
  * Parses given file and returns found gettext phrases
  *
  * @param string $file
  * @return array
  */
 public function extract($file)
 {
     $this->data = [];
     $lexer = new Lexer();
     //$parser		 = new Parser($lexer);
     $php5Parser = new Php5($lexer);
     $php7Parser = new Php7($lexer);
     $parsers = [$php5Parser, $php7Parser];
     $parser = new Multiple($parsers);
     $stmts = $parser->parse(file_get_contents($file));
     $traverser = new NodeTraverser();
     $traverser->addVisitor($this);
     $traverser->traverse($stmts);
     $data = $this->data;
     $this->data = NULL;
     return $data;
 }