public static function Middleware::tap in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/guzzlehttp/guzzle/src/Middleware.php \GuzzleHttp\Middleware::tap()
 
Middleware that invokes a callback before and after sending a request.
The provided listener cannot modify or alter the response. It simply "taps" into the chain to be notified before returning the promise. The before listener accepts a request and options array, and the after listener accepts a request, options array, and response promise.
Parameters
callable $before Function to invoke before forwarding the request.:
callable $after Function invoked after forwarding.:
Return value
callable Returns a function that accepts the next handler.
File
- vendor/
guzzlehttp/ guzzle/ src/ Middleware.php, line 124  
Class
- Middleware
 - Functions used to create and wrap handlers with handler middleware.
 
Namespace
GuzzleHttpCode
public static function tap(callable $before = null, callable $after = null) {
  return function (callable $handler) use ($before, $after) {
    return function ($request, array $options) use ($handler, $before, $after) {
      if ($before) {
        $before($request, $options);
      }
      $response = $handler($request, $options);
      if ($after) {
        $after($request, $options, $response);
      }
      return $response;
    };
  };
}