Navigation Menu

Skip to content

Commit

Permalink
[Zend\Ldap] Remove code marked as @deprecated
Browse files Browse the repository at this point in the history
* Remove the following deprecated methods:
  Ldap::filterEscape()
  Ldap::explodeDn()
  Exception/LdapException::getLDAPCode()
  Exception/LdapException::getErrorCode()
* Adapt Test cases
* Fix some CS issues
  • Loading branch information
Maks3w committed Apr 7, 2012
1 parent d84dccb commit 073395a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 50 deletions.
23 changes: 0 additions & 23 deletions Exception/LdapException.php
Expand Up @@ -144,27 +144,4 @@ public function __construct(Ldap $ldap = null, $str = null, $code = 0)

parent::__construct($message, $code);
}


/**
* @deprecated not necessary any more - will be removed
* @param Ldap $ldap A Zend\Ldap\Ldap object
* @return int The current error code for the resource
*/
public static function getLDAPCode(LDAP $ldap = null)
{
if ($ldap !== null) {
return $ldap->getLastErrorCode();
}
return 0;
}

/**
* @deprecated will be removed
* @return int The current error code for this exception
*/
public function getErrorCode()
{
return $this->getCode();
}
}
56 changes: 29 additions & 27 deletions Ldap.php
Expand Up @@ -73,40 +73,17 @@ class Ldap
/**
* Caches the RootDse
*
* @var Node
* @var Node\RootDse
*/
protected $rootDse = null;

/**
* Caches the schema
*
* @var Node
* @var Node\Schema
*/
protected $schema = null;

/**
* @deprecated will be removed, use {@see Filter\AbstractFilter::escapeValue()}
* @param string $str The string to escape.
* @return string The escaped string
*/
public static function filterEscape($str)
{
return Filter\AbstractFilter::escapeValue($str);
}

/**
* @deprecated will be removed, use {@see Dn::checkDn()}
* @param string $dn The DN to parse
* @param array $keys An optional array to receive DN keys (e.g. CN, OU, DC, ...)
* @param array $vals An optional array to receive DN values
* @return boolean True if the DN was successfully parsed or false if the string is
* not a valid DN.
*/
public static function explodeDn($dn, array &$keys = null, array &$vals = null)
{
return Dn::checkDn($dn, $keys, $vals);
}

/**
* Constructor.
*
Expand Down Expand Up @@ -141,6 +118,7 @@ public function getResource()
if (!is_resource($this->resource) || $this->boundUser === false) {
$this->bind();
}

return $this->resource;
}

Expand All @@ -161,6 +139,7 @@ public function getLastErrorCode()
}
return $err;
}

return 0;
}

Expand Down Expand Up @@ -204,6 +183,7 @@ public function getLastError(&$errorCode = null, array &$errorMessages = null)
} else {
$message .= '(no error message from LDAP)';
}

return $message;
}

Expand Down Expand Up @@ -243,7 +223,7 @@ public function getBoundUser()
* networkTimeout
*
* @param array|Traversable $options Options used in connecting, binding, etc.
* @return Ldap\Ldap Provides a fluent interface
* @return Ldap Provides a fluent interface
* @throws Exception\LdapException
*/
public function setOptions($options)
Expand Down Expand Up @@ -305,6 +285,7 @@ public function setOptions($options)
throw new Exception\LdapException(null, "Unknown Zend\\Ldap\\Ldap option: $key");
}
$this->options = $permittedOptions;

return $this;
}

Expand Down Expand Up @@ -488,6 +469,7 @@ protected function getAccountFilter($acctname)
// is there a better way to detect this?
return sprintf("(&(objectClass=user)(sAMAccountName=%s))", $aname);
}

return sprintf("(&(objectClass=posixAccount)(uid=%s))", $aname);
}

Expand Down Expand Up @@ -531,6 +513,7 @@ protected function getAccountDn($acctname)
}
$acctname = $this->getCanonicalAccountName($acctname, self::ACCTNAME_FORM_USERNAME);
$acct = $this->getAccount($acctname, array('dn'));

return $acct['dn'];
}

Expand All @@ -554,6 +537,7 @@ protected function isPossibleAuthority($dname)
if (strcasecmp($dname, $accountDomainNameShort) == 0) {
return true;
}

return false;
}

Expand Down Expand Up @@ -649,6 +633,7 @@ protected function getAccount($acctname, array $attrs = null)
}
}
$accounts->close();

throw new Exception\LdapException($this, $str, $code);
}

