protected function _lookup() { // Do we already have the result? if ($this->result instanceof Result) { return $this->result; } // Get the data from the directory server $task = new Task(static::$operation, $this->link); $task->filter($this->query); static::$attributes && $task->attributes(static::$attributes); static::$base && $task->base(static::$base); $result = static::$paged_search ? $task->run_paged(static::$sizelimit) : $task->run(); // Process the result and return the data! return $this->_process_result($result); }
/** * Read a single object from the server * * Use this method to read the specified attributes of a single entity in * the directory server if you know the distinguishe name of the object, * or if you can provide a search filter that returns exactly zero or one object. * * <h2>Example:</h2> * <code> * use ADX\Core\Object; // Import the class into the current namespace * * // Read the object with specified distinguished name * $user = Object::read( "CN=Karen Berge,OU=admins,DC=corp,DC=company,DC=com", * ['name', 'mail'], * $link ); // $link is a fully configured {@link Link} object * * // Read an object specified by the search filter * try * { * $user = Object::read( "(&(samaccountname=jsmith))", ['name', 'mail'], $link ); * } * catch ( ADX\Core\Exception $e ) * { * // More than one object found - refine your search query! * echo $e->getMessage(); * exit; * } * * // Use the object somehow... * echo $user->mail->value(0); * </code> * * @throws Exception If the lookup operation returns more than one object from the server * @param string The distinguished name of the entity to be loaded or an ldap filter that reaturns exactly one object * @param array Array of attributes to be loaded from the server * @param Link The configured and bound Link to server * * @return self Object containing the requested attributes */ public static function read($dnOrFilter, $attributes, Link $adxLink) { // Check if we have DN or a search filter if (!is_string($dnOrFilter)) { throw new IncorrectParameterException('Invalid search filter supplied - you must provide a valid ldap filter'); } if ($dnOrFilter === '' || preg_match('/^[^(].*DC={1}.*[^)]$/i', $dnOrFilter) === 1) { $task = new Task(Enums\Operation::OpRead, $adxLink); $task->attributes($attributes)->base($dnOrFilter); return $task->run()->first(); } else { $task = new Task(Enums\Operation::OpSearch, $adxLink); $task->attributes($attributes)->filter($dnOrFilter); $result = $task->run(); if (count($result) > 1) { throw new Exception("Ambiguous results returned - please refine your search filter ( {$dnOrFilter} )"); } return $result->first(); } }