From: Michael J. Rubinsky Date: Thu, 8 Jan 2009 01:13:06 +0000 (-0500) Subject: Actually, makes more sense and is cleaner to use a static setter/getter X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=2329188978a278dd671d8cdea439a3004b59409b;p=horde.git Actually, makes more sense and is cleaner to use a static setter/getter for the vimeo cache. --- diff --git a/framework/Service_Vimeo/lib/Horde/Service/Vimeo.php b/framework/Service_Vimeo/lib/Horde/Service/Vimeo.php index aad3c99b9..50adc138c 100644 --- a/framework/Service_Vimeo/lib/Horde/Service/Vimeo.php +++ b/framework/Service_Vimeo/lib/Horde/Service/Vimeo.php @@ -24,6 +24,9 @@ class Horde_Service_Vimeo { */ protected static $_httpClient = null; + protected static $_cache; + protected static $_cache_lifetime; + /** * Set the HTTP client instance * @@ -61,6 +64,31 @@ class Horde_Service_Vimeo { self::$_format = $format; } + + /** + * Inject a cache obect + * + * @param Horde_Cache $cache The cache object + * @param int $lifetime The cache lifetime in seconds + */ + public static function setCache($cache, $lifetime = 60) + { + self::$_cache = $cache; + self::$_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. * @@ -81,10 +109,7 @@ class Horde_Service_Vimeo { */ public function getEmbedJson($options) { - if (!empty($this->_cache)) { - $params = array('cache' => array('object' => $this->_cache, 'lifetime' => $this->_cache_lifetime)); - } - $request = new Horde_Service_Vimeo_Request($params); + $request = new Horde_Service_Vimeo_Request(); return $request->getEmbedJson($options); } diff --git a/framework/Service_Vimeo/lib/Horde/Service/Vimeo/Simple.php b/framework/Service_Vimeo/lib/Horde/Service/Vimeo/Simple.php index aad10dc87..c394e1768 100644 --- a/framework/Service_Vimeo/lib/Horde/Service/Vimeo/Simple.php +++ b/framework/Service_Vimeo/lib/Horde/Service/Vimeo/Simple.php @@ -13,28 +13,6 @@ class Horde_Service_Vimeo_Simple extends Horde_Service_Vimeo { /** - * An optional cache object that implments the same interface as - * Horde_Cache - * - * @var Horde_Cache - */ - protected $_cache; - protected $_cache_lifetime; - - - /** - * Inject a cache obect - * - * @param Horde_Cache $cache The cache object - * @param int $lifetime The cache lifetime in seconds - */ - public function setCache($cache, $lifetime = 1) - { - $this->_cache = $cache; - $this->_cache_lifetime = $lifetime; - } - - /** * Set up a request based on the method name. * * @TODO: validate that we have a valid method or throw an exception @@ -44,9 +22,7 @@ class Horde_Service_Vimeo_Simple extends Horde_Service_Vimeo { public function __call($name, $args) { $params = array('type' => $name, - 'identifier' => $args[0], - 'cache' => array('object' => $this->_cache, - 'lifetime' => $this->_cache_lifetime)); + 'identifier' => $args[0]); return new Horde_Service_Vimeo_Request($params); } @@ -91,27 +67,25 @@ class Horde_Service_Vimeo_Request { */ public function __construct($args = array()) { - if (count($args)) { - $this->_cache = isset($args['cache']) ? $args['cache'] : null; - if (!empty($args['type'])) { - - // The type of method we are calling (user, group, etc...) - $this->_type = $args['type']; - - switch ($args['type']) { - case 'user': - $this->_identifier = $args['identifier']; - break; - case 'group': - $this->_identifier = '/group/' . $args['identifier']; - break; - case 'channel': - $this->_identifier = '/channel/' . $args['identifier']; - break; - case 'album': - $this->_identifier = '/album/' . $args['identifier']; - break; - } + $this->_cache = Horde_Service_Vimeo::getCache(); + + if (count($args) && !empty($args['type'])) { + // The type of method we are calling (user, group, etc...) + $this->_type = $args['type']; + + switch ($args['type']) { + case 'user': + $this->_identifier = $args['identifier']; + break; + case 'group': + $this->_identifier = '/group/' . $args['identifier']; + break; + case 'channel': + $this->_identifier = '/channel/' . $args['identifier']; + break; + case 'album': + $this->_identifier = '/album/' . $args['identifier']; + break; } } } @@ -157,9 +131,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['object'])) { + if (!empty($this->_cache)) { $cache_key = 'VimeoJson' . md5(serialize($options)); - $data = $this->_cache['object']->get($cache_key, $this->_cache['lifetime']); + $data = $this->_cache->get($cache_key, Horde_Service_Vimeo::getCacheLifetime()); if ($data !== false) { return unserialize($data); } @@ -172,7 +146,7 @@ class Horde_Service_Vimeo_Request { $response = $req->request('GET', $url); $results = $response->getBody(); if (!empty($this->_cache)) { - $this->_cache['object']->set($cache_key, serialize($results)); + $this->_cache->set($cache_key, serialize($results)); } return $results; @@ -182,9 +156,9 @@ class Horde_Service_Vimeo_Request { public function run() { $call = '/' . $this->_identifier . '/' . $this->_method . '.' . Horde_Service_Vimeo::getFormat(); - if (!empty($this->_cache['object'])) { + if (!empty($this->_cache)) { $cache_key = 'VimeoRequest' . md5($call); - $data = $this->_cache['object']->get($cache_key, $this->_cache['lifetime']); + $data = $this->_cache->get($cache_key, Horde_Service_Vimeo::getCacheLifetime()); if ($data !== false) { // php format is already returned serialized if (Horde_Service_Vimeo::getFormat() != 'php') { @@ -199,13 +173,13 @@ class Horde_Service_Vimeo_Request { $response = $req->request('GET', $this->_api_endpoint . $call); $data = $response->getBody(); - if (!empty($this->_cache['object'])) { + if (!empty($this->_cache)) { if (Horde_Service_Vimeo::getFormat() != 'php') { $sdata = serialize($data); } else { $sdata = $data; } - $this->_cache['object']->set($cache_key, $sdata); + $this->_cache->set($cache_key, $sdata); } return $data;