diff --git a/includes/FeedsHTTPCacheItem.inc b/includes/FeedsHTTPCacheItem.inc index 8623f35..8d3c73a 100644 --- a/includes/FeedsHTTPCacheItem.inc +++ b/includes/FeedsHTTPCacheItem.inc @@ -25,21 +25,19 @@ class FeedsHTTPCacheItem { * The HTTP response object. */ public function __construct($result) { - if (isset($result->headers) && is_array($result->headers)) { - $this->headers = $result->headers; - } - if (isset($result->file_path)) { - $this->setFilePath($result->file_path); - } - // Copy over other metadata from result, but not the raw data. // Value is assigned by reference to save memory. foreach ($result as $key => &$value) { switch ($key) { case 'headers': + $this->headers = (array) $value; + break; + case 'file_path': + $this->setFilePath($value); + break; + case 'data': - // Headers and file path are already set above. // Data should not be cached, so this one is not set! break; @@ -63,6 +61,12 @@ class FeedsHTTPCacheItem { * Magic isset. */ public function __isset($member) { + if ($member == 'data') { + // Data should always be cached to a file, so in that case we check if the + // file exist where the data should be in. + return (isset($this->file_path) && file_exists($this->file_path)); + } + return isset($this->$member); } @@ -70,11 +74,21 @@ class FeedsHTTPCacheItem { * Magic getter. */ public function __get($member) { + if ($member == 'data') { + // Data is cached in a file, so when that member is requested, return the + // file contents. + return $this->getFileContents(); + } + return $this->$member; } /** * Gets the cached file from the file system. + * + * @return string|null + * The file's contents, if the file exists. + * NULL otherwise. */ public function getFileContents() { if (file_exists($this->file_path)) {