class Conditional implements ExtenderInterface

The Conditional extender allows developers to conditionally apply other extenders based on either boolean values or results from callable functions.

This is useful for applying extenders only if certain conditions are met, such as the presence of an enabled extension or a specific configuration setting.

Properties

protected array $conditions An array of conditions and their associated extenders.

Methods

whenExtensionEnabled(string $extensionId, callable|string $extenders)

Apply extenders only if a specific extension is enabled.

whenExtensionDisabled(string $extensionId, callable|string $extenders)

Apply extenders only if a specific extension is disabled.

whenSetting(string $key, mixed $expected, callable|string $extenders, bool $strict = false)

Apply extenders only if a setting matches an expected value.

when(callable|bool $condition, callable|string $extenders)

Apply extenders based on a condition.

void
extend(Container $container, Extension|null $extension = null)

Iterates over the conditions and applies the associated extenders if the conditions are met.

Details

Conditional whenExtensionEnabled(string $extensionId, callable|string $extenders)

Apply extenders only if a specific extension is enabled.

Parameters

string $extensionId The ID of the extension.
callable|string $extenders A callable returning an array of extenders, or an invokable class string.

Return Value

Conditional

Conditional whenExtensionDisabled(string $extensionId, callable|string $extenders)

Apply extenders only if a specific extension is disabled.

Parameters

string $extensionId The ID of the extension.
callable|string $extenders A callable returning an array of extenders, or an invokable class string.

Return Value

Conditional

Conditional whenSetting(string $key, mixed $expected, callable|string $extenders, bool $strict = false)

Apply extenders only if a setting matches an expected value.

Parameters

string $key The settings key.
mixed $expected The expected value.
callable|string $extenders A callable returning an array of extenders, or an invokable class string.
bool $strict Whether to use strict comparison (===). Defaults to false (loose comparison ==).

Return Value

Conditional

Conditional when(callable|bool $condition, callable|string $extenders)

Apply extenders based on a condition.

Parameters

callable|bool $condition A boolean or callable that should return a boolean. If this evaluates to true, the extenders will be applied.
callable|string $extenders A callable returning an array of extenders, or an invokable class string.

Return Value

Conditional

void extend(Container $container, Extension|null $extension = null)

Iterates over the conditions and applies the associated extenders if the conditions are met.

Parameters

Container $container
Extension|null $extension

Return Value

void