From: Gunnar Wrobel
Date: Thu, 12 Feb 2009 16:58:43 +0000 (+0000) Subject: Completed the first set of rearrangements of the interface for the PHP X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=17e92cbb976c8b0115b0f6c08a3d7014bc48b3ed;p=horde.git Completed the first set of rearrangements of the interface for the PHP 5 version of this package. Some fixes will still be necessary to get more efficient LDAP searches later. --- diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server.php b/framework/Kolab_Server/lib/Horde/Kolab/Server.php index 7894d9449..8004ccfbf 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server.php @@ -169,7 +169,7 @@ abstract class Horde_Kolab_Server * Fetch a Kolab object. * * This method will not necessarily retrieve any data from the server and - * might simply generate a new instance for hte desired object. This method + * might simply generate a new instance for the desired object. This method * can also be used in order to fetch non-existing objects that will be * saved later. * @@ -195,6 +195,30 @@ abstract class Horde_Kolab_Server } /** + * Generates a unique ID for the given information. + * + * @param string $type The type of the object to create. + * @param array $info Any additional information about the object to create. + * + * @return string|PEAR_Error The UID. + */ + public function generateUid($type, $info) + { + if (!class_exists($type)) { + $result = Horde_Kolab_Server_Object::loadClass($type); + if (is_a($result, 'PEAR_Error')) { + return $result; + } + } + + $id = call_user_func(array($type, 'generateId'), $info); + if (is_a($id, 'PEAR_Error')) { + return $id; + } + return $this->generateServerUid($type, $id, $info); + } + + /** * Add a Kolab object. * * @param array $info The object to store. @@ -230,106 +254,6 @@ abstract class Horde_Kolab_Server } /** - * Return the root of the UID values on this server. - * - * @return string The base UID on this server (base DN on ldap). - */ - public function getBaseUid() - { - return ''; - } - - /** - * Identify the primary mail attribute for the first object found - * with the given ID or mail. - * - * @param string $id Search for objects with this ID/mail. - * - * @return mixed|PEAR_Error The mail address or false if there was - * no result. - */ - public function mailForIdOrMail($id) - { - /* In the default class we just return the id */ - return $id; - } - - /** - * Returns a list of allowed email addresses for the given user. - * - * @param string $user The user name. - * - * @return array|PEAR_Error An array of allowed mail addresses. - */ - public function addrsForIdOrMail($user) - { - /* In the default class we just return the user name */ - return $user; - } - - /** - * Return the UID for a given primary mail, uid, or alias. - * - * @param string $mail A valid mail address for the user. - * - * @return mixed|PEAR_Error The UID or false if there was no result. - */ - public function uidForMailAddress($mail) - { - /* In the default class we just return the mail address */ - return $mail; - } - - /** - * Identify the UID for the first user found using a specified - * attribute value. - * - * @param string $attr The name of the attribute used for searching. - * @param string $value The desired value of the attribute. - * @param int $restrict A KOLAB_SERVER_RESULT_* result restriction. - * - * @return mixed|PEAR_Error The UID or false if there was no result. - */ - public function uidForAttr($attr, $value, - $restrict = KOLAB_SERVER_RESULT_SINGLE) - { - /* In the default class we just return false */ - return false; - } - - /** - * Identify the GID for the first group found using a specified - * attribute value. - * - * @param string $attr The name of the attribute used for searching. - * @param string $value The desired value of the attribute. - * @param int $restrict A KOLAB_SERVER_RESULT_* result restriction. - * - * @return mixed|PEAR_Error The GID or false if there was no result. - */ - public function gidForAttr($attr, $value, - $restrict = KOLAB_SERVER_RESULT_SINGLE) - { - /* In the default class we just return false */ - return false; - } - - /** - * Is the given UID member of the group with the given mail address? - * - * @param string $uid UID of the user. - * @param string $mail Search the group with this mail address. - * - * @return boolean|PEAR_Error True in case the user is in the - * group, false otherwise. - */ - public function memberOfGroupAddress($uid, $mail) - { - /* No groups in the default class */ - return false; - } - - /** * Identify the UID for the first object found with the given ID. * * @param string $id Search for objects with this ID. @@ -358,17 +282,17 @@ abstract class Horde_Kolab_Server } /** - * Identify the GID for the first group found with the given mail. + * Identify the UID for the first object found with the given alias. * - * @param string $mail Search for groups with this mail address. + * @param string $mail Search for objects with this mail alias. * @param int $restrict A KOLAB_SERVER_RESULT_* result restriction. * - * @return mixed|PEAR_Error The GID or false if there was no result. + * @return mixed|PEAR_Error The UID or false if there was no result. */ - public function gidForMail($mail, - $restrict = KOLAB_SERVER_RESULT_SINGLE) + public function uidForAlias($mail, + $restrict = KOLAB_SERVER_RESULT_SINGLE) { - return $this->gidForAttr('mail', $mail); + return $this->uidForAttr('alias', $mail); } /** @@ -388,20 +312,6 @@ abstract class Horde_Kolab_Server } /** - * Identify the UID for the first object found with the given alias. - * - * @param string $mail Search for objects with this mail alias. - * @param int $restrict A KOLAB_SERVER_RESULT_* result restriction. - * - * @return mixed|PEAR_Error The UID or false if there was no result. - */ - public function uidForAlias($mail, - $restrict = KOLAB_SERVER_RESULT_SINGLE) - { - return $this->uidForAttr('alias', $mail); - } - - /** * Identify the UID for the first object found with the given mail * address or alias. * @@ -427,7 +337,7 @@ abstract class Horde_Kolab_Server * * @return mixed|PEAR_Error The UID or false if there was no result. */ - public function uidForMailOrIdOrAlias($id) + public function uidForIdOrMailOrAlias($id) { $uid = $this->uidForAttr('uid', $id); if (!$uid) { @@ -440,6 +350,66 @@ abstract class Horde_Kolab_Server } /** + * Identify the primary mail attribute for the first object found + * with the given ID or mail. + * + * @param string $id Search for objects with this ID/mail. + * + * @return mixed|PEAR_Error The mail address or false if there was + * no result. + */ + public function mailForIdOrMail($id) + { + $uid = $this->uidForIdOrMail($id); + $data = $this->read($uid, array('mail')); + return $data['mail']; + } + + /** + * Returns a list of allowed email addresses for the given user. + * + * @param string $id Search for objects with this ID/mail. + * + * @return array|PEAR_Error An array of allowed mail addresses. + */ + public function addrsForIdOrMail($id) + { + $uid = $this->uidForIdOrMail($id); + $data = $this->read($uid, array('mail', 'alias')); + return array_merge($data['mail'], $data['alias']); + } + + /** + * Identify the GID for the first group found with the given mail. + * + * @param string $mail Search for groups with this mail address. + * @param int $restrict A KOLAB_SERVER_RESULT_* result restriction. + * + * @return mixed|PEAR_Error The GID or false if there was no result. + */ + public function gidForMail($mail, + $restrict = KOLAB_SERVER_RESULT_SINGLE) + { + return $this->gidForAttr('mail', $mail); + } + + /** + * Is the given UID member of the group with the given mail address? + * + * @param string $uid UID of the user. + * @param string $mail Search the group with this mail address. + * + * @return boolean|PEAR_Error True in case the user is in the + * group, false otherwise. + */ + public function memberOfGroupAddress($uid, $mail) + { + $gid = $this->gidForMail($mail); + $data = $this->read($gid, array('member')); + return in_array($uid, $data['member']); + } + + /** * Generate a hash representation for a list of objects. * * @param string $type The type of the objects to be listed @@ -469,30 +439,6 @@ abstract class Horde_Kolab_Server } /** - * Generates a unique ID for the given information. - * - * @param string $type The type of the object to create. - * @param array $info Any additional information about the object to create. - * - * @return string|PEAR_Error The UID. - */ - public function generateUid($type, $info) - { - if (!class_exists($type)) { - $result = Horde_Kolab_Server_Object::loadClass($type); - if (is_a($result, 'PEAR_Error')) { - return $result; - } - } - - $id = call_user_func(array($type, 'generateId'), $info); - if (is_a($id, 'PEAR_Error')) { - return $id; - } - return $this->generateServerUid($type, $id, $info); - } - - /** * Stub for reading object data. * * @param string $uid The object to retrieve. @@ -532,4 +478,37 @@ abstract class Horde_Kolab_Server */ abstract protected function generateServerUid($type, $id, $info); + /** + * Return the root of the UID values on this server. + * + * @return string The base UID on this server (base DN on ldap). + */ + abstract public function getBaseUid(); + + /** + * Identify the UID for the first user found using a specified + * attribute value. + * + * @param string $attr The name of the attribute used for searching. + * @param string $value The desired value of the attribute. + * @param int $restrict A KOLAB_SERVER_RESULT_* result restriction. + * + * @return mixed|PEAR_Error The UID or false if there was no result. + */ + abstract public function uidForAttr($attr, $value, + $restrict = KOLAB_SERVER_RESULT_SINGLE); + + /** + * Identify the GID for the first group found using a specified + * attribute value. + * + * @param string $attr The name of the attribute used for searching. + * @param string $value The desired value of the attribute. + * @param int $restrict A KOLAB_SERVER_RESULT_* result restriction. + * + * @return mixed|PEAR_Error The GID or false if there was no result. + */ + abstract public function gidForAttr($attr, $value, + $restrict = KOLAB_SERVER_RESULT_SINGLE); + } diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/ldap.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/ldap.php index 06b82756c..fce8f836f 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/ldap.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/ldap.php @@ -756,7 +756,7 @@ class Horde_Kolab_Server_ldap extends Horde_Kolab_Server * * @return mixed|PEAR_Error The UID or false if there was no result. */ - function uidForMailAddress($mail) + function uidForIdOrMailOrAlias($mail) { $filter = '(&(objectClass=kolabInetOrgPerson)(|(uid='. Horde_LDAP::quote($mail) . ')(mail=' . diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/ServerTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/ServerTest.php index 7a05d66de..56eb92d73 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/ServerTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/ServerTest.php @@ -65,8 +65,8 @@ class Horde_Kolab_Server_ServerTest extends PHPUnit_Framework_TestCase $ks = &Horde_Kolab_Server::factory('none'); $dn = $ks->uidForIdOrMail('test'); $this->assertEquals(false, $dn); - $dn = $ks->uidForMailAddress('test'); - $this->assertEquals('test', $dn); + $dn = $ks->uidForIdOrMailOrAlias('test'); + $this->assertFalse($dn); } } @@ -139,4 +139,47 @@ class Horde_Kolab_Server_none extends Horde_Kolab_Server return $id; } + /** + * Return the root of the UID values on this server. + * + * @return string The base UID on this server (base DN on ldap). + */ + public function getBaseUid() + { + return ''; + } + + /** + * Identify the UID for the first user found using a specified + * attribute value. + * + * @param string $attr The name of the attribute used for searching. + * @param string $value The desired value of the attribute. + * @param int $restrict A KOLAB_SERVER_RESULT_* result restriction. + * + * @return mixed|PEAR_Error The UID or false if there was no result. + */ + public function uidForAttr($attr, $value, + $restrict = KOLAB_SERVER_RESULT_SINGLE) + { + /* In the default class we just return false */ + return false; + } + + /** + * Identify the GID for the first group found using a specified + * attribute value. + * + * @param string $attr The name of the attribute used for searching. + * @param string $value The desired value of the attribute. + * @param int $restrict A KOLAB_SERVER_RESULT_* result restriction. + * + * @return mixed|PEAR_Error The GID or false if there was no result. + */ + public function gidForAttr($attr, $value, + $restrict = KOLAB_SERVER_RESULT_SINGLE) + { + /* In the default class we just return false */ + return false; + } } diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/testTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/testTest.php index ca851a829..c548d2368 100644 --- a/framework/Kolab_Server/test/Horde/Kolab/Server/testTest.php +++ b/framework/Kolab_Server/test/Horde/Kolab/Server/testTest.php @@ -215,19 +215,19 @@ class Horde_Kolab_Server_testTest extends Horde_Kolab_Test_Server */ public function testUidForMailOrIdOrAlias() { - $uid = $this->ldap->uidForMailOrIdOrAlias('g.wrobel@example.org'); + $uid = $this->ldap->uidForIdOrMailOrAlias('g.wrobel@example.org'); $this->assertNoError($uid); $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); - $uid = $this->ldap->uidForMailOrIdOrAlias('wrobel@example.org'); + $uid = $this->ldap->uidForIdOrMailOrAlias('wrobel@example.org'); $this->assertNoError($uid); $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); - $uid = $this->ldap->uidForMailOrIdOrAlias('wrobel'); + $uid = $this->ldap->uidForIdOrMailOrAlias('wrobel'); $this->assertNoError($uid); $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); - $uid = $this->ldap->uidForMailOrIdOrAlias('DOES NOT EXIST'); + $uid = $this->ldap->uidForIdOrMailOrAlias('DOES NOT EXIST'); $this->assertNoError($uid); $this->assertSame(false, $uid); } @@ -266,19 +266,19 @@ class Horde_Kolab_Server_testTest extends Horde_Kolab_Test_Server */ public function testUidForMailAddress() { - $uid = $this->ldap->uidForMailAddress('wrobel@example.org'); + $uid = $this->ldap->uidForIdOrMailOrAlias('wrobel@example.org'); $this->assertNoError($uid); $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); - $uid = $this->ldap->uidForMailAddress('test@example.org'); + $uid = $this->ldap->uidForIdOrMailOrAlias('test@example.org'); $this->assertNoError($uid); $this->assertEquals('cn=Test Test,dc=example,dc=org', $uid); - $uid = $this->ldap->uidForMailAddress('gunnar@example.org'); + $uid = $this->ldap->uidForIdOrMailOrAlias('gunnar@example.org'); $this->assertNoError($uid); $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); - $uid = $this->ldap->uidForMailAddress('wrobel'); + $uid = $this->ldap->uidForIdOrMailOrAlias('wrobel'); $this->assertNoError($uid); $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid); } @@ -302,20 +302,20 @@ class Horde_Kolab_Server_testTest extends Horde_Kolab_Test_Server */ public function testMemberOfGroupAddress() { - $uid = $this->ldap->uidForMailAddress('g.wrobel@example.org'); + $uid = $this->ldap->uidForIdOrMailOrAlias('g.wrobel@example.org'); $this->assertNoError($uid); $member = $this->ldap->memberOfGroupAddress($uid, 'group@example.org'); $this->assertNoError($member); $this->assertTrue($member); $member = $this->ldap->memberOfGroupAddress( - $this->ldap->uidForMailAddress('test@example.org'), + $this->ldap->uidForIdOrMailOrAlias('test@example.org'), 'group@example.org'); $this->assertNoError($member); $this->assertTrue($member); $member = $this->ldap->memberOfGroupAddress( - $this->ldap->uidForMailAddress('somebody@example.org'), + $this->ldap->uidForIdOrMailOrAlias('somebody@example.org'), 'group@example.org'); $this->assertNoError($member); $this->assertFalse($member); @@ -354,11 +354,11 @@ class Horde_Kolab_Server_testTest extends Horde_Kolab_Test_Server $this->assertNoError($groups); $this->assertTrue(!empty($groups)); - $groups = $this->ldap->getGroups($this->ldap->uidForMailAddress('g.wrobel@example.org')); + $groups = $this->ldap->getGroups($this->ldap->uidForIdOrMailOrAlias('g.wrobel@example.org')); $this->assertNoError($groups); $this->assertContains('cn=group@example.org,dc=example,dc=org', $groups); - $groups = $this->ldap->getGroups($this->ldap->uidForMailAddress('test@example.org')); + $groups = $this->ldap->getGroups($this->ldap->uidForIdOrMailOrAlias('test@example.org')); $this->assertNoError($groups); $this->assertContains('cn=group@example.org,dc=example,dc=org', $groups);