Exemplo n.º 1
0
 /**
  * @param string $code
  * @return \EBT\ExtensionBuilder\Domain\Model\File
  */
 public function parseCode($code)
 {
     $stmts = $this->parseRawStatements($code);
     // set defaults
     if (NULL === $this->traverser) {
         $this->traverser = new \EBT\ExtensionBuilder\Parser\Traverser(TRUE);
     }
     if (NULL === $this->fileVisitor) {
         $this->fileVisitor = new \EBT\ExtensionBuilder\Parser\Visitor\FileVisitor();
     }
     if (NULL === $this->classFactory) {
         $this->classFactory = new \EBT\ExtensionBuilder\Parser\ClassFactory();
     }
     $this->fileVisitor->setClassFactory($this->classFactory);
     $this->traverser->appendVisitor($this->fileVisitor);
     $this->traverser->traverse(array($stmts));
     $fileObject = $this->fileVisitor->getFileObject();
     return $fileObject;
 }
Exemplo n.º 2
0
 /**
  * @param array $stmts
  * @param array $replacements
  * @param string $nodeType
  * @param string $nodeProperty
  * @return array
  */
 public function replaceNodeProperty($stmts, $replacements, $nodeType = NULL, $nodeProperty = 'name')
 {
     if (NULL === $this->traverser) {
         $this->traverser = new \EBT\ExtensionBuilder\Parser\Traverser();
     }
     $this->traverser->resetVisitors();
     $visitor = new \EBT\ExtensionBuilder\Parser\Visitor\ReplaceVisitor();
     $visitor->setNodeType($nodeType)->setNodeProperty($nodeProperty)->setReplacements($replacements);
     $this->traverser->appendVisitor($visitor);
     $stmts = $this->traverser->traverse($stmts);
     $this->traverser->resetVisitors();
     return $stmts;
 }