1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
<?php
/*
+-----------------------------------------------------------------------+
| Net/LDAP3/Result.php |
| |
| Based on code created by the Roundcube Webmail team. |
| |
| Copyright (C) 2006-2014, The Roundcube Dev Team |
| Copyright (C) 2012-2014, Kolab Systems AG |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by |
| the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of the GNU General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/>. |
| |
| PURPOSE: |
| Provide advanced functionality for accessing LDAP directories |
| |
+-----------------------------------------------------------------------+
| Authors: Thomas Bruederli <roundcube@gmail.com> |
| Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> |
+-----------------------------------------------------------------------+
*/
/**
* Model class representing an LDAP search result
*
* @package LDAP
*/
class Net_LDAP3_Result implements Iterator
{
protected $conn;
protected $base_dn;
protected $filter;
protected $scope;
protected $result;
private $count;
private $current;
private $iteratorkey = 0;
/**
* Default constructor
*
* @param resource $conn LDAP link identifier
* @param string $base_dn Base DN used to get this result
* @param string $filter Filter query used to get this result
* @param string $scope Scope of the result
* @param resource $result LDAP result entry identifier
*/
function __construct($conn, $base_dn, $filter, $scope, $result)
{
$this->conn = $conn;
$this->base_dn = $base_dn;
$this->filter = $filter;
$this->scope = $scope;
$this->result = $result;
}
/**
* Property value getter
*
* @param string $property Property name
* @param mixed $default Return value if proprty is not set
*
* @return mixed Property value
*/
public function get($property, $default = null)
{
return isset($this->$property) ? $this->$property : $default;
}
/**
* Property value setter
*
* @param string $property Property name
* @param mixed $value Property value
*/
public function set($property, $value)
{
$this->$property = $value;
}
/**
* Wrapper for ldap_sort()
*
* @param string $attr The attribute to use as a key in the sort
*
* @return bool True on success, False on failure
*/
public function sort($attr)
{
// @TODO: Don't use ldap_sort() it's deprecated since PHP7
// and will be removed in future
return @ldap_sort($this->conn, $this->result, $attr);
}
/**
* Get entries count
*
* @return int Number of entries in the result
*/
public function count()
{
if (!isset($this->count)) {
$this->count = ldap_count_entries($this->conn, $this->result);
}
return $this->count;
}
/**
* Wrapper for ldap_get_entries()
*
* @param bool $normalize Optionally normalize the entries to a list of hash arrays
*
* @return array List of LDAP entries
*/
public function entries($normalize = false)
{
$entries = ldap_get_entries($this->conn, $this->result);
if ($normalize) {
return Net_LDAP3::normalize_result($entries);
}
return $entries;
}
/**
* Wrapper for ldap_get_dn() using the current entry pointer
*/
public function get_dn()
{
return $this->current ? ldap_get_dn($this->conn, $this->current) : null;
}
/*** Implement PHP 5 Iterator interface to make foreach work ***/
#[ReturnTypeWillChange]
function current()
{
$attrib = ldap_get_attributes($this->conn, $this->current);
$attrib['dn'] = ldap_get_dn($this->conn, $this->current);
return $attrib;
}
#[ReturnTypeWillChange]
function key()
{
return $this->iteratorkey;
}
#[ReturnTypeWillChange]
function rewind()
{
$this->iteratorkey = 0;
$this->current = ldap_first_entry($this->conn, $this->result);
}
#[ReturnTypeWillChange]
function next()
{
$this->iteratorkey++;
$this->current = ldap_next_entry($this->conn, $this->current);
}
#[ReturnTypeWillChange]
function valid()
{
return (bool) $this->current;
}
}
|