TestRequestHandler.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @license https://www.opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace TestApp\Http;
  15. use Cake\Http\Response;
  16. use Psr\Http\Message\ResponseInterface;
  17. use Psr\Http\Message\ServerRequestInterface;
  18. use Psr\Http\Server\RequestHandlerInterface;
  19. class TestRequestHandler implements RequestHandlerInterface
  20. {
  21. public $callable;
  22. public function __construct(?callable $callable = null)
  23. {
  24. $this->callable = $callable ?: function ($request) {
  25. return new Response();
  26. };
  27. }
  28. public function handle(ServerRequestInterface $request): ResponseInterface
  29. {
  30. return ($this->callable)($request);
  31. }
  32. }