Example #1
0
File: Node.php Project: narixx/zf2
 /**
  * Sets the new DN for this node
  *
  * This is an offline method.
  *
  * @param  \Zend\Ldap\Dn|string|array $newDn
  * @throws \Zend\Ldap\Exception
  * @return \Zend\Ldap\Node Provides a fluid interface
  */
 public function setDn($newDn)
 {
     if ($newDn instanceof Dn) {
         $this->_newDn = clone $newDn;
     } else {
         $this->_newDn = Dn::factory($newDn);
     }
     $this->_ensureRdnAttributeValues();
     return $this;
 }
Example #2
0
 /**
  * Update LDAP registry
  *
  * @param  string|\Zend\Ldap\Dn $dn
  * @param  array               $entry
  * @return \Zend\Ldap\Ldap                  Provides a fluid interface
  * @throws \Zend\Ldap\Exception
  */
 public function update($dn, array $entry)
 {
     if (!$dn instanceof Dn) {
         $dn = Dn::factory($dn, null);
     }
     self::prepareLdapEntryArray($entry);
     $rdnParts = $dn->getRdn(Dn::ATTR_CASEFOLD_LOWER);
     foreach ($rdnParts as $key => $value) {
         $value = Dn::unescapeValue($value);
         if (array_key_exists($key, $entry) && !in_array($value, $entry[$key])) {
             $entry[$key] = array_merge(array($value), $entry[$key]);
         }
     }
     $adAttributes = array('distinguishedname', 'instancetype', 'name', 'objectcategory', 'objectguid', 'usnchanged', 'usncreated', 'whenchanged', 'whencreated');
     foreach ($adAttributes as $attr) {
         if (array_key_exists($attr, $entry)) {
             unset($entry[$attr]);
         }
     }
     if (count($entry) > 0) {
         $isModified = @ldap_modify($this->getResource(), $dn->toString(), $entry);
         if ($isModified === false) {
             throw new Exception($this, 'updating: ' . $dn->toString());
         }
     }
     return $this;
 }