Exemplo n.º 1
0
 /**
  * The magic sleep method is called by the PHP runtime environment before an
  * instance of this class gets serialized. It returns an array with the
  * names of all those properties that should be cached for this class or
  * interface instance.
  *
  * @return array
  */
 public function __sleep()
 {
     if (is_array($this->methods)) {
         $this->cache->type('methods')->store($this->uuid, $this->methods);
         $this->methods = null;
     }
     return array('cache', 'context', 'docComment', 'endLine', 'modifiers', 'name', 'nodes', 'packageName', 'startLine', 'userDefined', 'uuid');
 }
Exemplo n.º 2
0
 /**
  * Sets the tokens for this file.
  *
  * @param array(array) $tokens The generated tokens.
  *
  * @return void
  */
 public function setTokens(array $tokens)
 {
     return $this->cache->type('tokens')->store($this->getUUID(), $tokens);
 }
Exemplo n.º 3
0
 /**
  * Parses the contents of the tokenizer and generates a node tree based on
  * the found tokens.
  *
  * @return void
  */
 public function parse()
 {
     $this->_sourceFile = $this->tokenizer->getSourceFile();
     $this->_sourceFile->setCache($this->cache)->setUUID($this->_uuidBuilder->forFile($this->_sourceFile));
     $hash = md5_file($this->_sourceFile->getFileName());
     if ($this->cache->restore($this->_sourceFile->getUUID(), $hash)) {
         return;
     }
     $this->cache->remove($this->_sourceFile->getUUID());
     $this->setUpEnvironment();
     $this->_tokenStack->push();
     PHP_Depend_Util_Log::debug('Processing file ' . $this->_sourceFile);
     $tokenType = $this->tokenizer->peek();
     while ($tokenType !== self::T_EOF) {
         switch ($tokenType) {
             case self::T_COMMENT:
                 $this->consumeToken(self::T_COMMENT);
                 break;
             case self::T_DOC_COMMENT:
                 $comment = $this->consumeToken(self::T_DOC_COMMENT)->image;
                 $this->_packageName = $this->_parsePackageAnnotation($comment);
                 $this->_docComment = $comment;
                 break;
             case self::T_USE:
                 // Parse a use statement. This method has no return value but it
                 // creates a new entry in the symbol map.
                 $this->_parseUseDeclarations();
                 break;
             case self::T_NAMESPACE:
                 $this->_parseNamespaceDeclaration();
                 break;
             case self::T_NO_PHP:
             case self::T_OPEN_TAG:
             case self::T_OPEN_TAG_WITH_ECHO:
                 $this->consumeToken($tokenType);
                 $this->reset();
                 break;
             case self::T_CLOSE_TAG:
                 $this->_parseNonePhpCode();
                 $this->reset();
                 break;
             default:
                 if (null === $this->_parseOptionalStatement()) {
                     // Consume whatever token
                     $this->consumeToken($tokenType);
                 }
                 break;
         }
         $tokenType = $this->tokenizer->peek();
     }
     $this->_sourceFile->setTokens($this->_tokenStack->pop());
     $this->cache->store($this->_sourceFile->getUUID(), $this->_sourceFile, $hash);
     $this->tearDownEnvironment();
 }
Exemplo n.º 4
0
 /**
  * Sets the tokens for this type.
  *
  * @param array(PHP_Depend_Token) $tokens The generated tokens.
  *
  * @return void
  */
 public function setTokens(array $tokens)
 {
     $this->startLine = reset($tokens)->startLine;
     $this->endLine = end($tokens)->endLine;
     $this->cache->type('tokens')->store($this->uuid, $tokens);
 }
Exemplo n.º 5
0
 /**
  * Parses the contents of the tokenizer and generates a node tree based on
  * the found tokens.
  *
  * @return void
  */
 public function parse()
 {
     // Get currently parsed source file
     $this->_sourceFile = $this->tokenizer->getSourceFile();
     $this->_sourceFile->setCache($this->cache)->setUUID($this->_uuidBuilder->forFile($this->_sourceFile));
     $hash = md5_file($this->_sourceFile->getFileName());
     if ($this->cache->restore($this->_sourceFile->getUUID(), $hash)) {
         return;
     }
     $this->cache->remove($this->_sourceFile->getUUID());
     $this->setUpEnvironment();
     $this->_tokenStack->push();
     // Debug currently parsed source file.
     PHP_Depend_Util_Log::debug('Processing file ' . $this->_sourceFile);
     $tokenType = $this->tokenizer->peek();
     while ($tokenType !== self::T_EOF) {
         switch ($tokenType) {
             case self::T_COMMENT:
                 $this->consumeToken(self::T_COMMENT);
                 break;
             case self::T_DOC_COMMENT:
                 $comment = $this->consumeToken(self::T_DOC_COMMENT)->image;
                 $this->_packageName = $this->_parsePackageAnnotation($comment);
                 $this->_docComment = $comment;
                 break;
             case self::T_INTERFACE:
                 $package = $this->_builder->buildPackage($this->_getNamespaceOrPackageName());
                 $package->addType($interface = $this->_parseInterfaceDeclaration());
                 $this->_builder->restoreInterface($interface);
                 $this->_sourceFile->addChild($interface);
                 break;
             case self::T_CLASS:
             case self::T_FINAL:
             case self::T_ABSTRACT:
                 $package = $this->_builder->buildPackage($this->_getNamespaceOrPackageName());
                 $package->addType($class = $this->_parseClassDeclaration());
                 $this->_builder->restoreClass($class);
                 $this->_sourceFile->addChild($class);
                 break;
             case self::T_FUNCTION:
                 $callable = $this->_parseFunctionOrClosureDeclaration();
                 $this->_sourceFile->addChild($callable);
                 break;
             case self::T_USE:
                 // Parse a use statement. This method has no return value but it
                 // creates a new entry in the symbol map.
                 $this->_parseUseDeclarations();
                 break;
             case self::T_NAMESPACE:
                 $this->_parseNamespaceDeclaration();
                 break;
             default:
                 // Consume whatever token
                 $this->consumeToken($tokenType);
                 $this->reset();
                 break;
         }
         $tokenType = $this->tokenizer->peek();
     }
     $this->_sourceFile->setTokens($this->_tokenStack->pop());
     $this->cache->store($this->_sourceFile->getUUID(), $this->_sourceFile, $hash);
     $this->tearDownEnvironment();
 }
Exemplo n.º 6
0
 /**
  * Unloads the metrics cache and stores the current set of metrics in the
  * cache.
  *
  * @return void
  */
 protected function unloadCache()
 {
     $this->_cache->type('metrics')->store(get_class($this), $this->metrics);
     $this->_metricsCached = array();
 }