예제 #1
0
 /**
  * Check if there is a current result item
  * after calls to rewind() or next()
  * Implements Iterator
  *
  * @return bool
  */
 public function valid()
 {
     if (isset($this->cache[$this->current])) {
         return true;
     }
     return $this->iterator->valid();
 }
예제 #2
0
 /**
  * Check if there is a current result item
  * after calls to rewind() or next()
  * Implements Iterator
  *
  * @return boolean
  */
 public function valid()
 {
     if (isset($this->_cache[$this->_current])) {
         return true;
     } else {
         return $this->_iterator->valid();
     }
 }
예제 #3
0
 /**
  * A global LDAP search routine for finding information.
  *
  * Options can be either passed as single parameters according to the
  * method signature or as an array with one or more of the following keys
  * - filter
  * - baseDn
  * - scope
  * - attributes
  * - sort
  * - collectionClass
  * - sizelimit
  * - timelimit
  *
  * @param  string|Filter\AbstractFilter|array $filter
  * @param  string|Dn|null                     $basedn
  * @param  int                            $scope
  * @param  array                              $attributes
  * @param  string|null                        $sort
  * @param  string|null                        $collectionClass
  * @param  int                            $sizelimit
  * @param  int                            $timelimit
  * @return Collection
  * @throws Exception\LdapException
  */
 public function search($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB, array $attributes = [], $sort = null, $collectionClass = null, $sizelimit = 0, $timelimit = 0)
 {
     if (is_array($filter)) {
         $options = array_change_key_case($filter, CASE_LOWER);
         foreach ($options as $key => $value) {
             switch ($key) {
                 case 'filter':
                 case 'basedn':
                 case 'scope':
                 case 'sort':
                     ${$key} = $value;
                     break;
                 case 'attributes':
                     if (is_array($value)) {
                         $attributes = $value;
                     }
                     break;
                 case 'collectionclass':
                     $collectionClass = $value;
                     break;
                 case 'sizelimit':
                 case 'timelimit':
                     ${$key} = (int) $value;
                     break;
             }
         }
     }
     if ($basedn === null) {
         $basedn = $this->getBaseDn();
     } elseif ($basedn instanceof Dn) {
         $basedn = $basedn->toString();
     }
     if ($filter instanceof Filter\AbstractFilter) {
         $filter = $filter->toString();
     }
     $resource = $this->getResource();
     ErrorHandler::start(E_WARNING);
     switch ($scope) {
         case self::SEARCH_SCOPE_ONE:
             $search = ldap_list($resource, $basedn, $filter, $attributes, 0, $sizelimit, $timelimit);
             break;
         case self::SEARCH_SCOPE_BASE:
             $search = ldap_read($resource, $basedn, $filter, $attributes, 0, $sizelimit, $timelimit);
             break;
         case self::SEARCH_SCOPE_SUB:
         default:
             $search = ldap_search($resource, $basedn, $filter, $attributes, 0, $sizelimit, $timelimit);
             break;
     }
     ErrorHandler::stop();
     if ($search === false) {
         throw new Exception\LdapException($this, 'searching: ' . $filter);
     }
     $iterator = new Collection\DefaultIterator($this, $search);
     if ($sort !== null && is_string($sort)) {
         $iterator->sort($sort);
     }
     return $this->createCollection($iterator, $collectionClass);
 }