}
$perm = new Horde_Perms_Permission_DataTreeObject($name, $this->_cacheVersion, $type, $params);
+ $perm->setCacheOb($this->_cache);
$perm->setDataTree($this->_datatree);
return $perm;
$this->_permsCache[$name] = unserialize($perm);
}
+ $this->_permsCache[$name]->setCacheOb($this->_cache);
+ $this->_permsCache[$name]->setDataTree($this->_datatree);
+
return $this->_permsCache[$name];
}
*/
class Horde_Perms_Permission
{
- // TODO
+ /**
+ * TODO
+ */
public $data;
- // TODO
+ /**
+ * TODO
+ */
public $name;
/**
* @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);
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.
*
}
/**
+ * 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.
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);
+ }
}
}
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;
}
/**
*/
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);
}
}
} 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;
}
/**
$this->_permsCache[$name] = unserialize($perm);
}
- $this->_permsCache[$name]->setSQLOb($this->_db);
+ $this->_permsCache[$name]->setObs($this->_cache, $this->_db);
return $this->_permsCache[$name];
}
$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;