初始化代码
This commit is contained in:
45
vendor/topthink/think-swoole/src/resetters/ResetService.php
vendored
Normal file
45
vendor/topthink/think-swoole/src/resetters/ResetService.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace think\swoole\resetters;
|
||||
|
||||
use think\Container;
|
||||
use think\swoole\contract\ResetterInterface;
|
||||
use think\swoole\Sandbox;
|
||||
|
||||
/**
|
||||
* Class ResetService
|
||||
* @package think\swoole\resetters
|
||||
* @property Container $app;
|
||||
*/
|
||||
class ResetService implements ResetterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* "handle" function for resetting app.
|
||||
*
|
||||
* @param Container $app
|
||||
* @param Sandbox $sandbox
|
||||
*/
|
||||
public function handle(Container $app, Sandbox $sandbox)
|
||||
{
|
||||
foreach ($sandbox->getServices() as $service) {
|
||||
$this->rebindServiceContainer($app, $service);
|
||||
if (method_exists($service, 'register')) {
|
||||
$service->register();
|
||||
}
|
||||
if (method_exists($service, 'boot')) {
|
||||
$app->invoke([$service, 'boot']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function rebindServiceContainer($app, $service)
|
||||
{
|
||||
$closure = function () use ($app) {
|
||||
$this->app = $app;
|
||||
};
|
||||
|
||||
$resetService = $closure->bindTo($service, $service);
|
||||
$resetService();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user