From 6ac9395fbd8fed837d4f40501e4e6cd089243b96 Mon Sep 17 00:00:00 2001 From: "Jeroen van Meeuwen (Kolab Systems)" Date: Fri, 1 Aug 2014 21:11:08 +0200 Subject: Use Net_LDAP3 --- program/lib/Net/LDAP3/Result.php | 139 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 program/lib/Net/LDAP3/Result.php (limited to 'program/lib/Net/LDAP3/Result.php') diff --git a/program/lib/Net/LDAP3/Result.php b/program/lib/Net/LDAP3/Result.php new file mode 100644 index 000000000..728b30442 --- /dev/null +++ b/program/lib/Net/LDAP3/Result.php @@ -0,0 +1,139 @@ + | + | Jeroen van Meeuwen | + +-----------------------------------------------------------------------+ +*/ + +/** + * Model class representing an LDAP search result + * + * @package LDAP + */ +class Net_LDAP3_Result implements Iterator +{ + protected $conn; + protected $base_dn; + protected $filter; + protected $scope; + + 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; + } + + public function get($property, $default = null) + { + if (isset($this->$property)) { + return $this->$property; + } else { + return $default; + } + } + + public function set($property, $value) + { + $this->$property = $value; + } + + /** + * + */ + public function sort($attr) + { + return ldap_sort($this->conn, $this->result, $attr); + } + + /** + * + */ + public function count() + { + if (!isset($this->count)) + $this->count = ldap_count_entries($this->conn, $this->result); + + return $this->count; + } + + /** + * + */ + public function entries($normalize = false) + { + $entries = ldap_get_entries($this->conn, $this->result); + + if ($normalize) { + return Net_LDAP3::normalize_result($entries); + } + + return $entries; + } + + + /*** Implement PHP 5 Iterator interface to make foreach work ***/ + + function current() + { + $attrib = ldap_get_attributes($this->conn, $this->current); + $attrib['dn'] = ldap_get_dn($this->conn, $this->current); + + return $attrib; + } + + function key() + { + return $this->iteratorkey; + } + + function rewind() + { + $this->iteratorkey = 0; + $this->current = ldap_first_entry($this->conn, $this->result); + } + + function next() + { + $this->iteratorkey++; + $this->current = ldap_next_entry($this->conn, $this->current); + } + + function valid() + { + return (bool)$this->current; + } + +} -- cgit v1.2.3