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.

55 lines
1.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  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. use App\TaskWorker\AliIotTask;
  12. /**
  13. * @AutoController()
  14. * Class TestController
  15. * @package App\Controller
  16. */
  17. class TestController extends AbstractController
  18. {
  19. private $name = 'default action';
  20. public function index1(RequestInterface $request)
  21. {
  22. // $container = ApplicationContext::getContainer();
  23. // $exec = $container->get(TaskExecutor::class);
  24. // $result = $exec->execute(new Task([MethodTask::class, 'handle'], [Coroutine::id()]));
  25. // $client = ApplicationContext::getContainer()->get(SSDBTask::class);
  26. // $result = $client->exec("set","bar","1234");
  27. // $result = $client->exec("get","bar");
  28. $client = ApplicationContext::getContainer()->get(AliIotTask::class);
  29. $client->exec("set","bar","1234");
  30. // $client = ApplicationContext::getContainer()->get(MethodTask::class);
  31. // $result = $client->handle("set");
  32. $this->name = 'index1 action '. $result;
  33. return $this->name;
  34. }
  35. public function index2(RequestInterface $request)
  36. {
  37. $this->name = 'index2 action';
  38. return $this->name;
  39. }
  40. public function index3(RequestInterface $request)
  41. {
  42. return $this->name;
  43. }
  44. }