ResetService.php 890 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace think\swoole\resetters;
  3. use think\Container;
  4. use think\swoole\concerns\ModifyProperty;
  5. use think\swoole\contract\ResetterInterface;
  6. use think\swoole\Sandbox;
  7. /**
  8. * Class ResetService
  9. * @package think\swoole\resetters
  10. * @property Container $app;
  11. */
  12. class ResetService implements ResetterInterface
  13. {
  14. use ModifyProperty;
  15. /**
  16. * "handle" function for resetting app.
  17. *
  18. * @param Container $app
  19. * @param Sandbox $sandbox
  20. */
  21. public function handle(Container $app, Sandbox $sandbox)
  22. {
  23. foreach ($sandbox->getServices() as $service) {
  24. $this->modifyProperty($service, $app);
  25. if (method_exists($service, 'register')) {
  26. $service->register();
  27. }
  28. if (method_exists($service, 'boot')) {
  29. $app->invoke([$service, 'boot']);
  30. }
  31. }
  32. }
  33. }