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

execute() public method

public execute ( LdapTools\Operation\LdapOperationInterface $operation )
$operation LdapTools\Operation\LdapOperationInterface
    public function execute(LdapOperationInterface $operation)
    {
        $result = @call_user_func($operation->getLdapFunction(), $this->connection->getConnection(), ...$operation->getArguments());
        if ($result === false) {
            throw new LdapConnectionException(sprintf('LDAP %s Operation Error. Diagnostic message: "%s"', $operation->getName(), $this->connection->getDiagnosticMessage()));
        }
        return $result;
    }

Usage Example

 function it_should_not_connect_if_not_yet_bound_on_an_AuthenticationOperation(OperationHandler $handler, $connection, $dispatcher)
 {
     $operation = new AuthenticationOperation('foo', 'bar');
     $handler->supports($operation)->willReturn(true);
     $handler->setConnection($connection)->shouldBeCalled();
     $handler->setEventDispatcher($dispatcher)->shouldBeCalled();
     $handler->setOperationDefaults($operation)->shouldBeCalled();
     $handler->execute($operation)->shouldBeCalled();
     $connection->getServer()->willReturn(null);
     $connection->isBound()->willReturn(false);
     $connection->getIdleTime()->willReturn(1);
     $connection->close()->shouldNotBeCalled();
     $connection->connect()->shouldNotBeCalled();
     $this->addHandler($handler);
     $this->execute($operation);
 }
OperationHandler