|
<?php |
|
|
|
namespace Kanboard\Core\Ldap; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Query |
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
protected $client = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected $entries = array(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct(Client $client) |
|
{ |
|
$this->client = $client; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function execute($baseDn, $filter, array $attributes, $limit = 0) |
|
{ |
|
if (DEBUG && $this->client->hasLogger()) { |
|
$this->client->getLogger()->debug('BaseDN='.$baseDn); |
|
$this->client->getLogger()->debug('Filter='.$filter); |
|
$this->client->getLogger()->debug('Attributes='.implode(', ', $attributes)); |
|
} |
|
|
|
$sr = @ldap_search($this->client->getConnection(), $baseDn, $filter, $attributes, null, $limit); |
|
if ($sr === false) { |
|
return $this; |
|
} |
|
|
|
$entries = ldap_get_entries($this->client->getConnection(), $sr); |
|
if ($entries === false || count($entries) === 0 || $entries['count'] == 0) { |
|
return $this; |
|
} |
|
|
|
$this->entries = $entries; |
|
|
|
if (DEBUG && $this->client->hasLogger()) { |
|
$this->client->getLogger()->debug('NbEntries='.$entries['count']); |
|
} |
|
|
|
return $this; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function hasResult() |
|
{ |
|
return ! empty($this->entries); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getEntries() |
|
{ |
|
return new Entries($this->entries); |
|
} |
|
} |
|
|