/** * Removes temporary test contents. * * @return void */ protected function setUp() { parent::setUp(); $run = dirname(__FILE__) . '/_run'; if (file_exists($run) === false) { mkdir($run, 0755); } $this->_clearRunResources($run); include_once 'PHP/Depend.php'; include_once 'PHP/Depend/StorageRegistry.php'; include_once 'PHP/Depend/Storage/MemoryEngine.php'; PHP_Depend_StorageRegistry::set(PHP_Depend::TOKEN_STORAGE, new PHP_Depend_Storage_MemoryEngine()); PHP_Depend_StorageRegistry::set(PHP_Depend::PARSER_STORAGE, new PHP_Depend_Storage_MemoryEngine()); if (defined('STDERR') === false) { define('STDERR', fopen('php://stderr', true)); } }
/** * Sets the tokens for this file. * * @param array(array) $tokens The generated tokens. * * @return void */ public function setTokens(array $tokens) { $storage = PHP_Depend_StorageRegistry::get(PHP_Depend::TOKEN_STORAGE); $storage->store($tokens, md5($this->_fileName), __CLASS__); }
/** * Sets a new php source file. * * @param string $sourceFile A php source file. * * @return void */ public function setSourceFile($sourceFile) { $storage = PHP_Depend_StorageRegistry::get(PHP_Depend::PARSER_STORAGE); $id = '$Id$-@package_version@'; $key = md5_file($sourceFile); $group = get_class($this->_tokenizer); $tokens = $storage->restore($key, $group, $id); if (is_array($tokens)) { $this->_sourceFile = new PHP_Depend_Code_File($sourceFile); $this->_sourceFile->setTokens($tokens); } else { $this->_tokenizer->setSourceFile($sourceFile); $this->_sourceFile = $this->_tokenizer->getSourceFile(); $tokens = $this->_sourceFile->getTokens(); $storage->store($tokens, $key, $group, $id); } $this->_tokens = $tokens; $this->_index = 0; $this->_count = count($tokens); }
/** * Sets the tokens found in the function body. * * @param array(mixed) $tokens The body tokens. * * @return void */ public function setTokens(array $tokens) { $this->_startLine = reset($tokens)->startLine; $this->_endLine = end($tokens)->endLine; $storage = PHP_Depend_StorageRegistry::get(PHP_Depend::TOKEN_STORAGE); $storage->store($tokens, $this->getUUID(), get_class($this)); }
/** * Sets the tokens found in the function body. * * @param array(mixed) $tokens The body tokens. * * @return void */ public function setTokens(array $tokens) { $storage = PHP_Depend_StorageRegistry::get(PHP_Depend::TOKEN_STORAGE); $storage->store($tokens, $this->getUUID(), get_class($this)); }
/** * This method initializes the storage strategies for node tokens that are * used during a single PHP_Depend run and the parser cache storage. * * @return void */ private function _initStorages() { foreach ($this->_storages as $identifier => $storage) { // Fallback for unconfigured storage engines if ($storage === null) { // Include memory storage class definition include_once 'PHP/Depend/Storage/MemoryEngine.php'; $storage = new PHP_Depend_Storage_MemoryEngine(); } PHP_Depend_StorageRegistry::set($identifier, $storage); } }
/** * Tests that the registry throws an exception when an invalid engine key * is used. * * @return void */ public function testRegistryThrowsExpectedExceptionForInvalidEngineKey() { $storageKey = uniqid(md5(rand(0, PHP_INT_MAX)), true); $this->setExpectedException('OutOfRangeException', sprintf('Invalid storage identifier "%s" given.', $storageKey)); PHP_Depend_StorageRegistry::get($storageKey); }