CakesController.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. declare(strict_types=1);
  3. namespace TestApp\Controller;
  4. use Cake\Controller\Controller;
  5. use Psr\Http\Message\ResponseInterface;
  6. /**
  7. * CakesController class
  8. */
  9. class CakesController extends Controller
  10. {
  11. /**
  12. * The default model to use.
  13. *
  14. * @var string
  15. */
  16. protected ?string $modelClass = 'Posts';
  17. /**
  18. * index method
  19. *
  20. * @return \Cake\Http\Response
  21. */
  22. public function index()
  23. {
  24. return $this->response->withStringBody('Hello Jane');
  25. }
  26. /**
  27. * No autoRender
  28. *
  29. * @return void
  30. */
  31. public function noRender()
  32. {
  33. $this->autoRender = false;
  34. $this->response = $this->response->withStringBody('autoRender false body');
  35. }
  36. /**
  37. * invalid method
  38. *
  39. * @return string
  40. */
  41. public function invalid(): string
  42. {
  43. return 'Some string';
  44. }
  45. /**
  46. * Startup process
  47. *
  48. * \Psr\Http\Message\ResponseInterface|null
  49. */
  50. public function startupProcess(): ?ResponseInterface
  51. {
  52. parent::startupProcess();
  53. if ($this->request->getParam('stop') === 'startup') {
  54. return $this->response->withStringBody('startup stop');
  55. }
  56. return null;
  57. }
  58. /**
  59. * Shutdown process
  60. *
  61. * \Psr\Http\Message\ResponseInterface|null
  62. */
  63. public function shutdownProcess(): ?ResponseInterface
  64. {
  65. parent::shutdownProcess();
  66. if ($this->request->getParam('stop') === 'shutdown') {
  67. return $this->response->withStringBody('shutdown stop');
  68. }
  69. return null;
  70. }
  71. }