Request Lifecycle
The Request Lifecycle describes how the application is bootstrapped, how services are registered, and how the application handles requests.
Application Class
The Ecommerce\Core\Application class is the heart of the plugin. It extends the Service Container and manages the application's lifecycle.
Boot Application
Boot the application and all registered service providers.
Description:
The boot() method initializes the application by booting all registered service providers. This is the entry point for the application's execution flow. It ensures that all services are ready to be used. It also registers core CLI commands if the application is running in a CLI environment.
Method Signature:
public function boot(): void
Examples:
// In the main plugin file
$app = Ecommerce\Core\Application::get_instance();
// Boot the application
$app->boot();
// Check if booted
if ($app->is_booted()) {
// Application logic...
}
Execution Output:
// No direct output, but triggers provider boot methods:
// - PolicyDiscovery::discover()
// - ListenerDiscovery::discover()
// - Scheduler::setup()
Register Service Provider
Register a service provider with the application.
Description:
The register() method allows you to register a service provider. Service providers are responsible for binding services into the container. You can pass either a ServiceProvider instance or a fully qualified class name.
Method Signature:
public function register(ServiceProvider|string $provider): ServiceProvider
Parameters:
$provider- TheServiceProviderinstance or class name string to register.
Examples:
use Ecommerce\Providers\AppServiceProvider;
// Register by class name
$app->register(AppServiceProvider::class);
// Register by instance
$app->register(new AppServiceProvider($app));
Execution Output:
// Returns the registered ServiceProvider instance.
// Triggers the register() method of the provider.
Check CLI Availability
Check if the application is running in a CLI environment.
Description:
The is_cli_available() method determines if the application is running within a WP-CLI context. This is useful for conditionally registering commands or executing CLI-specific logic.
Method Signature:
public function is_cli_available(): bool
Examples:
if ($app->is_cli_available()) {
// Register custom commands
$app->make('command')->add('custom:command', CustomCommand::class);
}
Execution Output:
// Returns true if WP_CLI constant is defined and true
Configure Application
Get the singleton instance of the application.
Description:
The configure() method is a static alias for get_instance(). It retrieves the single active instance of the Application class.
Method Signature:
public static function configure(): self
Examples:
$app = Ecommerce\Core\Application::configure();