Permalink
Browse files

Add Cache::get_handler()

To try and fix compatibility issues, add Cache::get_handler() This is now called instead of Cache::create(), *except* if the cache handler is registered via the legacy method.
  • Loading branch information...
1 parent af76999 commit 9aa3385b315bf0831edaef4815ad8d9317690974 @rmccue rmccue committed Oct 11, 2012
Showing with 29 additions and 4 deletions.
  1. +2 −2 library/SimplePie.php
  2. +11 −1 library/SimplePie/Cache.php
  3. +15 −0 library/SimplePie/Registry.php
  4. +1 −1 library/SimplePie/Sanitize.php
View
@@ -1263,7 +1263,7 @@ public function init()
// Decide whether to enable caching
if ($this->cache && $parsed_feed_url['scheme'] !== '')
{
- $cache = $this->registry->call('Cache', 'create', array($this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc'));
+ $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc'));
}
// Fetch the data via SimplePie_File into $this->raw_data
@@ -1513,7 +1513,7 @@ protected function fetch_data(&$cache)
{
trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
}
- $cache = $this->registry->call('Cache', 'create', array($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc'));
+ $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc'));
}
$this->feed_url = $file->url;
}
@@ -79,7 +79,7 @@ private function __construct() { }
* @param string $extension 'spi' or 'spc'
* @return SimplePie_Cache_Base Type of object depends on scheme of `$location`
*/
- public static function create($location, $filename, $extension)
+ public static function get_handler($location, $filename, $extension)
{
$type = explode(':', $location, 2);
$type = $type[0];
@@ -93,6 +93,16 @@ public static function create($location, $filename, $extension)
}
/**
+ * Create a new SimplePie_Cache object
+ *
+ * @deprecated Use {@see get_handler} instead
+ */
+ public function create($location, $filename, $extension)
+ {
+ return self::get_handler($location, $filename, $extension);
+ }
+
+ /**
* Register a handler
*
* @param string $type DSN type to register for
@@ -203,6 +203,21 @@ public function &call($type, $method, $parameters = array())
{
$class = $this->get_class($type);
+ if (in_array($class, $this->legacy))
+ {
+ switch ($type)
+ {
+ case 'Cache':
+ // For backwards compatibility with old non-static
+ // Cache::create() methods
+ if ($method === 'get_handler')
+ {
+ $method = 'create';
+ }
+ break;
+ }
+ }
+
$result = call_user_func_array(array($class, $method), $parameters);
return $result;
}
@@ -302,7 +302,7 @@ public function sanitize($data, $type, $base = '')
if ($img->hasAttribute('src'))
{
$image_url = call_user_func($this->cache_name_function, $img->getAttribute('src'));
- $cache = $this->registry->call('Cache', 'create', array($this->cache_location, $image_url, 'spi'));
+ $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, $image_url, 'spi'));
if ($cache->load())
{

0 comments on commit 9aa3385

Please sign in to comment.