Expand Down Expand Up @@ -761,6 +746,7 @@ public function connect($host = null, $port = null, $useSsl = null, $useStartTls
$this->disconnect();
throw $zle;
}

throw new Exception\LdapException(null, "Failed to connect to LDAP server: $host:$port");
}

Expand Down Expand Up @@ -845,6 +831,7 @@ public function bind($username = null, $password = null)
$zle = new Exception\LdapException($this, $message);
}
$this->disconnect();

throw $zle;
}

Expand Down Expand Up @@ -930,6 +917,7 @@ public function search(
}

$iterator = new Collection\DefaultIterator($this, $search);

return $this->createCollection($iterator, $collectionClass);
}

Expand All @@ -955,6 +943,7 @@ protected function createCollection(Collection\DefaultIterator $iterator, $colle
throw new Exception\LdapException(null,
"Class '$collectionClass' must subclass 'Zend\\Ldap\\Collection'");
}

return new $collectionClass($iterator);
}
}
Expand All @@ -979,6 +968,7 @@ public function count($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB)
throw $e;
}
}

return $result->count();
}

Expand Down Expand Up @@ -1046,6 +1036,7 @@ public function searchEntries(
if ((bool)$reverseSort === true) {
$items = array_reverse($items, false);
}

return $items;
}

Expand All @@ -1056,7 +1047,7 @@ public function searchEntries(
* @param array $attributes
* @param boolean $throwOnNotFound
* @return array
* @throws Exception\LdapException
* @throws null|Exception\LdapException
*/
public function getEntry($dn, array $attributes = array(), $throwOnNotFound = false)
{
Expand All @@ -1065,6 +1056,7 @@ public function getEntry($dn, array $attributes = array(), $throwOnNotFound = fa
"(objectClass=*)", $dn, self::SEARCH_SCOPE_BASE,
$attributes, null
);

return $result->getFirst();
} catch (Exception\LdapException $e) {
if ($throwOnNotFound !== false) {
Expand Down Expand Up @@ -1163,6 +1155,7 @@ public function add($dn, array $entry)
if ($isAdded === false) {
throw new Exception\LdapException($this, 'adding: ' . $dn->toString());
}

return $this;
}

Expand Down Expand Up @@ -1202,6 +1195,7 @@ public function update($dn, array $entry)
throw new Exception\LdapException($this, 'updating: ' . $dn->toString());
}
}

return $this;
}

Expand Down Expand Up @@ -1255,6 +1249,7 @@ public function delete($dn, $recursively = false)
if ($isDeleted === false) {
throw new Exception\LdapException($this, 'deleting: ' . $dn);
}

return $this;
}

Expand Down Expand Up @@ -1286,6 +1281,7 @@ protected function getChildrenDns($parentDn)
$children[] = $childDn;
}
@ldap_free_result($search);

return $children;
}

Expand Down Expand Up @@ -1315,6 +1311,7 @@ public function moveToSubtree($from, $to, $recursively = false, $alwaysEmulate =

$newDnParts = array_merge(array(array_shift($orgDnParts)), $newParentDnParts);
$newDn = Dn::fromArray($newDnParts);

return $this->rename($from, $newDn, $recursively, $alwaysEmulate);
}

Expand Down Expand Up @@ -1380,6 +1377,7 @@ public function rename($from, $to, $recursively = false, $alwaysEmulate = false)
$this->copy($from, $to, $recursively);
$this->delete($from, $recursively);
}

return $this;
}

Expand Down Expand Up @@ -1408,6 +1406,7 @@ public function copyToSubtree($from, $to, $recursively = false)

$newDnParts = array_merge(array(array_shift($orgDnParts)), $newParentDnParts);
$newDn = Dn::fromArray($newDnParts);

return $this->copy($from, $newDn, $recursively);
}

Expand Down Expand Up @@ -1440,6 +1439,7 @@ public function copy($from, $to, $recursively = false)
$this->copy($c, $newChild, true);
}
}

return $this;
}

Expand Down Expand Up @@ -1477,6 +1477,7 @@ public function getRootDse()
if ($this->rootDse === null) {
$this->rootDse = Node\RootDse::create($this);
}

return $this->rootDse;
}

Expand All @@ -1491,6 +1492,7 @@ public function getSchema()
if ($this->schema === null) {
$this->schema = Node\Schema::create($this);
}

return $this->schema;
}
}

0 comments on commit 073395a

Please sign in to comment.