This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
events
scil edited this page Aug 20, 2018
·
1 revision
Laravel has an dispatcher named 'events' in container, which is an app events dispatcher for Laravelfly.
There is another server dispatcher (Symfony\Component\EventDispatcher).
The app dispatcher objects does not created until the Laravel app created.
- worker.starting
available args: $event['server'], $event['workerid'] the swooler http server wrapped in a Laravelfly server can be got by $event['server']->getSwoole(). - laravel.ready
available args: $event['server'], $event['app'], $event['request']
the $event['request'] is null unless FpmLike is used. - Laravel provides event 'bootstrapping' and event 'bootstrapped' of multiple Bootstrap classes listed in your kernel class
In Mode Map, callbacks bootingCallbacks are called after the event 'bootstrapping: LaravelFly\Map\Bootstrap\RegisterAndBootProvidersOnWork', before the event 'bootstrapped: LaravelFly\Map\Bootstrap\RegisterAndBootProvidersOnWork' - worker.ready
available args: $event['server'], $event['workerid'], $event['app']
the $event['app'] is null with Mode FpmLike.
In Mode Simple or Map, this event may look like 'PHP_MINIT_FUNCTION' in php ext, or 'before_first_request' in python Flask. - worker.stopped
available args: $event['server'] ,$event['workerid'], $event['app']
Events provides by laravelfly are instances of Symfony\Component\EventDispatcher\GenericEvent, they can be used like
$dispatcher = \LaravelFly\Fly::getServer()->getDispatcher();
$dispatcher->addListener('worker.starting', function (GenericEvent $event) {
echo "There files can not be hot reloaded, because they are included before worker starting\n";
var_dump(get_included_files());
});
$dispatcher->addListener('laravel.ready', function (GenericEvent $event) {
$event['app']->instance('tinker', \LaravelFly\Tinker\Shell::$instance);
});
$dispatcher can also be available in a new server class which extends LaravelFly\Server\HttpServer or LaravelFly\Server\FpmHttpServer.
class MyServer extends \LaravelFly\Server\HttpServer
{
public function start()
{
$this->dispatcher->addListener('laravel.ready', function (GenericEvent $event) {
$event['app']->instance('tinker', \LaravelFly\Tinker\Shell::$instance);
});
parent::start();
}
}
Put the new class in the server config file fly.conf.php
'server' => MyServer::class,
- request.corinit
- bootedCallbacks (callbacks provided by laravel)
register a callback: app()->booted($callback) - Illuminate\Routing\Events\RouteMatched (provided by laravel)
- Illuminate\Foundation\Http\Events\RequestHandled (provided by laravel)
- terminatingCallbacks (callbacks provided by laravel)
register a callback: app()->terminating($callback) - request.corunset
- bootingCallbacks (callbacks provided by laravel)
- bootedCallbacks (callbacks provided by laravel)
- Illuminate\Routing\Events\RouteMatched
- Illuminate\Foundation\Http\Events\RequestHandled
- terminatingCallbacks (callbacks provided by laravel)
- Start
- Coding Guideline
- Deploy and OS Configuration
- New API
- Design
- Dev about Mode Map
- Dev about Mode Backup