protected function executeOperation(LdapOperationInterface $operation, LogOperation $log = null)
{
$lastServer = $this->connection->getServer();
try {
$this->connectIfNotBound($operation);
$lastServer = $this->connection->getServer();
$handler = $this->getOperationHandler($operation);
$handler->setOperationDefaults($operation);
$this->logStart($log);
$this->switchServerIfNeeded($this->connection->getServer(), $operation->getServer(), $operation);
$this->idleReconnectIfNeeded($operation);
$this->setLdapControls($operation);
return $handler->execute($operation);
} catch (\Throwable $e) {
$this->logExceptionAndThrow($e, $log);
} catch (\Exception $e) {
$this->logExceptionAndThrow($e, $log);
} finally {
$this->logEnd($log);
$this->resetLdapControls($operation);
$this->switchServerIfNeeded($this->connection->getServer(), $lastServer, $operation);
$this->dispatcher->dispatch(new LdapOperationEvent(Event::LDAP_OPERATION_EXECUTE_AFTER, $operation, $this->connection));
}
}