/** * Read an entry * * @param peer.ldap.LDAPEntry entry specifying the dn * @return peer.ldap.LDAPEntry entry * @throws lang.IllegalArgumentException * @throws peer.ldap.LDAPException */ public function read(LDAPEntry $entry) { $res = ldap_read($this->_hdl, $entry->getDN(), 'objectClass=*', array(), FALSE, 0); if (0 != ldap_errno($this->_hdl)) { throw new LDAPException('Read "' . $entry->getDN() . '" failed', ldap_errno($this->_hdl)); } return LDAPEntry::fromResource($this->_hdl, ldap_first_entry($this->_hdl, $res)); }
/** * Gets next entry - ideal for loops such as: * <code> * while ($entry= $l->getNextEntry()) { * // doit * } * </code> * * @return peer.ldap.LDAPEntry or FALSE if none exists by this offset * @throws peer.ldap.LDAPException in case of a read error */ public function getNextEntry() { // Check if we were called without getFirstEntry() being called first // Tolerate this situation by simply returning whatever getFirstEntry() // returns. if (NULL === $this->entry) { return $this->getFirstEntry(); } // If we have reached the number of results reported by ldap_count_entries() // - see constructor, return FALSE without trying to read further. Trying // to read "past the end" results in LDAP error #84 (decoding error) in some // client/server constellations, which is then incorrectly reported as an error. if ($this->entry[1] >= $this->size) { return FALSE; } // Fetch the next entry. Return FALSE if it was the last one (where really, // we shouldn't be getting here) $this->entry[0] = ldap_next_entry($this->_hdl, $this->entry[0]); if (FALSE === $this->entry[0]) { if (!($e = ldap_errno($this->_hdl))) { return FALSE; } throw new LDAPException('Could not fetch next result entry.', $e); } // Keep track how many etnries we have fetched so we stop once we // have reached this number - see above for explanation. $this->entry[1]++; return LDAPEntry::fromResource($this->_hdl, $this->entry[0]); }