Exemplo n.º 1
0
 /**
  * Renames a LDAP entry from one DN to another DN.
  *
  * This method implicitly moves the entry to another location within the tree.
  *
  * @param  string|Dn $from
  * @param  string|Dn $to
  * @param  bool   $recursively
  * @param  bool   $alwaysEmulate
  * @return Ldap Provides a fluid interface
  * @throws Exception\LdapException
  */
 public function rename($from, $to, $recursively = false, $alwaysEmulate = false)
 {
     $emulate = (bool) $alwaysEmulate;
     if (!function_exists('ldap_rename')) {
         $emulate = true;
     } elseif ($recursively) {
         $emulate = true;
     }
     if ($emulate === false) {
         if ($from instanceof Dn) {
             $from = $from->toString();
         }
         if ($to instanceof Dn) {
             $newDnParts = $to->toArray();
         } else {
             $newDnParts = Dn::explodeDn($to);
         }
         $newRdn = Dn::implodeRdn(array_shift($newDnParts));
         $newParent = Dn::implodeDn($newDnParts);
         $resource = $this->getResource();
         ErrorHandler::start(E_WARNING);
         $isOK = ldap_rename($resource, $from, $newRdn, $newParent, true);
         ErrorHandler::stop();
         if ($isOK === false) {
             throw new Exception\LdapException($this, 'renaming ' . $from . ' to ' . $to);
         } elseif (!$this->exists($to)) {
             $emulate = true;
         }
     }
     if ($emulate) {
         $this->copy($from, $to, $recursively);
         $this->delete($from, $recursively);
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Unserialize a serialized value to return the corresponding object
  *
  * @param string $value The value to convert
  * @return mixed
  * @throws Exception\UnexpectedValueException
  */
 public static function fromLdapUnserialize($value)
 {
     ErrorHandler::start(E_NOTICE);
     $v = unserialize($value);
     ErrorHandler::stop();
     if (false === $v && $value != 'b:0;') {
         throw new Exception\UnexpectedValueException('The given value could not be unserialized');
     }
     return $v;
 }
Exemplo n.º 3
0
 /**
  * Return the result item key
  * Implements Iterator
  *
  * @throws \Zend\Ldap\Exception\LdapException
  * @return string|null
  */
 public function key()
 {
     if (!is_resource($this->current)) {
         $this->rewind();
     }
     if (is_resource($this->current)) {
         $resource = $this->ldap->getResource();
         ErrorHandler::start();
         $currentDn = ldap_get_dn($resource, $this->current);
         ErrorHandler::stop();
         if ($currentDn === false) {
             throw new Exception\LdapException($this->ldap, 'getting dn');
         }
         return $currentDn;
     } else {
         return;
     }
 }
Exemplo n.º 4
0
 /**
  * Remove LDAP User
  * @param User $user
  * @return mixed
  */
 public function ldapRemoveUser(User $user)
 {
     // Initialiazing ldap connection
     $ldapInitialisation = $this->ldapInit();
     $issue = null;
     if ($ldapInitialisation) {
         // Creating user
         ErrorHandler::start(E_WARNING);
         $issue = ldap_delete($this->ldapLinkIdentifier, $user->getDn());
         ErrorHandler::stop();
         // Closing ldap connection
         ldap_close($this->ldapLinkIdentifier);
     }
     return $issue;
 }