abstract class AbstractMiddleware implements SetLoggerInterface (View source)

The base middleware class that all other middleware classes extend from. It handles low-level functionality that is shared across all middleware classes.

Traits

Shared code for working with the logger.

Properties

protected LoggerInterface $logger A PSR-3 logger. from LoggerTrait
protected callable $fn A callable which is used to determine whether or not to run this middleware.

Methods

setLogger(LoggerInterface $logger)

Sets the PSR-3 logger.

getLogger()

Retrieves the PSR-3 logger.

__construct(callable|null $fn = null)

Constructs a new instance of this class.

void
addArrayProperty(mixed $object, string $property)

Checks whether or not a particular property exists on an object, and if not, instantiates it as an array.

get(array $arr, string $key, mixed $default = null)

Return the value of an associative array key, if it exists. If not, return $default.

Details

LoggerTrait setLogger(LoggerInterface $logger)

Sets the PSR-3 logger.

Parameters

LoggerInterface $logger A PSR-3 compatible logger.

Return Value

LoggerTrait

LoggerInterface getLogger()

Retrieves the PSR-3 logger.

Return Value

LoggerInterface

__construct(callable|null $fn = null)

Constructs a new instance of this class.

Accepts a callable with the following function signature:

function () {}

Parameters

callable|null $fn A callable which is used to determine whether or not to run this middleware. A value of true means that the middleware should run. A value of false means that the middleware should NOT run, By default, the middleware will run.

void addArrayProperty(mixed $object, string $property)

Checks whether or not a particular property exists on an object, and if not, instantiates it as an array.

Parameters

mixed $object An object that you can add ad-hoc properties to. Preferably a stdClass object.
string $property The name of the property to check and/or add.

Return Value

void

get(array $arr, string $key, mixed $default = null)

Return the value of an associative array key, if it exists. If not, return $default.

Parameters

array $arr The associative array to check.
string $key The key in the associative array to return the value for.
mixed $default The default value to return if there is no value. The default value is null.