初始化代码

This commit is contained in:
2025-12-22 14:34:25 +08:00
parent c2c5ae2fdd
commit a77dbc743f
1510 changed files with 213008 additions and 0 deletions

View 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();
}
}