1234567891011121314151617181920212223242526272829303132 |
- <?php
- declare(strict_types=1);
- namespace App\Listener;
- use Hyperf\Event\Annotation\Listener;
- use Hyperf\Event\Contract\ListenerInterface;
- use Hyperf\Framework\Event\BeforeMainServerStart;
- use Hyperf\Task\TaskExecutor;
- use Psr\Container\ContainerInterface;
- #[Listener]
- class TaskEventListener implements ListenerInterface
- {
- public function __construct(private ContainerInterface $container)
- {
- }
- public function listen(): array
- {
- return [
- BeforeMainServerStart::class,
- ];
- }
- public function process(object $event): void
- {
- $executor = $this->container->get(TaskExecutor::class);
- $event->server->on('Task', [$executor, 'execute']);
- }
- }
|