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 $conditions An array of conditions and their associated extenders.

Methods

whenExtensionEnabled(string $extensionId, ExtenderInterface[]|callable|string $extenders)

Apply extenders only if a specific extension is enabled.

whenExtensionDisabled(string $extensionId, ExtenderInterface[]|callable|string $extenders)

Apply extenders only if a specific extension is disabled/not installed.

when(bool|callable $condition, ExtenderInterface[]|callable|string $extenders)

Apply extenders based on a condition.

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

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

Details

Conditional whenExtensionEnabled(string $extensionId, ExtenderInterface[]|callable|string $extenders)

Apply extenders only if a specific extension is enabled.

Parameters

string $extensionId The ID of the extension.
ExtenderInterface[]|callable|string $extenders An array of extenders, a callable returning an array of extenders, or an invokable class string.

Return Value

Conditional

Conditional whenExtensionDisabled(string $extensionId, ExtenderInterface[]|callable|string $extenders)

Apply extenders only if a specific extension is disabled/not installed.

Parameters

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

Return Value

Conditional

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

Apply extenders based on a condition.

Parameters

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

Return Value

Conditional

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

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

Parameters

Container $container
Extension $extension