ProcessManager.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Process;
  12. use Hyperf\Contract\ProcessInterface;
  13. use RuntimeException;
  14. class ProcessManager
  15. {
  16. protected static array $processes = [];
  17. protected static bool $running = false;
  18. public static function register(ProcessInterface $process): void
  19. {
  20. if (static::$running) {
  21. throw new RuntimeException('Processes is running, please register before BeforeMainServerStart or MainCoroutineServerStart dispatched.');
  22. }
  23. static::$processes[] = $process;
  24. }
  25. public static function all(): array
  26. {
  27. return static::$processes;
  28. }
  29. public static function clear(): void
  30. {
  31. static::$processes = [];
  32. }
  33. public static function isRunning(): bool
  34. {
  35. return static::$running;
  36. }
  37. public static function setRunning(bool $running): void
  38. {
  39. static::$running = $running;
  40. }
  41. }