/**
  * Tests the preloaded search on the Native side
  */
 public function testSetPreloadedSearch()
 {
     $search = new SearchPreloaded(array('count' => 3, array('dn' => 'd'), array('dn' => 'e'), array('dn' => 'f')));
     $this->assertEquals('d', $search->next()->getDn());
     $this->assertEquals('e', $search->next()->getDn());
     $this->assertEquals('f', $search->next()->getDn());
     $this->assertNull($search->next());
     $this->assertNull($search->next());
     $this->assertNull($search->next(), 'Does not reset when end of array is reached');
     $search->reset();
     $this->assertEquals('d', $search->next()->getDn());
     $this->assertEquals('e', $search->next()->getDn());
     $search->reset();
     $this->assertEquals('d', $search->next()->getDn());
 }
示例#2
0
 /**
  * Performs multiple ldap_search calls to retrieve multiple pages of entries
  * 
  * @param int     $pageSize   Page size
  * @param string  $baseDn     Base distinguished name to look below
  * @param string  $filter     Filter for the search
  * @param array   $attributes Names of attributes to retrieve (Default: All)
  * 
  * @return SearchInterface
  */
 protected function searchLdapPaged($pageSize, $baseDn, $filter, $attributes = null)
 {
     $cookie = '';
     $allResults = new SearchPreloaded();
     do {
         if (!ldap_control_paged_result($this->connection, $pageSize, true, $cookie)) {
             throw new SearchException("Unable to set paged control pageSize: " . $pageSize);
         }
         $search = ldap_search($this->connection, $baseDn, $filter, is_array($attributes) ? $attributes : array());
         if (!$search) {
             // Something went wrong in search
             throw self::createLdapSearchException(ldap_errno($this->connection), $baseDn, $filter, $pageSize);
         }
         $entries = ldap_get_entries($this->connection, $search);
         if (!$entries) {
             // No entries?
             throw self::createLdapSearchException(ldap_errno($this->connection), $baseDn, $filter, $pageSize);
         }
         // Ok add all entries
         $allResults->addEntries($entries);
         // Ok go to next page
         ldap_control_paged_result_response($this->connection, $search, $cookie);
     } while ($cookie !== null && $cookie != '');
     return $allResults;
 }