/** * 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(LDAP_SCOPE_BASE => 'ldap_read', LDAP_SCOPE_ONELEVEL => 'ldap_list', LDAP_SCOPE_SUB => 'ldap_search'); if (empty($methods[$filter->getScope()])) { throw new 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($this->_hdl, $res); }