Version 1
[yaffs-website] / vendor / symfony / http-kernel / Tests / HttpCache / TestHttpKernel.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\HttpKernel\Tests\HttpCache;
13
14 use Symfony\Component\HttpKernel\HttpKernel;
15 use Symfony\Component\HttpKernel\HttpKernelInterface;
16 use Symfony\Component\HttpFoundation\Request;
17 use Symfony\Component\HttpFoundation\Response;
18 use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
19 use Symfony\Component\EventDispatcher\EventDispatcher;
20
21 class TestHttpKernel extends HttpKernel implements ControllerResolverInterface
22 {
23     protected $body;
24     protected $status;
25     protected $headers;
26     protected $called = false;
27     protected $customizer;
28     protected $catch = false;
29     protected $backendRequest;
30
31     public function __construct($body, $status, $headers, \Closure $customizer = null)
32     {
33         $this->body = $body;
34         $this->status = $status;
35         $this->headers = $headers;
36         $this->customizer = $customizer;
37
38         parent::__construct(new EventDispatcher(), $this);
39     }
40
41     public function getBackendRequest()
42     {
43         return $this->backendRequest;
44     }
45
46     public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = false)
47     {
48         $this->catch = $catch;
49         $this->backendRequest = $request;
50
51         return parent::handle($request, $type, $catch);
52     }
53
54     public function isCatchingExceptions()
55     {
56         return $this->catch;
57     }
58
59     public function getController(Request $request)
60     {
61         return array($this, 'callController');
62     }
63
64     public function getArguments(Request $request, $controller)
65     {
66         return array($request);
67     }
68
69     public function callController(Request $request)
70     {
71         $this->called = true;
72
73         $response = new Response($this->body, $this->status, $this->headers);
74
75         if (null !== $customizer = $this->customizer) {
76             $customizer($request, $response);
77         }
78
79         return $response;
80     }
81
82     public function hasBeenCalled()
83     {
84         return $this->called;
85     }
86
87     public function reset()
88     {
89         $this->called = false;
90     }
91 }