Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Middleware.php

function 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 135

Class

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

Namespace

GuzzleHttp

Code

public static function tap(?callable $before = null, ?callable $after = null) : callable {
    return static function (callable $handler) use ($before, $after) : callable {
        return static function (RequestInterface $request, array $options) use ($handler, $before, $after) {
            if ($before) {
                $before($request, $options);
            }
            $response = $handler($request, $options);
            if ($after) {
                $after($request, $options, $response);
            }
            return $response;
        };
    };
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal