示例#1
0
 /**
  *
  * @param SourceFile $sourceFile
  *
  * @throws ParseErrorException
  * @return ParseResult
  */
 public function parse(SourceFile $sourceFile) {
     try {
         $result = new ParseResult($sourceFile->getFileInfo());
         $parser = $this->getParserInstance();
         $nodes = $parser->parse($sourceFile->getSource());
         $this->getTraverserInstance($result)->traverse($nodes);
         return $result;
     } catch (\Exception $e) {
         throw new ParseErrorException('Something went wrwong', ParseErrorException::GeneralParseError, $e);
     }
 }
示例#2
0
 /**
  *
  * @param SourceFile $sourceFile
  *
  * @throws ParseErrorException
  * @return ParseResult
  */
 public function parse(SourceFile $sourceFile)
 {
     try {
         $result = new ParseResult($sourceFile);
         $parser = $this->getParserInstance();
         $nodes = $parser->parse($sourceFile->getSource());
         if (!$nodes) {
             throw new ParseErrorException("Parser didn't return any nodes", ParseErrorException::GeneralParseError);
         }
         $this->getTraverserInstance($result)->traverse($nodes);
         return $result;
     } catch (\Exception $e) {
         $this->errorHandler->clearLastError();
         throw new ParseErrorException('Internal Error during parsing', ParseErrorException::GeneralParseError, $e);
     }
 }
示例#3
0
 /**
  * @param string       $name
  * @param \SplFileInfo $file
  */
 public function __construct($name = NULL, SourceFile $file = NULL)
 {
     if ($this->rootName === NULL) {
         throw new UnitObjectException('No or invalid rootname set', UnitObjectException::InvalidRootname);
     }
     $this->dom = new fDOMDocument('1.0', 'UTF-8');
     $this->dom->registerNamespace('phpdox', self::XMLNS);
     $this->rootNode = $this->dom->createElementNS(self::XMLNS, $this->rootName);
     $this->dom->appendChild($this->rootNode);
     if ($name !== NULL) {
         $this->setName($name, $this->rootNode);
     }
     if ($file !== NULL) {
         $this->rootNode->appendChild($file->asNode($this->rootNode));
     }
     $this->setAbstract(FALSE);
     $this->setFinal(FALSE);
 }
示例#4
0
 /**
  * @param FileInfo $file
  *
  * @throws CollectorException
  * @throws \TheSeer\phpDox\ProgressLoggerException
  *
  * @return bool
  */
 private function processFile(SourceFile $file)
 {
     try {
         if ($file->getSize() === 0) {
             $this->logger->progress('processed');
             return true;
         }
         $result = $this->backend->parse($file);
         if ($result->hasClasses()) {
             foreach ($result->getClasses() as $class) {
                 $this->project->addClass($class);
             }
         }
         if ($result->hasInterfaces()) {
             foreach ($result->getInterfaces() as $interface) {
                 $this->project->addInterface($interface);
             }
         }
         if ($result->hasTraits()) {
             foreach ($result->getTraits() as $trait) {
                 $this->project->addTrait($trait);
             }
         }
         $this->logger->progress('processed');
         return true;
     } catch (ParseErrorException $e) {
         $this->parseErrors[$file->getPathname()] = $e->getPrevious()->getMessage();
         $this->logger->progress('failed');
         return false;
     } catch (\Exception $e) {
         throw new CollectorException('Error while processing source file', CollectorException::ProcessingError, $e, $file);
     }
 }
示例#5
0
 public function setTokenFileReference(SourceFile $file, $tokenPath)
 {
     $path = $file->getRealPath();
     if (!isset($this->collection[$path])) {
         throw new SourceCollectionException(sprintf("File %s not found in collection", $path), SourceCollectionException::SourceNotFound);
     }
     $this->collection[$path]->setAttribute('xml', $tokenPath);
 }