From: Jan Schneider Date: Fri, 15 Jan 2010 23:32:56 +0000 (+0100) Subject: Fix class name. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=b2231eb2cb89baf44b6bc00e504666bc23aa814c;p=horde.git Fix class name. Use typehints. Don't hardcode string length. --- diff --git a/framework/Perms/lib/Horde/Perms/Datatree.php b/framework/Perms/lib/Horde/Perms/Datatree.php index 51cce6a94..397cd0db1 100644 --- a/framework/Perms/lib/Horde/Perms/Datatree.php +++ b/framework/Perms/lib/Horde/Perms/Datatree.php @@ -146,12 +146,8 @@ class Horde_Perms_Datatree extends Horde_Perms * object. * @throws Horde_Perms_Exception */ - public function addPermission($perm) + public function addPermission(Horde_Perms_Permission_DataTreeObject $perm) { - if (!($perm instanceof Horde_Perms_Permission_DataTreeObject)) { - throw Horde_Perms_Exception('Permissions must be Horde_Perms_Permission_DataTreeObject objects.'); - } - $name = $perm->getName(); if (empty($name)) { throw Horde_Perms_Exception('Permission names must be non-empty.'); @@ -170,12 +166,8 @@ class Horde_Perms_Datatree extends Horde_Perms * @param boolean $force Force to remove * every child. */ - public function removePermission($perm, $force = false) + public function removePermission(Horde_Perms_Permission_DataTreeObject $perm, $force = false) { - if (!($perm instanceof Horde_Perms_Permission_DataTreeObject)) { - throw Horde_Perms_Exception('Permissions must be Horde_Perms_Permission_DataTreeObject objects.'); - } - $keys = $this->_datatree->get(DATATREE_FORMAT_FLAT, $perm->name, true); foreach ($keys as $key) { $this->_cache->expire('perm_' . $this->_cacheVersion . $key); diff --git a/framework/Perms/lib/Horde/Perms/Sql.php b/framework/Perms/lib/Horde/Perms/Sql.php index 24f770ed6..4b96887ed 100644 --- a/framework/Perms/lib/Horde/Perms/Sql.php +++ b/framework/Perms/lib/Horde/Perms/Sql.php @@ -181,12 +181,8 @@ class Horde_Perms_Sql extends Horde_Perms * @return TODO * @throws Horde_Perms_Exception */ - public function addPermission($perm) + public function addPermission(Horde_Perms_Permission_SqlObject $perm) { - if (!($perm instanceof Horde_Perms_Permission_SqlObject)) { - throw new Horde_Perms_Exception('Permissions must be a Horde_Perms_Permission_SqlObject object.'); - } - $name = $perm->getName(); if (empty($name)) { throw new Horde_Perms_Exception('Permission name must be non-empty.'); @@ -199,8 +195,9 @@ class Horde_Perms_Sql extends Horde_Perms $id = $this->_write_db->nextId('horde_perms'); // remove root from the name - if (substr($name, 0, 3) == (Horde_Perms::ROOT . ':')) { - $name = substr($name, 3); + $root = Horde_Perms::ROOT . ':'; + if (substr($name, 0, strlen($root)) == ($root)) { + $name = substr($name, strlen($root)); } // build parents @@ -239,12 +236,8 @@ class Horde_Perms_Sql extends Horde_Perms * @return TODO * @throws Horde_Perms_Exception */ - public function removePermission($perm, $force = false) + public function removePermission(Horde_Perms_Permission_SqlObject $perm, $force = false) { - if (!($perm instanceof Horde_Perms_Permissions_SqlObject)) { - throw new Horde_Perms_Exception('Permissions must be Horde_Perms_Permission_SqlObject objects.'); - } - $name = $perm->getName(); $this->_cache->expire('perm_sql' . $this->_cacheVersion . $name); $this->_cache->expire('perm_sql_exists_' . $this->_cacheVersion . $name);