DefaultController.php 770 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace app\modules\site\controllers;
  3. use HttpSoft\Message\StreamFactory;
  4. use Psr\Http\Message\ResponseInterface;
  5. class DefaultController extends \Piko\Controller
  6. {
  7. /**
  8. * Return a Hello World! in text/plain
  9. *
  10. * @return ResponseInterface
  11. */
  12. public function plaintextAction(): ResponseInterface
  13. {
  14. $body = (new StreamFactory())->createStream('Hello, World!');
  15. return $this->response->withHeader('Content-Type', 'text/plain; charset=UTF-8')->withBody($body);
  16. }
  17. /**
  18. * Return a json response with a Hello, World! message
  19. *
  20. * @return ResponseInterface
  21. */
  22. public function jsonAction(): ResponseInterface
  23. {
  24. return $this->jsonResponse(['message' => 'Hello, World!']);
  25. }
  26. }