You are here

public static function Middleware::history in Lockr 7.3

Middleware that pushes history data to an ArrayAccess container.

Parameters

array|\ArrayAccess $container Container to hold the history (by reference).:

Return value

callable Returns a function that accepts the next handler.

Throws

\InvalidArgumentException if container is not an array or ArrayAccess.

File

vendor/guzzlehttp/guzzle/src/Middleware.php, line 81

Class

Middleware
Functions used to create and wrap handlers with handler middleware.

Namespace

GuzzleHttp

Code

public static function history(&$container) {
  if (!is_array($container) && !$container instanceof \ArrayAccess) {
    throw new \InvalidArgumentException('history container must be an array or object implementing ArrayAccess');
  }
  return function (callable $handler) use (&$container) {
    return function ($request, array $options) use ($handler, &$container) {
      return $handler($request, $options)
        ->then(function ($value) use ($request, &$container, $options) {
        $container[] = [
          'request' => $request,
          'response' => $value,
          'error' => null,
          'options' => $options,
        ];
        return $value;
      }, function ($reason) use ($request, &$container, $options) {
        $container[] = [
          'request' => $request,
          'response' => null,
          'error' => $reason,
          'options' => $options,
        ];
        return \GuzzleHttp\Promise\rejection_for($reason);
      });
    };
  };
}