From: Michael J. Rubinsky Date: Thu, 8 Jan 2009 19:04:57 +0000 (-0500) Subject: Don't use static members for cache - require the cache object to be passed X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=9464641f354371be7f5ce3275754b26db94d8db7;p=horde.git Don't use static members for cache - require the cache object to be passed around in the constructors --- diff --git a/framework/Service_Vimeo/lib/Horde/Service/Vimeo.php b/framework/Service_Vimeo/lib/Horde/Service/Vimeo.php index 50adc138c..16786ab2d 100644 --- a/framework/Service_Vimeo/lib/Horde/Service/Vimeo.php +++ b/framework/Service_Vimeo/lib/Horde/Service/Vimeo.php @@ -24,8 +24,8 @@ class Horde_Service_Vimeo { */ protected static $_httpClient = null; - protected static $_cache; - protected static $_cache_lifetime; + protected $_cache; + protected $_cache_lifetime; /** * Set the HTTP client instance @@ -71,24 +71,12 @@ class Horde_Service_Vimeo { * @param Horde_Cache $cache The cache object * @param int $lifetime The cache lifetime in seconds */ - public static function setCache($cache, $lifetime = 60) + protected function _setCache($cache, $lifetime = 60) { - self::$_cache = $cache; - self::$_cache_lifetime = $lifetime; + $this->_cache = $cache; + $this->_cache_lifetime = $lifetime; } - - public static function getCache() - { - return self::$_cache; - } - - public static function getCacheLifetime() - { - return self::$_cache_lifetime; - } - - /** * Get the raw JSON response containing the data to embed a single video. * @@ -109,14 +97,16 @@ class Horde_Service_Vimeo { */ public function getEmbedJson($options) { - $request = new Horde_Service_Vimeo_Request(); + $params = array('cache' => array('object' => $this->_cache, + 'lifetime' => $this->_cache_lifetime)); + $request = new Horde_Service_Vimeo_Request($params); return $request->getEmbedJson($options); } /** */ - public function factory($driver = 'Simple') + public function factory($driver = 'Simple', $params = null) { $driver = basename($driver); @@ -130,4 +120,12 @@ class Horde_Service_Vimeo { } } + private function __construct($params) + { + if (isset($params['cache'])) { + $this->_setCache($params['cache'], $params['cache_lifetime']); + } + + } + } \ No newline at end of file diff --git a/framework/Service_Vimeo/lib/Horde/Service/Vimeo/Simple.php b/framework/Service_Vimeo/lib/Horde/Service/Vimeo/Simple.php index c394e1768..eb12390cb 100644 --- a/framework/Service_Vimeo/lib/Horde/Service/Vimeo/Simple.php +++ b/framework/Service_Vimeo/lib/Horde/Service/Vimeo/Simple.php @@ -22,8 +22,9 @@ class Horde_Service_Vimeo_Simple extends Horde_Service_Vimeo { public function __call($name, $args) { $params = array('type' => $name, - 'identifier' => $args[0]); - + 'identifier' => $args[0], + 'cache' => array('object' => $this->_cache, + 'lifetime' => $this->_cache_lifetime)); return new Horde_Service_Vimeo_Request($params); } @@ -67,7 +68,7 @@ class Horde_Service_Vimeo_Request { */ public function __construct($args = array()) { - $this->_cache = Horde_Service_Vimeo::getCache(); + $this->_cache = !empty($args['cache']['object']) ? $args['cache'] : null; if (count($args) && !empty($args['type'])) { // The type of method we are calling (user, group, etc...) @@ -111,6 +112,9 @@ class Horde_Service_Vimeo_Request { * parameter. Passing a url is the most effecient as we won't have to query * the vimeo service for the url. * + * @TODO: Validate that we don't put any extraneous options onto the end + * of the url (in other words, make sure the options passed make + * sense for the method we are calling * @param mixed $options Either an array containing the vimeo url or * vimeo clip id, OR a scaler containing the clip id. @@ -131,9 +135,9 @@ class Horde_Service_Vimeo_Request { // See if we have a cache, and if so, try to get the data from it before // polling the vimeo service. - if (!empty($this->_cache)) { + if (!empty($this->_cache['object'])) { $cache_key = 'VimeoJson' . md5(serialize($options)); - $data = $this->_cache->get($cache_key, Horde_Service_Vimeo::getCacheLifetime()); + $data = $this->_cache['object']->get($cache_key, $this->_cache['lifetime']); if ($data !== false) { return unserialize($data); } @@ -143,10 +147,11 @@ class Horde_Service_Vimeo_Request { $url = Util::addParameter($this->_oembed_endpoint, $options, null, false); $req = Horde_Service_Vimeo::getHttpClient(); + $response = $req->request('GET', $url); $results = $response->getBody(); if (!empty($this->_cache)) { - $this->_cache->set($cache_key, serialize($results)); + $this->_cache['object']->set($cache_key, serialize($results)); } return $results; @@ -156,9 +161,9 @@ class Horde_Service_Vimeo_Request { public function run() { $call = '/' . $this->_identifier . '/' . $this->_method . '.' . Horde_Service_Vimeo::getFormat(); - if (!empty($this->_cache)) { + if (!empty($this->_cache['object'])) { $cache_key = 'VimeoRequest' . md5($call); - $data = $this->_cache->get($cache_key, Horde_Service_Vimeo::getCacheLifetime()); + $data = $this->_cache['object']->get($cache_key, $this->_cache['lifetime']); if ($data !== false) { // php format is already returned serialized if (Horde_Service_Vimeo::getFormat() != 'php') { @@ -173,13 +178,13 @@ class Horde_Service_Vimeo_Request { $response = $req->request('GET', $this->_api_endpoint . $call); $data = $response->getBody(); - if (!empty($this->_cache)) { + if (!empty($this->_cache['object'])) { if (Horde_Service_Vimeo::getFormat() != 'php') { $sdata = serialize($data); } else { $sdata = $data; } - $this->_cache->set($cache_key, $sdata); + $this->_cache['object']->set($cache_key, $sdata); } return $data;