setCache() public method

Setter method for the used parser and token cache.
Since: 0.10.0
public setCache ( PDepend\Util\Cache\CacheDriver $cache ) : ASTCompilationUnit
$cache PDepend\Util\Cache\CacheDriver
return ASTCompilationUnit
Esempio n. 1
0
 /**
  * Parses the contents of the tokenizer and generates a node tree based on
  * the found tokens.
  *
  * @return void
  */
 public function parse()
 {
     $this->compilationUnit = $this->tokenizer->getSourceFile();
     $this->compilationUnit->setCache($this->cache)->setId($this->idBuilder->forFile($this->compilationUnit));
     $hash = md5_file($this->compilationUnit->getFileName());
     if ($this->cache->restore($this->compilationUnit->getId(), $hash)) {
         return;
     }
     $this->cache->remove($this->compilationUnit->getId());
     $this->setUpEnvironment();
     $this->tokenStack->push();
     Log::debug('Processing file ' . $this->compilationUnit);
     $tokenType = $this->tokenizer->peek();
     while ($tokenType !== Tokenizer::T_EOF) {
         switch ($tokenType) {
             case Tokens::T_COMMENT:
                 $this->consumeToken(Tokens::T_COMMENT);
                 break;
             case Tokens::T_DOC_COMMENT:
                 $comment = $this->consumeToken(Tokens::T_DOC_COMMENT)->image;
                 $this->packageName = $this->parsePackageAnnotation($comment);
                 $this->docComment = $comment;
                 break;
             case Tokens::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 Tokens::T_NAMESPACE:
                 $this->parseNamespaceDeclaration();
                 break;
             case Tokens::T_NO_PHP:
             case Tokens::T_OPEN_TAG:
             case Tokens::T_OPEN_TAG_WITH_ECHO:
                 $this->consumeToken($tokenType);
                 $this->reset();
                 break;
             case Tokens::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->compilationUnit->setTokens($this->tokenStack->pop());
     $this->cache->store($this->compilationUnit->getId(), $this->compilationUnit, $hash);
     $this->tearDownEnvironment();
 }
 /**
  * testSetTokensDelegatesCallToCacheStoreWithFileId
  *
  * @return void
  */
 public function testSetTokensDelegatesCallToCacheStoreWithFileId()
 {
     $cache = $this->createCacheFixture();
     $cache->expects($this->once())->method('type')->with(self::equalTo('tokens'))->will($this->returnValue($cache));
     $cache->expects($this->once())->method('store')->with(self::equalTo(__FUNCTION__), self::equalTo(array(1, 2, 3)));
     $compilationUnit = new ASTCompilationUnit(null);
     $compilationUnit->setCache($cache);
     $compilationUnit->setId(__FUNCTION__);
     $compilationUnit->setTokens(array(1, 2, 3));
 }