AbstractController.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 App\Controller;
  12. use Hyperf\Di\Annotation\Inject;
  13. use Hyperf\HttpServer\Contract\RequestInterface;
  14. use Hyperf\HttpServer\Contract\ResponseInterface;
  15. use Psr\Container\ContainerInterface;
  16. abstract class AbstractController
  17. {
  18. /**
  19. * @Inject
  20. * @var ContainerInterface
  21. */
  22. protected $container;
  23. /**
  24. * @Inject
  25. * @var RequestInterface
  26. */
  27. protected $request;
  28. /**
  29. * @Inject
  30. * @var ResponseInterface
  31. */
  32. protected $response;
  33. public function responseApi($code, $message)
  34. {
  35. return [
  36. 'code' => $code,
  37. 'msg' => $message,
  38. ];
  39. }
  40. public function responseApiWithData($code, $message, $data)
  41. {
  42. return [
  43. 'code' => $code,
  44. 'msg' => $message,
  45. 'data' => $data,
  46. ];
  47. }
  48. public function responseApiData($data){
  49. return $data;
  50. }
  51. }