pluginManager = $plugin_manager; $this->logger = $logger; $this->configFactory = $config_factory; $this->fileSystem = $file_system; $this->cache = $cache_service; } /** * Returns an hash for the URI, used internally by the manager. * * @param string $uri * The URI to a file. * * @return string * An hash string. */ protected function calculateHash($uri) { // Sanitize URI removing duplicate slashes, if any. // @see http://stackoverflow.com/questions/12494515/remove-unnecessary-slashes-from-path $uri = preg_replace('/([^:])(\/{2,})/', '$1/', $uri); // If URI is invalid and no local file path exists, return NULL. if (!file_valid_uri($uri) && !$this->fileSystem->realpath($uri)) { return NULL; } // Return a hash of the URI. return hash('sha256', $uri); } /** * {@inheritdoc} */ public function has($uri) { $hash = $this->calculateHash($uri); return $hash ? isset($this->files[$hash]) : NULL; } /** * {@inheritdoc} */ public function uri($uri) { if (!$hash = $this->calculateHash($uri)) { return NULL; } if (!isset($this->files[$hash])) { $this->files[$hash] = new FileMetadata($this->pluginManager, $this->logger, $this->fileSystem, $uri, $hash); } return $this->files[$hash]; } /** * {@inheritdoc} */ public function deleteCachedMetadata($uri) { if (!$hash = $this->calculateHash($uri)) { return FALSE; } foreach (array_keys($this->pluginManager->getDefinitions()) as $plugin_id) { $this->cache->delete("hash:{$plugin_id}:{$hash}"); } return TRUE; } /** * {@inheritdoc} */ public function release($uri) { if (!$hash = $this->calculateHash($uri)) { return FALSE; } if (isset($this->files[$hash])) { unset($this->files[$hash]); return TRUE; } return FALSE; } /** * {@inheritdoc} */ public function count() { return count($this->files); } }