private function bindFilterParameters($ldapFilter, $bind) { $idx = 0; return preg_replace_callback("/(?<!\\\\)[?]/", function ($matches) use(&$idx, $bind) { if (!isset($bind[$idx])) { return "?"; } $result = Client::escapeFilterParameter($bind[$idx]); ++$idx; return $result; }, $ldapFilter); }
public function test_count_ReturnsCorrectValue() { LdapFunctions::$phpUnitMock->expects($this->any())->method('ldap_search')->will($this->returnValue("resource")); LdapFunctions::$phpUnitMock->expects($this->any())->method('ldap_count_entries')->will($this->returnValue(8)); $ldapClient = new LdapClient(); $result = $ldapClient->count("base dn", "filter"); $this->assertEquals(8, $result); }
/** * Public only for use in closure. */ public function bindAsAdmin(LdapClient $ldapClient, ServerInfo $server) { $adminUserName = $server->getAdminUsername(); // bind using the admin user which has at least read access to LDAP users if (!$ldapClient->bind($adminUserName, $server->getAdminPassword())) { throw new Exception("Could not bind as LDAP admin."); } }