parse() public method

public parse ( $code, PhpParser\ErrorHandler $errorHandler = null )
$errorHandler PhpParser\ErrorHandler
Exemplo n.º 1
0
 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');
 }
Exemplo n.º 2
0
 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());
 }
Exemplo n.º 3
0
 /**
  * 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;
 }