@param callable $operation

@return mixed
@throws \Exception
492258
public function withinTransaction(callable $operation)
    {
        if ($this->isInTransaction()) {
            return $operation();
        }

        $this->beginTransaction();
        try {
            $result = $operation();
            $this->commitTransaction();

            return $result;
        } catch (\Exception $e) {
            $this->rollbackTransaction();
            throw $e;
        }
    }
331861
public function call(callable $callable, ...$params)
    {
        foreach ($this->settings as $key => $value) {
            $this->ini->set($key, $value);
        }

        $result = null;
        $exception = null;
        try {
            $result = $callable(...$params);
        } catch (\Throwable $e) {
            $exception = $e;
        }

        $this->ini->cleanup();

        if ($exception) {
            throw $exception;
        }

        return $result;
    }
797712
static public function isOperation($operation) {
    return ((string) $operation == Connect2PayClient::OPERATION_TYPE_SALE ||
        (string) $operation == Connect2PayClient::OPERATION_TYPE_AUTHORIZE);
  }
779374
public static function getReflectionCallable($callable)
    {
        if (is_callable($callable, true)) {
            try {
                if (is_object($callable)) {
                    return new ReflectionFunction($callable);
                }
                if (is_array($callable)) {
                    return new ReflectionMethod($callable[0], $callable[1]);
                }
                if (strpos($callable, '::') === false) {
                    return new ReflectionFunction($callable);
                }
                return new ReflectionMethod($callable);
            } catch (ReflectionException $exception) {
            }
        }
        return false;
    }
116536
public function execute(string $type, string $operation, array $parameters = [])
    {
        return $this->{$type}->{$operation}(...$parameters);
    }
930138
private function performOperationOn2Currencies($operation)
    {
        $this->assertCurrenciesMatch();

        return new Money(
            $operation($this->valueA->getUnits(), $this->valueB->getUnits()),
            $this->valueA->getCurrency()
        );
    }
920533
public static function call($key, callable $func)
    {
        $trace = debug_backtrace();
        if ($function = $trace[1]["function"]) {
            $key = $function . "_" . $key;
            if ($class = $trace[1]["class"]) {
                $key = str_replace("\\", "_", $class) . "_" . $key;
            }
        }

        if (static::check($key)) {
            return static::get($key);
        }

        $return = $func();

        static::set($key, $return);

        return $return;
    }
1146001
public static function create($callable)
    {
        // Closure
        if ($callable instanceof \Closure) {
            return new \ReflectionFunction($callable);
        }

        // Array callable
        if (is_array($callable)) {
            list($class, $method) = $callable;

            if (! method_exists($class, $method)) {
                throw NotCallableException::fromInvalidCallable($callable);
            }

            return new \ReflectionMethod($class, $method);
        }

        // Callable object (i.e. implementing __invoke())
        if (is_object($callable) && method_exists($callable, '__invoke')) {
            return new \ReflectionMethod($callable, '__invoke');
        }

        // Callable class (i.e. implementing __invoke())
        if (is_string($callable) && class_exists($callable) && method_exists($callable, '__invoke')) {
            return new \ReflectionMethod($callable, '__invoke');
        }

        // Standard function
        if (is_string($callable) && function_exists($callable)) {
            return new \ReflectionFunction($callable);
        }

        throw new NotCallableException(sprintf(
            '%s is not a callable',
            is_string($callable) ? $callable : 'Instance of ' . get_class($callable)
        ));
    }
598518
public function getListArgumentForService(callable $service)
    {
        if (is_array($service)) {
            reset($service);
            $serviceObject = current($service);
            $serviceMethod = next($service);
            return $this->getListArgumentForMethod($serviceObject, $serviceMethod);
        }

        $errMsg = 'Unsupported type callback';
        throw new Exception\UnsupportedServiceTypeException($errMsg);
    }
1275535
public function execute($command, callable $next)
    {
        try {
            return $next($command);
        } catch (ExceptionInterface $exception) {
            throw $exception;
        } catch (ValidationException $exception) {
            $this->exceptionHandler->throwServiceExceptionFromViolationException($exception);
        } catch (RequestException $exception) {
            $this->exceptionHandler->throwServiceExceptionFromRequestException($exception);
        } catch (\Throwable $exception) {
            $this->exceptionHandler->throwServiceException($exception);
        }
    }
1341035
public static function getComparator($operator)
    {
        if (!isset(self::$operators[$operator])) {
            if (count(self::$operatorsMap)) {
                self::initMap();
            }

            if (!isset(self::$operators[$operator])) {
                throw new \Exception(sprintf('"%s" operator not found', $operator));
            }
        }

        return self::$operators[$operator];
    }
80157
public function ignorePersistHooksFor(callable $operation, array $persistHooks)
    {
        InvalidArgumentException::verifyAllInstanceOf(__METHOD__, 'persistHooks', $persistHooks, IPersistHook::class);
        $this->ignorePersistHookStack[] = $persistHooks;
        $result                         = $operation();
        array_pop($this->ignorePersistHookStack);

        return $result;
    }
459569
public static function convertToArray($mixed)
    {
        // get operator from callable
        if (is_callable($mixed)) {
            $callable = $mixed;
            $mixed = new self();
            call_user_func($callable, $mixed);
        }

        // get operator array
        if ($mixed instanceof ArrayableInterface && $mixed instanceof self) {
            $mixed = $mixed->toArray();
        } elseif (!is_array($mixed)) {
            throw new Exception('Mixed must be instance of Operator');
        }

        return $mixed;
    }
798431
public function withTransaction(callable $callable)
    {
        try {
            $nested = $this->transactionStarted;
            if (!$nested) {
                $this->startTransaction();
            }
            $this->transactionStarted = true;
            $result = $callable();
            if (!$nested) {
                $this->commit();
            }
            $this->transactionStarted = $nested;
            return $result;
        } catch (Throwable $e) {
            if ($this->transactionStarted) {
                $this->rollback();
                $this->transactionStarted = false;
            }
            throw $e;
        }
    }
934624
public function each(callable $action = null)
    {
        if ($action === null) {
            $each = call_user_func($this->each);
            if (!self::isIterable($each)) {
                throw new \RuntimeException("return value is not iterable object");
            }
            return $each;
        } else {
            $this->apply($action);
        }

        return null;
    }
373231
private function runOperation(PromiseOperation $operation)
    {
        $promise = $operation->getPromise();

        return $promise->then(
            $this->onTerminate($operation, $this->fulfilledVoter, true, $promise),
            $this->onTerminate($operation, $this->rejectedVoter, false, $promise)
        );
    }
1283183
public function getOperation(string $method): Operation
    {
        if (!$this->hasOperation($method)) {
            throw new \InvalidArgumentException(
                "Path '{$this->getPath()}' does not support '$method'" .
                " (supports " . implode(', ', array_keys($this->operations)) . ')'
            );
        }

        return $this->operations[strtolower($method)];
    }