WORKER SERVICE and WORKER OBJECT - scil/LaravelFly GitHub Wiki
WORKER SERVICE
This kind of SERVICE that must satisfy folling conditions:
-
singleton. A singleton service is made by by Illuminate\Containe\Application::singleton() or Illuminate\Containe\Application::instance()
-
its vars should restore if a change made in a request and harm the next request
-
if it has ref attibutes, like app['events'] has an attribubte
container
, the attribute container must be also A WORKER SERVICE.
If a singleton service does not satisfy the second condition, you can try refactor.
WORKER SERVICE and coroutine: COROUTINE-FRIENDLY SERVICE
If you use coroutine in your code, it must be also a COROUTINE-FRIENDLY SERVICE.
-
its vars will not change in any requests
-
if it has ref attibutes, like app['events'] has an attribubte
container
, the container must be also A COROUTINE-FRIENDLY SERVICE
Refactor
There are two Traits LaravelFly\Map\Util\Dict
and LaravelFly\Map\Util\StaticDic
used by LaravelFly to make a service to be a WORKER SERVICE or COROUTINE-FRIENDLY SERVICE. The first trait handles non-static vars, while the second static vars.
method 1: making new classes extending old classes
There two simple examples which make Laravel's official service coroutine-friendly.
service | official | refactor |
---|---|---|
app['event'] | Illuminate\Events\Dispatcher | LaravelFly\Map\IlluminateBase\Dispatcher |
app['translator'] | Illuminate\Translation\Translator | LaravelFly\Map\Illuminate\Translation\Translator |
method 2: making new files replacing old files
service | official | refactor |
---|---|---|
app() | Illuminate/Foundation/Application.php | LaravelFly-fly-files/src/Application.php |
WORKER OBJECT
refactor can work on any other objects like a WORKER SERVICE.
object | official | refactor |
---|---|---|
Facade | Illuminate/Support/Facades/Facade | LaravelFly-fly-files/src/Facade.php |