quoteDN() public static method

Takes an array of DN elements and properly quotes it according to RFC 1485.
public static quoteDN ( array $parts ) : string
$parts array An array of tuples containing the attribute name and that attribute's value which make up the DN. Example: $parts = array( array('cn', 'John Smith'), array('dc', 'example'), array('dc', 'com') ); Nested arrays are supported since 2.1.0, to form multi-valued RDNs. Example: $parts = array( array( array('cn', 'John'), array('sn', 'Smith'), array('o', 'Acme Inc.'), ), array('dc', 'example'), array('dc', 'com') ); which will result in cn=John+sn=Smith+o=Acme Inc.,dc=example,dc=com
return string The properly quoted string DN.
Exemplo n.º 1
0
 /**
  * Build a RDN based on a set of attributes and what attributes
  * make a RDN for the current source.
  *
  * @param array $attributes The attributes (in driver keys) of the
  *                          object being added.
  *
  * @return string  The RDN for the new object.
  */
 protected function _makeRDN(array $attributes)
 {
     if (!is_array($this->_params['dn'])) {
         return '';
     }
     $pairs = array();
     foreach ($this->_params['dn'] as $param) {
         if (isset($attributes[$param])) {
             $pairs[] = array($param, $attributes[$param]);
         }
     }
     return Horde_Ldap::quoteDN($pairs);
 }
Exemplo n.º 2
0
 public function testQuoteDN()
 {
     $this->assertEquals('cn=John Smith,dc=example,dc=com', Horde_Ldap::quoteDN(array(array('cn', 'John Smith'), array('dc', 'example'), array('dc', 'com'))));
     $this->assertEquals('cn=John+sn=Smith+o=Acme Inc.,dc=example,dc=com', Horde_Ldap::quoteDN(array(array(array('cn', 'John'), array('sn', 'Smith'), array('o', 'Acme Inc.')), array('dc', 'example'), array('dc', 'com'))));
     $this->assertEquals('cn=John+sn=Smith+o=Acme Inc.', Horde_Ldap::quoteDN(array(array(array('cn', 'John'), array('sn', 'Smith'), array('o', 'Acme Inc.')))));
 }
Exemplo n.º 3
0
 /**
  * Creates a new group.
  *
  * @param string $name       A group name.
  * @param array $attributes  The group's attributes.
  *
  * @return mixed  The ID of the created group.
  * @throws Horde_Group_Exception
  */
 protected function _create($name, array $attributes)
 {
     $dn = Horde_Ldap::quoteDN(array(array($this->_params['gid'], $name))) . ',' . $this->_params['basedn'];
     try {
         $entry = Horde_Ldap_Entry::createFresh($dn, $attributes);
         $this->_rebind(true);
         $this->_ldap->add($entry);
         $this->_rebind(false);
         return $dn;
     } catch (Horde_Ldap_Exception $e) {
         throw new Horde_Group_Exception($e);
     }
 }
Exemplo n.º 4
0
 /**
  * Build a RDN based on a set of attributes and what attributes
  * make a RDN for the current source.
  *
  * @param array $attributes The attributes (in driver keys) of the
  *                          object being added.
  *
  * @return string  The RDN for the new object.
  */
 protected function _makeRDN(array $attributes)
 {
     if (!is_array($this->_params['dn'])) {
         return '';
     }
     return Horde_Ldap::quoteDN(self::_makeRDNhelper($attributes, $this->_params['dn']));
 }
Exemplo n.º 5
0
Arquivo: Ldap.php Projeto: horde/horde
 /**
  * Creates a new group.
  *
  * @param string $name   A group name.
  * @param string $email  The group's email address.
  *
  * @return mixed  The ID of the created group.
  * @throws Horde_Group_Exception
  */
 protected function _create($name, $email = null)
 {
     if ($this->readOnly()) {
         throw new Horde_Group_Exception('This group backend is read-only.');
     }
     $attributes = array($this->_params['gid'] => $name, 'objectclass' => $this->_params['newgroup_objectclass'], 'gidnumber' => $this->_nextGid());
     if (!empty($email)) {
         $attributes['mail'] = $email;
     }
     $dn = Horde_Ldap::quoteDN(array(array($this->_params['gid'], $name))) . ',' . $this->_params['basedn'];
     try {
         $entry = Horde_Ldap_Entry::createFresh($dn, $attributes);
         $this->_rebind(true);
         $this->_ldap->add($entry);
         $this->_rebind(false);
     } catch (Horde_Ldap_Exception $e) {
         throw new Horde_Group_Exception($e);
     }
     return $dn;
 }