Пример #1
0
 /**
  * Perform an LDAP search specified by a given filter.
  *
  * @param   peer.ldap.LDAPQuery filter
  * @return  peer.ldap.LDAPSearchResult search result object
  */
 public function searchBy(LDAPQuery $filter)
 {
     static $methods = array(self::SCOPE_BASE => 'ldap_read', self::SCOPE_ONELEVEL => 'ldap_list', self::SCOPE_SUB => 'ldap_search');
     if (empty($methods[$filter->getScope()])) {
         throw new \lang\IllegalArgumentException('Scope ' . $args[0] . ' not supported');
     }
     if (false === ($res = @call_user_func_array($methods[$filter->getScope()], array($this->_hdl, $filter->getBase(), $filter->getFilter(), $filter->getAttrs(), $filter->getAttrsOnly(), $filter->getSizeLimit(), $filter->getTimelimit(), $filter->getDeref())))) {
         throw new LDAPException('Search failed', ldap_errno($this->_hdl));
     }
     // Sort results by given sort attributes
     if ($filter->getSort()) {
         foreach ($filter->getSort() as $sort) {
             ldap_sort($this->_hdl, $res, $sort);
         }
     }
     return new LDAPSearchResult(new LDAPEntries($this->_hdl, $res));
 }
Пример #2
0
 /**
  * Perform an LDAP search specified by a given filter.
  *
  * @param   peer.ldap.LDAPQuery filter
  * @return  peer.ldap.LDAPSearchResult search result object
  */
 public function searchBy(LDAPQuery $filter)
 {
     static $methods = [LDAPQuery::SCOPE_BASE => 'ldap_read', LDAPQuery::SCOPE_ONELEVEL => 'ldap_list', LDAPQuery::SCOPE_SUB => 'ldap_search'];
     if (!isset($methods[$filter->getScope()])) {
         throw new IllegalArgumentException('Scope ' . $filter->getScope() . ' not supported');
     }
     $f = $methods[$filter->getScope()];
     if (false === ($res = $f($this->handle, $filter->getBase(), $filter->getFilter(), $filter->getAttrs(), $filter->getAttrsOnly(), $filter->getSizeLimit(), $filter->getTimelimit(), $filter->getDeref()))) {
         throw $this->error('Search failed');
     }
     // Sort results by given sort attributes
     if ($filter->getSort()) {
         foreach ($filter->getSort() as $sort) {
             ldap_sort($this->handle, $res, $sort);
         }
     }
     return new LDAPSearchResult(new LDAPEntries($this->handle, $res));
 }