Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/http-kernel/Client.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
12 namespace Symfony\Component\HttpKernel; | 12 namespace Symfony\Component\HttpKernel; |
13 | 13 |
14 use Symfony\Component\BrowserKit\Client as BaseClient; | 14 use Symfony\Component\BrowserKit\Client as BaseClient; |
15 use Symfony\Component\BrowserKit\Request as DomRequest; | 15 use Symfony\Component\BrowserKit\Request as DomRequest; |
16 use Symfony\Component\BrowserKit\Response as DomResponse; | 16 use Symfony\Component\BrowserKit\Response as DomResponse; |
17 use Symfony\Component\BrowserKit\Cookie as DomCookie; | |
18 use Symfony\Component\BrowserKit\History; | 17 use Symfony\Component\BrowserKit\History; |
19 use Symfony\Component\BrowserKit\CookieJar; | 18 use Symfony\Component\BrowserKit\CookieJar; |
20 use Symfony\Component\HttpFoundation\File\UploadedFile; | 19 use Symfony\Component\HttpFoundation\File\UploadedFile; |
21 use Symfony\Component\HttpFoundation\Request; | 20 use Symfony\Component\HttpFoundation\Request; |
22 use Symfony\Component\HttpFoundation\Response; | 21 use Symfony\Component\HttpFoundation\Response; |
24 /** | 23 /** |
25 * Client simulates a browser and makes requests to a Kernel object. | 24 * Client simulates a browser and makes requests to a Kernel object. |
26 * | 25 * |
27 * @author Fabien Potencier <fabien@symfony.com> | 26 * @author Fabien Potencier <fabien@symfony.com> |
28 * | 27 * |
29 * @method Request|null getRequest() A Request instance | 28 * @method Request|null getRequest() A Request instance |
30 * @method Response|null getResponse() A Response instance | 29 * @method Response|null getResponse() A Response instance |
31 */ | 30 */ |
32 class Client extends BaseClient | 31 class Client extends BaseClient |
33 { | 32 { |
34 protected $kernel; | 33 protected $kernel; |
35 | 34 private $catchExceptions = true; |
36 /** | 35 |
37 * Constructor. | 36 /** |
38 * | |
39 * @param HttpKernelInterface $kernel An HttpKernel instance | 37 * @param HttpKernelInterface $kernel An HttpKernel instance |
40 * @param array $server The server parameters (equivalent of $_SERVER) | 38 * @param array $server The server parameters (equivalent of $_SERVER) |
41 * @param History $history A History instance to store the browser history | 39 * @param History $history A History instance to store the browser history |
42 * @param CookieJar $cookieJar A CookieJar instance to store the cookies | 40 * @param CookieJar $cookieJar A CookieJar instance to store the cookies |
43 */ | 41 */ |
49 | 47 |
50 parent::__construct($server, $history, $cookieJar); | 48 parent::__construct($server, $history, $cookieJar); |
51 } | 49 } |
52 | 50 |
53 /** | 51 /** |
52 * Sets whether to catch exceptions when the kernel is handling a request. | |
53 * | |
54 * @param bool $catchExceptions Whether to catch exceptions | |
55 */ | |
56 public function catchExceptions($catchExceptions) | |
57 { | |
58 $this->catchExceptions = $catchExceptions; | |
59 } | |
60 | |
61 /** | |
54 * Makes a request. | 62 * Makes a request. |
55 * | 63 * |
56 * @param Request $request A Request instance | |
57 * | |
58 * @return Response A Response instance | 64 * @return Response A Response instance |
59 */ | 65 */ |
60 protected function doRequest($request) | 66 protected function doRequest($request) |
61 { | 67 { |
62 $response = $this->kernel->handle($request); | 68 $response = $this->kernel->handle($request, HttpKernelInterface::MASTER_REQUEST, $this->catchExceptions); |
63 | 69 |
64 if ($this->kernel instanceof TerminableInterface) { | 70 if ($this->kernel instanceof TerminableInterface) { |
65 $this->kernel->terminate($request, $response); | 71 $this->kernel->terminate($request, $response); |
66 } | 72 } |
67 | 73 |
69 } | 75 } |
70 | 76 |
71 /** | 77 /** |
72 * Returns the script to execute when the request must be insulated. | 78 * Returns the script to execute when the request must be insulated. |
73 * | 79 * |
74 * @param Request $request A Request instance | |
75 * | |
76 * @return string | 80 * @return string |
77 */ | 81 */ |
78 protected function getScript($request) | 82 protected function getScript($request) |
79 { | 83 { |
80 $kernel = str_replace("'", "\\'", serialize($this->kernel)); | 84 $kernel = str_replace("'", "\\'", serialize($this->kernel)); |
81 $request = str_replace("'", "\\'", serialize($request)); | 85 $request = str_replace("'", "\\'", serialize($request)); |
82 | |
83 $r = new \ReflectionClass('\\Symfony\\Component\\ClassLoader\\ClassLoader'); | |
84 $requirePath = str_replace("'", "\\'", $r->getFileName()); | |
85 $symfonyPath = str_replace("'", "\\'", dirname(dirname(dirname(__DIR__)))); | |
86 $errorReporting = error_reporting(); | 86 $errorReporting = error_reporting(); |
87 | |
88 $requires = ''; | |
89 foreach (get_declared_classes() as $class) { | |
90 if (0 === strpos($class, 'ComposerAutoloaderInit')) { | |
91 $r = new \ReflectionClass($class); | |
92 $file = dirname(dirname($r->getFileName())).'/autoload.php'; | |
93 if (file_exists($file)) { | |
94 $requires .= "require_once '".str_replace("'", "\\'", $file)."';\n"; | |
95 } | |
96 } | |
97 } | |
98 | |
99 if (!$requires) { | |
100 throw new \RuntimeException('Composer autoloader not found.'); | |
101 } | |
87 | 102 |
88 $code = <<<EOF | 103 $code = <<<EOF |
89 <?php | 104 <?php |
90 | 105 |
91 error_reporting($errorReporting); | 106 error_reporting($errorReporting); |
92 | 107 |
93 require_once '$requirePath'; | 108 $requires |
94 | |
95 \$loader = new Symfony\Component\ClassLoader\ClassLoader(); | |
96 \$loader->addPrefix('Symfony', '$symfonyPath'); | |
97 \$loader->register(); | |
98 | 109 |
99 \$kernel = unserialize('$kernel'); | 110 \$kernel = unserialize('$kernel'); |
100 \$request = unserialize('$request'); | 111 \$request = unserialize('$request'); |
101 EOF; | 112 EOF; |
102 | 113 |
117 } | 128 } |
118 | 129 |
119 /** | 130 /** |
120 * Converts the BrowserKit request to a HttpKernel request. | 131 * Converts the BrowserKit request to a HttpKernel request. |
121 * | 132 * |
122 * @param DomRequest $request A DomRequest instance | |
123 * | |
124 * @return Request A Request instance | 133 * @return Request A Request instance |
125 */ | 134 */ |
126 protected function filterRequest(DomRequest $request) | 135 protected function filterRequest(DomRequest $request) |
127 { | 136 { |
128 $httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent()); | 137 $httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent()); |
142 * | 151 * |
143 * If the size of a file is greater than the allowed size (from php.ini) then | 152 * If the size of a file is greater than the allowed size (from php.ini) then |
144 * an invalid UploadedFile is returned with an error set to UPLOAD_ERR_INI_SIZE. | 153 * an invalid UploadedFile is returned with an error set to UPLOAD_ERR_INI_SIZE. |
145 * | 154 * |
146 * @see UploadedFile | 155 * @see UploadedFile |
147 * | |
148 * @param array $files An array of files | |
149 * | 156 * |
150 * @return array An array with all uploaded files marked as already moved | 157 * @return array An array with all uploaded files marked as already moved |
151 */ | 158 */ |
152 protected function filterFiles(array $files) | 159 protected function filterFiles(array $files) |
153 { | 160 { |
182 } | 189 } |
183 | 190 |
184 /** | 191 /** |
185 * Converts the HttpKernel response to a BrowserKit response. | 192 * Converts the HttpKernel response to a BrowserKit response. |
186 * | 193 * |
187 * @param Response $response A Response instance | |
188 * | |
189 * @return DomResponse A DomResponse instance | 194 * @return DomResponse A DomResponse instance |
190 */ | 195 */ |
191 protected function filterResponse($response) | 196 protected function filterResponse($response) |
192 { | 197 { |
193 $headers = $response->headers->all(); | |
194 if ($response->headers->getCookies()) { | |
195 $cookies = array(); | |
196 foreach ($response->headers->getCookies() as $cookie) { | |
197 $cookies[] = new DomCookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); | |
198 } | |
199 $headers['Set-Cookie'] = $cookies; | |
200 } | |
201 | |
202 // this is needed to support StreamedResponse | 198 // this is needed to support StreamedResponse |
203 ob_start(); | 199 ob_start(); |
204 $response->sendContent(); | 200 $response->sendContent(); |
205 $content = ob_get_clean(); | 201 $content = ob_get_clean(); |
206 | 202 |
207 return new DomResponse($content, $response->getStatusCode(), $headers); | 203 return new DomResponse($content, $response->getStatusCode(), $response->headers->all()); |
208 } | 204 } |
209 } | 205 } |