getFilter() public method

Get the filter for the LDAP query operation.
public getFilter ( ) : string | OperatorCollection
return string | LdapTools\Query\OperatorCollection
Example #1
0
 /**
  * Goes through each alias for the operation to get results only for that specific type, then combine and return
  * them all.
  *
  * @param string $hydratorType
  * @return array|LdapObjectCollection|mixed
  */
 protected function getResultsForAliases($hydratorType)
 {
     /** @var LdapObjectCollection|array $results */
     $results = [];
     foreach ($this->operation->getFilter()->getAliases() as $alias => $schema) {
         $operation = clone $this->operation;
         /**
          * If we received the partial limit of results, re-adjust the next operations limit so we don't go over.
          * 
          * @todo This is getting difficult due to multiple operations needed to select all schema types. If this was
          *       a single operation the issue would not exist. But with a single query and multiple types I cannot
          *       easily determine which result is what type. Unsure of the best way to fix this at the moment. 
          */
         if ($operation->getSizeLimit() && count($results) < $operation->getSizeLimit()) {
             $operation->setSizeLimit($operation->getSizeLimit() - count($results));
         }
         $objects = $this->getResultsFromLdap($operation, $hydratorType, $schema, $alias);
         if ($objects instanceof LdapObjectCollection && $results) {
             $results->add(...$objects->toArray());
         } elseif ($objects instanceof LdapObjectCollection) {
             $results = $objects;
         } else {
             $results = array_merge($results, $objects);
         }
         // If the results have reached the expected size limit then end the loop.
         if ($this->operation->getSizeLimit() && count($results) == $operation->getSizeLimit()) {
             break;
         }
     }
     return $results;
 }
Example #2
0
 function it_should_resolve_base_dn_parameters_when_querying_ldap($connection)
 {
     $schema = new LdapObjectSchema('ad', 'user');
     $schema->setBaseDn('%_configurationnamingcontext_%');
     $schema->setFilter(new Comparison('foo', '=', 'bar'));
     $this->operation->getFilter()->addLdapObjectSchema($schema);
     $this->operation->setBaseDn('%_configurationnamingcontext_%');
     $connection->execute(Argument::that(function ($op) {
         return $op->getBaseDn() == 'cn=Configuration,dc=example,dc=local';
     }))->willReturn($this->ldapEntries);
     $this->execute();
 }
 /**
  * @param QueryOperation $operation
  */
 protected function hydrateQueryOperation(QueryOperation $operation)
 {
     $operation->setAttributes($this->getAttributesToLdap($operation->getAttributes(), true, $this->schema, $this->alias));
     // Only want it set if it wasn't explicitly set...
     if ($this->schema && is_null($operation->getBaseDn())) {
         $operation->setBaseDn($this->schema->getBaseDn());
     }
     // Empty check instead of null due to the way the BaseDN is set for a RootDSE query...
     if (!empty($operation->getBaseDn()) && ParameterResolver::hasParameters($operation->getBaseDn())) {
         $this->setDefaultParameters();
         $operation->setBaseDn($this->resolveParameters(['baseDn' => $operation->getBaseDn()])['baseDn']);
     }
     // If null then we default to the domain config or the explicitly set value...
     if ($this->schema && !is_null($this->schema->getUsePaging())) {
         $operation->setUsePaging($this->schema->getUsePaging());
     }
     if ($this->schema && !is_null($this->schema->getScope())) {
         $operation->setScope($this->schema->getScope());
     }
     if ($this->schema) {
         $operation->addControl(...$this->schema->getControls());
     }
     if ($operation->getFilter() instanceof OperatorCollection) {
         $this->convertValuesToLdap($operation->getFilter());
         $operation->setFilter($operation->getFilter()->toLdapFilter($this->alias));
     }
 }
 function it_should_not_attempt_to_resolve_parameters_for_a_base_dn_for_the_RootDSE(QueryOperation $operation, $connection)
 {
     $operation->getBaseDn()->willReturn('');
     $operation->getAttributes()->willReturn(['foo']);
     $operation->setAttributes(['foo'])->shouldBeCalled();
     $operation->getFilter()->willReturn('(objectClass=*)');
     $connection->getRootDse()->shouldNotBeCalled();
     $operation->setBaseDn(Argument::any())->shouldNotBeCalled();
     $this->hydrateToLdap($operation);
 }