From: Michael M Slusarz Date: Sat, 15 May 2010 03:01:56 +0000 (-0600) Subject: Remove reliance on injector in Horde_Perms X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=dc2e7b1d199806b31ff75caec5f59e5dd43dd927;p=horde.git Remove reliance on injector in Horde_Perms --- diff --git a/framework/Perms/lib/Horde/Perms/Datatree.php b/framework/Perms/lib/Horde/Perms/Datatree.php index a939164e5..85e5a90c1 100644 --- a/framework/Perms/lib/Horde/Perms/Datatree.php +++ b/framework/Perms/lib/Horde/Perms/Datatree.php @@ -84,6 +84,7 @@ class Horde_Perms_Datatree extends Horde_Perms } $perm = new Horde_Perms_Permission_DataTreeObject($name, $this->_cacheVersion, $type, $params); + $perm->setCacheOb($this->_cache); $perm->setDataTree($this->_datatree); return $perm; @@ -113,6 +114,9 @@ class Horde_Perms_Datatree extends Horde_Perms $this->_permsCache[$name] = unserialize($perm); } + $this->_permsCache[$name]->setCacheOb($this->_cache); + $this->_permsCache[$name]->setDataTree($this->_datatree); + return $this->_permsCache[$name]; } diff --git a/framework/Perms/lib/Horde/Perms/Permission.php b/framework/Perms/lib/Horde/Perms/Permission.php index f0e8df122..2b2614419 100644 --- a/framework/Perms/lib/Horde/Perms/Permission.php +++ b/framework/Perms/lib/Horde/Perms/Permission.php @@ -14,10 +14,14 @@ */ class Horde_Perms_Permission { - // TODO + /** + * TODO + */ public $data; - // TODO + /** + * TODO + */ public $name; /** @@ -36,7 +40,8 @@ class Horde_Perms_Permission * @param array $params A hash with any parameters that the * permission type needs. */ - public function __construct($name, $cacheVersion = null, $type = 'matrix', $params = null) + public function __construct($name, $cacheVersion = null, $type = 'matrix', + $params = null) { $this->setName($name); $this->setCacheVersion($cacheVersion); diff --git a/framework/Perms/lib/Horde/Perms/Permission/DataTreeObject.php b/framework/Perms/lib/Horde/Perms/Permission/DataTreeObject.php index 6926929ce..af66847b9 100644 --- a/framework/Perms/lib/Horde/Perms/Permission/DataTreeObject.php +++ b/framework/Perms/lib/Horde/Perms/Permission/DataTreeObject.php @@ -17,6 +17,13 @@ class Horde_Perms_Permission_DataTreeObject extends DataTreeObject { /** + * Cache object. + * + * @var Horde_Cache + */ + protected $_cache; + + /** * Constructor. Just makes sure to call the parent constructor so that * the perm's name is set properly. * @@ -36,6 +43,26 @@ class Horde_Perms_Permission_DataTreeObject extends DataTreeObject } /** + * Don't store cache object on serialize(). + * + * @return array List of variables to serialize. + */ + public function __sleep() + { + return array_diff(array_keys(get_class_vars(__CLASS__)), array('_cache')); + } + + /** + * Sets the cache instance in the object. + * + * @param Horde_Cache $cache The cache object. + */ + public function setCacheOb(Horde_Cache $cache) + { + $this->_cache = $cache; + } + + /** * Gets one of the attributes of the object, or null if it isn't defined. * * @param string $attribute The attribute to get. @@ -554,9 +581,10 @@ class Horde_Perms_Permission_DataTreeObject extends DataTreeObject parent::save(); - $cache = $GLOBALS['injector']->getInstance('Horde_Cache'); - $cache->expire('perm_' . $this->_cacheVersion . $name); - $cache->expire('perm_exists_' . $this->_cacheVersion . $name); + if ($this->_cache) { + $this->_cache->expire('perm_' . $this->_cacheVersion . $name); + $this->_cache->expire('perm_exists_' . $this->_cacheVersion . $name); + } } } diff --git a/framework/Perms/lib/Horde/Perms/Permission/SqlObject.php b/framework/Perms/lib/Horde/Perms/Permission/SqlObject.php index 76224d5ed..9ffefacca 100644 --- a/framework/Perms/lib/Horde/Perms/Permission/SqlObject.php +++ b/framework/Perms/lib/Horde/Perms/Permission/SqlObject.php @@ -22,20 +22,39 @@ class Horde_Perms_Permission_SqlObject extends Horde_Perms_Permission protected $_id; /** + * Cache object. + * + * @var Horde_Cache + */ + protected $_cache; + + /** * Database handle for saving changes. * - * @var DB + * @var Horde_Db_Adapter_Base */ - protected $_write_db; + protected $_db; /** - * Associates a DB object with this share. + * Tasks to run on serialize(). * - * @param DB $write_db The DB object. + * @return array Parameters that are stored. */ - public function setSqlOb($write_db) + public function __sleep() { - $this->_write_db = $write_db; + return array_diff(array_keys(get_class_vars(__CLASS__)), array('_cache', '_db')); + } + + /** + * Sets the helper functions within the object. + * + * @param Horde_Cache $cache The cache object. + * @param Horde_Db_Adapter_Base $db The database object. + */ + public function setObs(Horde_Cache $cache, Horde_Db_Adapter_Base $db) + { + $this->_cache = $cache; + $this->_db = $db; } /** @@ -66,22 +85,26 @@ class Horde_Perms_Permission_SqlObject extends Horde_Perms_Permission */ public function save() { + if (!isset($this->_db)) { + throw new Horde_Perms_Exception('Cannot save because the DB instances has not been set in this object.'); + } + $name = $this->getName(); if (empty($name)) { throw new Horde_Perms_Exception('Permission names must be non-empty'); } + $query = 'UPDATE horde_perms SET perm_data = ? WHERE perm_id = ?'; $params = array(serialize($this->data), $this->getId()); try { - $this->_write_db->update($query, $params); + $this->_db->update($query, $params); } catch (Horde_Db_Exception $e) { throw new Horde_Perms_Exception($e); } - $cache = $GLOBALS['injector']->getInstance('Horde_Cache'); - $cache->expire('perm_sql_' . $this->_cacheVersion . $name); - $cache->expire('perm_sql_exists_' . $this->_cacheVersion . $name); + $this->_cache->expire('perm_sql_' . $this->_cacheVersion . $name); + $this->_cache->expire('perm_sql_exists_' . $this->_cacheVersion . $name); } } diff --git a/framework/Perms/lib/Horde/Perms/Sql.php b/framework/Perms/lib/Horde/Perms/Sql.php index 2da835f9b..153f2c0bc 100644 --- a/framework/Perms/lib/Horde/Perms/Sql.php +++ b/framework/Perms/lib/Horde/Perms/Sql.php @@ -95,7 +95,10 @@ class Horde_Perms_Sql extends Horde_Perms } catch (Horde_Perms_Exception $e) {} } - return new Horde_Perms_Permission_SqlObject($name, $this->_cacheVersion, $type, $params); + $ob = new Horde_Perms_Permission_SqlObject($name, $this->_cacheVersion, $type, $params); + $ob->setObs($this->_cache, $this->_db); + + return $ob; } /** @@ -139,7 +142,7 @@ class Horde_Perms_Sql extends Horde_Perms $this->_permsCache[$name] = unserialize($perm); } - $this->_permsCache[$name]->setSQLOb($this->_db); + $this->_permsCache[$name]->setObs($this->_cache, $this->_db); return $this->_permsCache[$name]; } @@ -174,7 +177,7 @@ class Horde_Perms_Sql extends Horde_Perms $object = new Horde_Perms_Permission_SqlObject($result['perm_name'], $this->_cacheVersion); $object->setId($id); $object->setData(unserialize($result['perm_data'])); - $object->setSQLOb($this->_db); + $object->setObs($this->_cache, $this->_db); } return $object;