super-kernel / event
Application startup event declaration for SuperKernel.
Requires
- php: >=8.4.27 <8.5
- super-kernel/contract: 1.0.0-alpha.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.95.27
- phpunit/phpunit: ^13.4.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-11 02:23:30 UTC
README
English | 中文文档
SuperKernel Event
super-kernel/event declares the application lifecycle events that SuperKernel publishes, so that components and applications can act when an application starts and when a project is built.
Installation
composer require super-kernel/event
The package has no requirement beyond PHP. It only declares events: to receive them, an application also needs super-kernel/event-dispatcher, which registers listeners, and a publisher, which is super-kernel/framework for BeforeApplicationStart and skernel build for ApplicationBuild.
What it provides
BeforeApplicationStart, published after the application is created and before it is returned to run, carrying that application.ApplicationBuild, published once byskernel buildso that components write the artifacts a packaged application loads.
It does not:
- dispatch events or discover listeners;
super-kernel/event-dispatcherdoes; - decide when an event is published; the publishing package does;
- declare events for other boundaries, such as after start or at stop; an application declares its own event classes for those.
Quick start
In an application created from super-kernel/skeleton, this listener renames the console application before it runs. Save it as src/Listener/NameTheApplication.php:
<?php declare(strict_types=1); namespace Src\Listener; use SuperKernel\Attribute\Listener; use SuperKernel\Contract\ListenerInterface; use SuperKernel\Event\BeforeApplicationStart; use Symfony\Component\Console\Application; #[Listener] final readonly class NameTheApplication implements ListenerInterface { public function listen(): array { return [ BeforeApplicationStart::class, ]; } public function process(object $event): void { assert($event instanceof BeforeApplicationStart); $application = $event->application(); if ($application instanceof Application) { $application->setName('Billing'); } } }
Build the project and ask the application for its name:
skernel build php bin/bootstrap.php --version
The output starts with Billing.
Public surface
| Name | Kind | Purpose |
|---|---|---|
SuperKernel\Event\BeforeApplicationStart |
Event | Published after the application is created and before it is returned; application() returns that application. |
SuperKernel\Event\ApplicationBuild |
Event | Published once during skernel build, in the project's own process; it carries no payload. |
Behavior to know
- Creating an event object publishes nothing and starts nothing.
super-kernel/frameworkpublishesBeforeApplicationStartonce for each application it creates, synchronously. An exception from a listener propagates, and the application is not returned or run.skernel buildpublishesApplicationBuildwithout creating or running the application. An exception from a listener fails the build.- Listeners are discovered from the build metadata: run
skernel buildagain after adding, removing, or changing a listener, or start withskernel run, which builds first.
Documentation
The developer documentation describes both events, more listener examples, and how the packages that publish them work together: SuperKernel Event.
License
Released under the MIT License. See LICENSE.