LdapTools\Operation\Handler\QueryOperationHandler::execute PHP Method

execute() public method

public execute ( LdapTools\Operation\LdapOperationInterface $operation )
$operation LdapTools\Operation\LdapOperationInterface
    public function execute(LdapOperationInterface $operation)
    {
        $allEntries = [];
        /** @var QueryOperation $operation */
        $this->paging()->setIsEnabled($this->shouldUsePaging($operation));
        $this->paging()->start($operation->getPageSize(), $operation->getSizeLimit());
        do {
            $this->paging()->next();
            $result = @call_user_func($operation->getLdapFunction(), $this->connection->getConnection(), ...$operation->getArguments());
            $allEntries = $this->processSearchResult($result, $allEntries);
            $this->paging()->update($result);
        } while ($this->paging()->isActive());
        $this->paging()->end();
        @ldap_free_result($result);
        return $allEntries;
    }

Usage Example

 function it_should_execute_an_operation_with_the_correct_handler($dispatcher, $connection, OperationHandler $handler, QueryOperationHandler $queryHandler, DeleteOperation $operation)
 {
     $queryHandler->supports($operation)->willReturn(false);
     $queryHandler->execute($operation)->shouldNotBeCalled();
     $handler->supports($operation)->willReturn(true);
     $handler->setConnection($connection)->shouldBeCalled();
     $handler->setEventDispatcher($dispatcher)->shouldBeCalled();
     $handler->setOperationDefaults($operation)->shouldBeCalled();
     $handler->execute($operation)->shouldBeCalled();
     $operation->getServer()->willReturn('foo');
     $operation->getControls()->willReturn([]);
     $operation->getPreOperations()->willReturn([]);
     $operation->getPostOperations()->willReturn([]);
     // This should not be called unless a control is explicitly set
     $connection->setControl(Argument::any())->shouldNotBeCalled();
     $this->addHandler($handler);
     $this->addHandler($queryHandler);
     $this->execute($operation);
 }