Container::register_on_action( string $action, string $class, string $alias )
Registers a service provider on a given action is dispatched.
Parameters
- $action
-
(string) (Required) The action to register the provider on.
- $class
-
(string) (Required) The service provider class name.
- $alias
-
(string) (Optional) The alias(es) to register the service provider with.
Return
(void) The Service Provider is registered when the action fires, or immediately if the action has already fired.
Source
File: src/Conference/Contracts/Container.php
public function register_on_action( string $action, string $class, string ...$alias ): void {
if ( did_action( $action ) ) {
// If the action has already fired, register the provider immediately.
$this->register( $class, ...$alias );
return;
}
// If the action has not fired yet, register the provider when it does.
$registration_closure = function () use ( $action, $class, $alias, &$registration_closure ) {
// Remove the closure from the action to avoid calling it again.
remove_action( $action, $registration_closure );
$this->register( $class, ...$alias );
};
add_action( $action, $registration_closure );
}
Changelog
| Version | Description |
|---|---|
| 1.0.0 | Introduced. |