No Description

TestMultipleHttpKernel.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 = array();
  20. protected $statuses = array();
  21. protected $headers = array();
  22. protected $call = false;
  23. protected $backendRequest;
  24. public function __construct($responses)
  25. {
  26. foreach ($responses as $response) {
  27. $this->bodies[] = $response['body'];
  28. $this->statuses[] = $response['status'];
  29. $this->headers[] = $response['headers'];
  30. }
  31. parent::__construct(new EventDispatcher(), $this);
  32. }
  33. public function getBackendRequest()
  34. {
  35. return $this->backendRequest;
  36. }
  37. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = false)
  38. {
  39. $this->backendRequest = $request;
  40. return parent::handle($request, $type, $catch);
  41. }
  42. public function getController(Request $request)
  43. {
  44. return array($this, 'callController');
  45. }
  46. public function getArguments(Request $request, $controller)
  47. {
  48. return array($request);
  49. }
  50. public function callController(Request $request)
  51. {
  52. $this->called = true;
  53. $response = new Response(array_shift($this->bodies), array_shift($this->statuses), array_shift($this->headers));
  54. return $response;
  55. }
  56. public function hasBeenCalled()
  57. {
  58. return $this->called;
  59. }
  60. public function reset()
  61. {
  62. $this->call = false;
  63. }
  64. }