You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.3 KiB

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller;
  4. use Hyperf\HttpServer\Contract\RequestInterface;
  5. use Hyperf\HttpServer\Annotation\AutoController;
  6. use Hyperf\Utils\Coroutine;
  7. use Hyperf\Utils\ApplicationContext;
  8. use Hyperf\Task\TaskExecutor;
  9. use Hyperf\Task\Task;
  10. use App\TaskWorker\SSDBTask;
  11. /**
  12. * @AutoController()
  13. * Class TestController
  14. * @package App\Controller
  15. */
  16. class TestController extends AbstractController
  17. {
  18. private $name = 'default action';
  19. public function index1(RequestInterface $request)
  20. {
  21. // $container = ApplicationContext::getContainer();
  22. // $exec = $container->get(TaskExecutor::class);
  23. // $result = $exec->execute(new Task([MethodTask::class, 'handle'], [Coroutine::id()]));
  24. $client = ApplicationContext::getContainer()->get(SSDBTask::class);
  25. $result = $client->exec("set","bar","1234");
  26. $result = $client->exec("get","bar");
  27. // $client = ApplicationContext::getContainer()->get(MethodTask::class);
  28. // $result = $client->handle("set");
  29. $this->name = 'index1 action '. $result;
  30. return $this->name;
  31. }
  32. public function index2(RequestInterface $request)
  33. {
  34. $this->name = 'index2 action';
  35. return $this->name;
  36. }
  37. public function index3(RequestInterface $request)
  38. {
  39. return $this->name;
  40. }
  41. }