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;
            };
        };
    }
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;
            };
        };
    }
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 ; } ; } ; }
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.

@param callable $before Function to invoke before forwarding the request.
@param callable $after  Function invoked after forwarding.

@return callable Returns a function that accepts the next handler.
Middleware that invokes a callback before and after sending a request .