TestMultipleHttpKernel.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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\HttpKernel;
  12. use Symfony\Component\HttpKernel\HttpKernelInterface;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
  16. use Symfony\Component\EventDispatcher\EventDispatcher;
  17. class TestMultipleHttpKernel extends HttpKernel implements ControllerResolverInterface
  18. {
  19. protected $bodies;
  20. protected $statuses;
  21. protected $headers;
  22. protected $catch;
  23. protected $call;
  24. protected $backendRequest;
  25. public function __construct($responses)
  26. {
  27. $this->bodies = array();
  28. $this->statuses = array();
  29. $this->headers = array();
  30. $this->call = false;
  31. foreach ($responses as $response) {
  32. $this->bodies[] = $response['body'];
  33. $this->statuses[] = $response['status'];
  34. $this->headers[] = $response['headers'];
  35. }
  36. parent::__construct(new EventDispatcher(), $this);
  37. }
  38. public function getBackendRequest()
  39. {
  40. return $this->backendRequest;
  41. }
  42. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = false)
  43. {
  44. $this->backendRequest = $request;
  45. return parent::handle($request, $type, $catch);
  46. }
  47. public function getController(Request $request)
  48. {
  49. return array($this, 'callController');
  50. }
  51. public function getArguments(Request $request, $controller)
  52. {
  53. return array($request);
  54. }
  55. public function callController(Request $request)
  56. {
  57. $this->called = true;
  58. $response = new Response(array_shift($this->bodies), array_shift($this->statuses), array_shift($this->headers));
  59. return $response;
  60. }
  61. public function hasBeenCalled()
  62. {
  63. return $this->called;
  64. }
  65. public function reset()
  66. {
  67. $this->call = false;
  68. }
  69. }