TestMultipleHttpKernel.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Tests\HttpCache;
  11. use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
  12. use Symfony\Component\HttpKernel\HttpKernel;
  13. use Symfony\Component\HttpKernel\HttpKernelInterface;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
  17. use Symfony\Component\EventDispatcher\EventDispatcher;
  18. class TestMultipleHttpKernel extends HttpKernel implements ControllerResolverInterface, ArgumentResolverInterface
  19. {
  20. protected $bodies = array();
  21. protected $statuses = array();
  22. protected $headers = array();
  23. protected $called = false;
  24. protected $backendRequest;
  25. public function __construct($responses)
  26. {
  27. foreach ($responses as $response) {
  28. $this->bodies[] = $response['body'];
  29. $this->statuses[] = $response['status'];
  30. $this->headers[] = $response['headers'];
  31. }
  32. parent::__construct(new EventDispatcher(), $this, null, $this);
  33. }
  34. public function getBackendRequest()
  35. {
  36. return $this->backendRequest;
  37. }
  38. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = false)
  39. {
  40. $this->backendRequest = $request;
  41. return parent::handle($request, $type, $catch);
  42. }
  43. public function getController(Request $request)
  44. {
  45. return array($this, 'callController');
  46. }
  47. public function getArguments(Request $request, $controller)
  48. {
  49. return array($request);
  50. }
  51. public function callController(Request $request)
  52. {
  53. $this->called = true;
  54. $response = new Response(array_shift($this->bodies), array_shift($this->statuses), array_shift($this->headers));
  55. return $response;
  56. }
  57. public function hasBeenCalled()
  58. {
  59. return $this->called;
  60. }
  61. public function reset()
  62. {
  63. $this->called = false;
  64. }
  65. }