/** * @see stream_stat(). */ public function url_stat($path, $flags) { $url = $this->parseUrl($path); \AJXP_Logger::debug("STATING " . $path); $base = $url["host"]; //dirname($path)."/"; $name = basename($path); if (isset(self::$statCacheData["HPC_MAIN_PATH"]) && $path . "/" == self::$statCacheData["HPC_MAIN_PATH"]) { return $this->fakeStat(true); } if (isset(self::$statCache[$name]) && self::$statCacheData["HPC_MAIN_PATH"] == $base) { return self::$statCache[$name]; } if (is_array(self::$statCache) && isset(self::$statCache[$path])) { \AJXP_Logger::debug("Cached path!"); return self::$statCache[$path]; } if (empty($url['host']) || empty($url['path'])) { if ($flags & STREAM_URL_STAT_QUIET) { trigger_error('Container name (host) and path are required.', E_USER_WARNING); } return FALSE; } try { $this->initializeObjectStorage(); // Since we are throwing the $container away without really using its // internals, we create an unchecked container. It may not actually // exist on the server, which will cause a 404 error. //$container = $this->store->container($url['host']); $name = $url['host']; try { if (isset(self::$statCacheData["HPC_CONTAINER"]) && self::$statCacheData["HPC_MAIN_PATH"] == $name) { \AJXP_Logger::debug("URL_STAT Getting container from cache"); $container = self::$statCacheData["HPC_CONTAINER"]; } else { \AJXP_Logger::debug("URL_STAT Instanciating container " . $name); $token = $this->store->token(); $endpoint_url = $this->store->url() . '/' . rawurlencode($name); $container = new \HPCloud\Storage\ObjectStorage\Container($name, $endpoint_url, $token); self::$statCacheData["HPC_MAIN_PATH"] = $name; self::$statCacheData["HPC_CONTAINER"] = $container; } } catch (\HPCloud\Transport\FileNotFoundException $e) { trigger_error('Container not found.', E_USER_WARNING); return FALSE; } $obj = $container->remoteObject($url['path']); } catch (\HPCloud\Exception $e) { // Apparently file_exists does not set STREAM_URL_STAT_QUIET. //if ($flags & STREAM_URL_STAT_QUIET) { //trigger_error('Could not stat remote file: ' . $e->getMessage(), E_USER_WARNING); //} return FALSE; } if (!is_array(self::$statCache)) { self::$statCache = array(); } if ($flags & STREAM_URL_STAT_QUIET) { try { $s = @$this->generateStat($obj, $container, $obj->contentLength()); \AJXP_Logger::debug("CACHING1 " . $path, array_keys(self::$statCache)); self::$statCache[$path] = $s; return $s; } catch (\HPCloud\Exception $e) { return FALSE; } } $s = $this->generateStat($obj, $container, $obj->contentLength()); self::$statCache[$path] = $s; \AJXP_Logger::debug("CACHING2 " . $path, array_keys(self::$statCache)); return $s; }
/** * @see stream_stat(). */ public function url_stat($path, $flags) { $url = $this->parseUrl($path); if (empty($url['host']) || empty($url['path'])) { if ($flags & STREAM_URL_STAT_QUIET) { trigger_error('Container name (host) and path are required.', E_USER_WARNING); } return FALSE; } try { $this->initializeObjectStorage(); // Since we are throwing the $container away without really using its // internals, we create an unchecked container. It may not actually // exist on the server, which will cause a 404 error. //$container = $this->store->container($url['host']); $name = $url['host']; $token = $this->store->token(); $endpoint_url = $this->store->url() . '/' . rawurlencode($name); $container = new \HPCloud\Storage\ObjectStorage\Container($name, $endpoint_url, $token); $obj = $container->remoteObject($url['path']); } catch (\HPCloud\Exception $e) { // Apparently file_exists does not set STREAM_URL_STAT_QUIET. //if ($flags & STREAM_URL_STAT_QUIET) { //trigger_error('Could not stat remote file: ' . $e->getMessage(), E_USER_WARNING); //} return FALSE; } if ($flags & STREAM_URL_STAT_QUIET) { try { return @$this->generateStat($obj, $container, $obj->contentLength()); } catch (\HPCloud\Exception $e) { return FALSE; } } return $this->generateStat($obj, $container, $obj->contentLength()); }