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

Methods

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

<p>Apply extenders only if a specific extension is enabled.</p>

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

<p>Apply extenders only if a specific extension is disabled.</p>

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

<p>Apply extenders based on a condition.</p>

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

<p>Iterates over the conditions and applies the associated extenders if the conditions are met.</p>

Details

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

<p>Apply extenders only if a specific extension is enabled.</p>

Parameters

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

Return Value

Conditional

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

<p>Apply extenders only if a specific extension is disabled.</p>

Parameters

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

Return Value

Conditional

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

<p>Apply extenders based on a condition.</p>

Parameters

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

Return Value

Conditional

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

<p>Iterates over the conditions and applies the associated extenders if the conditions are met.</p>

Parameters

Container $container
Extension $extension

Return Value

void