Skip to content

MiddlewareCatalog

MiddlewareCatalog stores enable/disable flags for middleware FQCNs, settable programmatically via MiddlewareCatalog::initialize() (tests, app bootstrap code), so the runtime pipeline builder can cheaply skip optional middlewares.

Unknown classes default to enabled (backwards compatible). Declarative middleware.xml enable/disable is a separate, higher-level mechanism (see MiddlewareConfigRegistry) that merges into a MiddlewareDefinition’s own enabled field rather than this map — this map still wins when both are present (see the precedence check in MiddlewarePipeline::doBuild()).

class MiddlewareCatalog

SourceMiddleware/MiddlewareCatalog.php
ConstantValueDescription
REPLACE_CORE_STACK_ACKNOWLEDGEMENT'I_UNDERSTAND_THIS_DISCARDS_ERROR_HANDLING_SESSIONS_CSRF_S…'The exact string MiddlewareCatalog::replaceCoreStack() requires as its second argument.
MethodDescription
all(): array<string, bool>Raw map mainly for tests.
[`attributedFactory(string $fqcn): callable(Context): \Psr\Http\Server\MiddlewareInterfacenull`](#attributedfactory)
buildCoreStack(Context $context): list<MiddlewareInterface>Invoke the app-supplied replacement factory.
getAttributedCandidates(): array<string>
getRegistered(): array<string, array{fqcn: string, factory: callable, after: ?string, before: ?string, priority: int}>
hasCoreStackOverride(): boolWhether an app has installed a full core-stack replacement via MiddlewareCatalog::replaceCoreStack().
hasOverride(string $fqcn): boolWhether $fqcn has an explicit enabled/disabled entry via MiddlewareCatalog::initialize().
initialize(array<string, bool> $map): voidInitialize the catalog (idempotent overwrite).
isEnabled(string $fqcn): boolWhether a middleware is enabled; unknown => true.
[`register(string $fqcn, callable $factory, stringnull $after = null, string
registerAttributed(string $fqcn, ?callable(Context): \Psr\Http\Server\MiddlewareInterface $factory = null): voidRegister an app/plugin middleware class as a candidate for #[Middleware] attribute scanning.
replaceCoreStack(callable(Context): list<\Psr\Http\Server\MiddlewareInterface> $factory, string $acknowledgement): voidReplaces Quiote’s ENTIRE built-in middleware stack — including ErrorHandlingMiddleware, SessionMiddleware, CSRF, SecurityMiddleware, and RoutingMiddleware — with one supplied by the application.
reset(): voidClear all registered middleware (mainly for tests).

public static function all(): array<string, bool>

Raw map mainly for tests.

Returns array``<``string``, ``bool``>

public static function attributedFactory(string $fqcn): callable(Context): \Psr\Http\Server\MiddlewareInterface|null

ParameterTypeDescription
$fqcnstring

Returns callable(Context): \Psr\Http\Server\MiddlewareInterface``|``null — The custom factory for $fqcn, if one was supplied to MiddlewareCatalog::registerAttributed().

public static function buildCoreStack(Context $context): list<MiddlewareInterface>

Invoke the app-supplied replacement factory.

ParameterTypeDescription
$contextContext

Returns list``<MiddlewareInterface>

public static function getAttributedCandidates(): array<string>

Returns array``<``string``> — FQCNs registered via MiddlewareCatalog::registerAttributed().

public static function getRegistered(): array<string, array{fqcn: string, factory: callable, after: ?string, before: ?string, priority: int}>

Returns array``<``string``, ``array{fqcn: string, factory: callable, after: ?string, before: ?string, priority: int}``>

public static function hasCoreStackOverride(): bool

Whether an app has installed a full core-stack replacement via MiddlewareCatalog::replaceCoreStack().

Returns bool

public static function hasOverride(string $fqcn): bool

Whether $fqcn has an explicit enabled/disabled entry via MiddlewareCatalog::initialize().

ParameterTypeDescription
$fqcnstring

Returns bool

public static function initialize(array<string, bool> $map): void

Initialize the catalog (idempotent overwrite).

ParameterTypeDescription
$maparray``<``string``, ``bool``>

public static function isEnabled(string $fqcn): bool

Whether a middleware is enabled; unknown => true.

ParameterTypeDescription
$fqcnstring

Returns bool

public static function register(string $fqcn, callable $factory, string|null $after = null, string|null $before = null, int $priority = 0): void

Register a custom middleware to be inserted into the pipeline.

Ordering among registered middleware at the same position (lower = earlier)

ParameterTypeDescription
$fqcnstringFully-qualified class name (used as key + debug label)
$factorycallableFactory that returns a PSR-15 MiddlewareInterface
$after`string““null`
$before`string““null`
$priorityintOrdering among registered middleware at the same position (lower = earlier)

public static function registerAttributed(string $fqcn, ?callable(Context): \Psr\Http\Server\MiddlewareInterface $factory = null): void

Register an app/plugin middleware class as a candidate for #[Middleware] attribute scanning.

ParameterTypeDescription
$fqcnstring
$factory?``callable(Context): \Psr\Http\Server\MiddlewareInterface

public static function replaceCoreStack(callable(Context): list<\Psr\Http\Server\MiddlewareInterface> $factory, string $acknowledgement): void

Replaces Quiote’s ENTIRE built-in middleware stack — including ErrorHandlingMiddleware, SessionMiddleware, CSRF, SecurityMiddleware, and RoutingMiddleware — with one supplied by the application.

Returns the complete ordered stack. Quiote still appends a terminal sentinel after it so the pipeline always yields a response instead of silently returning null — that’s a PSR-15 contract requirement, not an opinion about what your stack should contain. Externally MiddlewareCatalog::register()-ed middleware is NOT spliced in when this is active; if you want it, add it inside $factory yourself.

ParameterTypeDescription
$factorycallable(Context): list<\Psr\Http\Server\MiddlewareInterface>Returns the complete ordered stack. Quiote still appends a terminal sentinel after it so the pipeline always yields a response instead of silently returning null — that’s a PSR-15 contract requirement, not an opinion about what your stack should contain. Externally MiddlewareCatalog::register()-ed middleware is NOT spliced in when this is active; if you want it, add it inside $factory yourself.
$acknowledgementstring
ThrowsWhen
InvalidArgumentExceptionif $acknowledgement doesn’t match exactly.

public static function reset(): void

Clear all registered middleware (mainly for tests).