/** * 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)); }
public function testNullTokens() { $q = new LDAPQuery(); $this->assertEquals($q->prepare('%d', null), 'NULL'); $this->assertEquals($q->prepare('%c', null), 'NULL'); }
public function searchWithSizeLimitOne() { with($query = new LDAPQuery('ou=People,dc=OpenLDAP,dc=Org', '(objectClass=*)')); $query->setSizelimit(1); $query->setScope(LDAP_SCOPE_SUB); $res = $this->lc->searchBy($query); $this->assertClass($res, 'peer.ldap.LDAPSearchResult'); $this->assertEquals(1, $res->numEntries()); $this->assertClass($res->getFirstEntry(), 'peer.ldap.LDAPEntry'); $this->assertFalse($res->getNextEntry()); }
/** * 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)); }