/** * Rewind the Iterator to the first result item * Implements Iterator * * @throws \Zend\Ldap\Exception */ public function rewind() { if (is_resource($this->_resultId)) { $this->_current = @ldap_first_entry($this->_ldap->getResource(), $this->_resultId); if ($this->_current === false && $this->_ldap->getLastErrorCode() > Ldap\Exception::LDAP_SUCCESS) { throw new Ldap\Exception($this->_ldap, 'getting first entry'); } } }
protected function cleanupLDAPServer() { if (!constant('TESTS_ZEND_LDAP_ONLINE_ENABLED')) { return; } $ldap = $this->ldap->getResource(); foreach (array_reverse($this->nodes) as $dn => $entry) { ldap_delete($ldap, $dn); } }
/** * Rewind the Iterator to the first result item * Implements Iterator * * * @throws \Zend\Ldap\Exception\LdapException */ public function rewind() { if (is_resource($this->resultId)) { ErrorHandler::start(); $this->current = ldap_first_entry($this->ldap->getResource(), $this->resultId); ErrorHandler::stop(); if ($this->current === false && $this->ldap->getLastErrorCode() > Exception\LdapException::LDAP_SUCCESS) { throw new Exception\LdapException($this->ldap, 'getting first entry'); } } }
/** * Sort the iterator * * Sorting is done using the set sortFunction which is by default strnatcasecmp. * * The attribute is determined by lowercasing everything. * * The sort-value will be the first value of the attribute. * * @param string $sortAttribute The attribute to sort by. If not given the * value set via setSortAttribute is used. * * @return void */ public function sort($sortAttribute) { foreach ($this->entries as $key => $entry) { $attributes = ldap_get_attributes($this->ldap->getResource(), $entry['resource']); $attributes = array_change_key_case($attributes, CASE_LOWER); if (isset($attributes[$sortAttribute][0])) { $this->entries[$key]['sortValue'] = $attributes[$sortAttribute][0]; } } $sortFunction = $this->sortFunction; $sorted = usort($this->entries, function ($a, $b) use($sortFunction) { return $sortFunction($a['sortValue'], $b['sortValue']); }); if (!$sorted) { throw new Exception\LdapException($this, 'sorting result-set'); } }
public function testExplicitNetworkTimeoutConnect() { $networkTimeout = 1; $host = TESTS_ZEND_LDAP_HOST; $port = 0; if (defined('TESTS_ZEND_LDAP_PORT') && TESTS_ZEND_LDAP_PORT != 389) { $port = TESTS_ZEND_LDAP_PORT; } $useSsl = false; if (defined('TESTS_ZEND_LDAP_USE_SSL')) { $useSsl = TESTS_ZEND_LDAP_USE_SSL; } $ldap = new Ldap\Ldap(); $ldap->connect($host, $port, $useSsl, null, $networkTimeout); ldap_get_option($ldap->getResource(), LDAP_OPT_NETWORK_TIMEOUT, $actual); $this->assertEquals($networkTimeout, $actual); }
/** * @group ZF-8259 */ public function testResourceIsAlwaysReturned() { $ldap = new Ldap\Ldap($this->_options); $this->assertNotNull($ldap->getResource()); $this->assertTrue(is_resource($ldap->getResource())); $this->assertEquals(TESTS_ZEND_LDAP_USERNAME, $ldap->getBoundUser()); }