You are here

class DebuggerMiddleware in Acquia Purge 8

HTTP middleware which logs requests and responses for debugging purposes.

Hierarchy

Expanded class hierarchy of DebuggerMiddleware

1 string reference to 'DebuggerMiddleware'
acquia_purge.services.yml in ./acquia_purge.services.yml
acquia_purge.services.yml
1 service uses DebuggerMiddleware
http_client_middleware.acquia_purge_debugger_middleware in ./acquia_purge.services.yml
Drupal\acquia_purge\Http\DebuggerMiddleware

File

src/Http/DebuggerMiddleware.php, line 12

Namespace

Drupal\acquia_purge\Http
View source
class DebuggerMiddleware implements DebuggerAwareInterface {
  use DebuggerAwareTrait;

  /**
   * {@inheritdoc}
   */
  public function __invoke() {
    return function (callable $handler) {
      return function ($req, array $options) use ($handler) {

        // Don't interfere on requests not made by the acquia_purge module, or
        // set the debgger object (::setDebugger will do input type validation).
        if (!isset($options['acquia_purge_debugger'])) {
          return $handler($req, $options);
        }
        else {
          $this
            ->setDebugger($options['acquia_purge_debugger'], FALSE);
        }

        // Render a visual separation between middleware invocations.
        $this
          ->debugger()
          ->writeSeparator('█');

        // Guzzle Request Options.
        $info = [];
        foreach ($options as $key => $value) {
          if (is_scalar($value)) {
            $info[$key] = $value;
          }
        }
        $this
          ->debugger()
          ->writeTable($info, 'Guzzle Request Options');

        // Cache Tags Mapping.
        if (isset($options['acquia_purge_tags'])) {
          $this
            ->debugger()
            ->writeTable($options['acquia_purge_tags']
            ->getTagsMap(), 'Cache Tags Mapping');
        }

        // Request table.
        $info = $this
          ->debugger()
          ->extractRequestInfo($req);
        $this
          ->debugger()
          ->writeTable($info);

        // Return a handler which writes out a response table.
        return $handler($req, $options)
          ->then(function (ResponseInterface $rsp) {
          $info = $this
            ->debugger()
            ->extractResponseInfo($rsp);
          $this
            ->debugger()
            ->writeTable($info);
          return $rsp;
        });
      };
    };
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DebuggerAwareTrait::$debuggerInstance private property The debugger instance.
DebuggerAwareTrait::debugger public function
DebuggerAwareTrait::setDebugger public function
DebuggerMiddleware::__invoke public function
PurgeLoggerAwareTrait::$logger protected property Channel logger.
PurgeLoggerAwareTrait::logger public function