Skip to content

ShutdownSequence

The ordered list of components to shut down, and the operations on that order.

Order is the whole point: a component’s shutdown may write through another one, so the sequence is built back-to-front from the factory configuration and every operation here preserves position rather than recomputing it. That is why replacing a component is a splice at its old index and not an append.

final class ShutdownSequence

Since4.0.0
SourceShutdownSequence.php
MethodDescription
all(): array<int, object>The components, in shutdown order.
append(object $component): voidAdd a component at the end of the sequence, so it shuts down last.
count(): intHow many components are in the sequence.
has(object $component): boolWhether the sequence holds this exact component.
remove(callable(object): bool $matches): voidDrop every component the predicate matches, closing the gaps.
replaceAll(array<int, mixed> $components): voidInstall the sequence wholesale.
replaceRole(object $replacement, callable(object): bool $matches, int $fallbackIndex = 0, string $caller = 'replaceRole'): voidReplace every component of one role with $replacement, at the role’s original position.
shutdownAll(?object $skip = null): voidShut every component down in order.

public function all(): array<int, object>

The components, in shutdown order.

Returns array``<``int``, ``object``>

public function append(object $component): void

Add a component at the end of the sequence, so it shuts down last.

Idempotent by identity: a component already in the sequence keeps its existing position rather than being shut down twice.

ParameterTypeDescription
$componentobject

public function count(): int

How many components are in the sequence.

Returns int

public function has(object $component): bool

Whether the sequence holds this exact component.

ParameterTypeDescription
$componentobject

Returns bool

public function remove(callable(object): bool $matches): void

Drop every component the predicate matches, closing the gaps.

ParameterTypeDescription
$matchescallable(object): bool

public function replaceAll(array<int, mixed> $components): void

Install the sequence wholesale.

ParameterTypeDescription
$componentsarray``<``int``, ``mixed``>

public function replaceRole(object $replacement, callable(object): bool $matches, int $fallbackIndex = 0, string $caller = 'replaceRole'): void

Replace every component of one role with $replacement, at the role’s original position.

Label for the debug line, naming why the replacement happened.

ParameterTypeDescription
$replacementobjectThe freshly created component.
$matchescallable(object): boolIdentifies instances of the role.
$fallbackIndexintInsertion point when the role was absent.
$callerstringLabel for the debug line, naming why the replacement happened.

public function shutdownAll(?object $skip = null): void

Shut every component down in order.

A component shut down by its own owner — the user, which the request-state flush persists so the ordering against the session holds. Shutting it down again here would double-write.

ParameterTypeDescription
$skip?``objectA component shut down by its own owner — the user, which the request-state flush persists so the ordering against the session holds. Shutting it down again here would double-write.