TaskEventListener.php 747 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Listener;
  4. use Hyperf\Event\Annotation\Listener;
  5. use Hyperf\Event\Contract\ListenerInterface;
  6. use Hyperf\Framework\Event\BeforeMainServerStart;
  7. use Hyperf\Task\TaskExecutor;
  8. use Psr\Container\ContainerInterface;
  9. #[Listener]
  10. class TaskEventListener implements ListenerInterface
  11. {
  12. public function __construct(private ContainerInterface $container)
  13. {
  14. }
  15. public function listen(): array
  16. {
  17. return [
  18. BeforeMainServerStart::class,
  19. ];
  20. }
  21. public function process(object $event): void
  22. {
  23. $executor = $this->container->get(TaskExecutor::class);
  24. $event->server->on('Task', [$executor, 'execute']);
  25. }
  26. }