Events
What's happening?
Events are a powerful tool to escape and interact between various pieces of functionality. In general, there are only a few methods:
- \Neoan3\Core\Event::listen($eventname, $closure )
- \Neoan3\Core\Event::listenAll($closure )
- \Neoan3\Core\Event::dispatch($eventname, $closure )
- \Neoan3\Core\Event::getFiredEvents()
- \Neoan3\Core\Event::getRegisteredListeners()
- \Neoan3\Core\Event::hook($eventname, $closure)
// example in default.php:
\Neoan3\Core\Event::listen('Core::beforeInit', fn($event) => var_dump($event))
You can dispatch custom events as needed using Event::dispatch. Here we want to give you a quick look at existing core-events:
Core::beforeInit
Earliest event fired. This event happens AFTER resources are loaded and BEFORE any methods, instances or functions are called.
Core\Route::notFound
This event happens AFTER a route has been searched for and BEFORE a 404 redirect and header gets served.
Core\Reflection::attribute
Fired when PHP8 attribute was encountered.
Core\Api::incoming
This event happens AFTER the API handler has been initialized and BEFORE processing of the request begins.
Core\Api::beforeAnswer
This event happens AFTER the API has completed the request and BEFORE the response is sent to the client.
Core\Api::afterAnswer
This event happens AFTER the API has completed the request and AFTER the response is sent to the client.
(Getting ideas?: neoan3 does not ship with parallelism out of the box.
We play nicely with Spatie's Asynchronous and parallel PHP and are fans of
Swoole)
Core\Api::error
This event happens on multiple occasions AFTER an issue was encountered and BEFORE a response is sent to the client.