[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
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; 13 14 use Symfony\Component\BrowserKit\Client as BaseClient; 15 use Symfony\Component\BrowserKit\Cookie as DomCookie; 16 use Symfony\Component\BrowserKit\CookieJar; 17 use Symfony\Component\BrowserKit\History; 18 use Symfony\Component\BrowserKit\Request as DomRequest; 19 use Symfony\Component\BrowserKit\Response as DomResponse; 20 use Symfony\Component\HttpFoundation\File\UploadedFile; 21 use Symfony\Component\HttpFoundation\Request; 22 use Symfony\Component\HttpFoundation\Response; 23 24 /** 25 * Client simulates a browser and makes requests to a Kernel object. 26 * 27 * @author Fabien Potencier <fabien@symfony.com> 28 * 29 * @method Request|null getRequest() A Request instance 30 * @method Response|null getResponse() A Response instance 31 */ 32 class Client extends BaseClient 33 { 34 protected $kernel; 35 36 /** 37 * @param HttpKernelInterface $kernel An HttpKernel instance 38 * @param array $server The server parameters (equivalent of $_SERVER) 39 * @param History $history A History instance to store the browser history 40 * @param CookieJar $cookieJar A CookieJar instance to store the cookies 41 */ 42 public function __construct(HttpKernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null) 43 { 44 // These class properties must be set before calling the parent constructor, as it may depend on it. 45 $this->kernel = $kernel; 46 $this->followRedirects = false; 47 48 parent::__construct($server, $history, $cookieJar); 49 } 50 51 /** 52 * Makes a request. 53 * 54 * @return Response A Response instance 55 */ 56 protected function doRequest($request) 57 { 58 $response = $this->kernel->handle($request); 59 60 if ($this->kernel instanceof TerminableInterface) { 61 $this->kernel->terminate($request, $response); 62 } 63 64 return $response; 65 } 66 67 /** 68 * Returns the script to execute when the request must be insulated. 69 * 70 * @return string 71 */ 72 protected function getScript($request) 73 { 74 $kernel = var_export(serialize($this->kernel), true); 75 $request = var_export(serialize($request), true); 76 77 $r = new \ReflectionClass('\\Symfony\\Component\\ClassLoader\\ClassLoader'); 78 $requirePath = var_export($r->getFileName(), true); 79 $symfonyPath = var_export(\dirname(\dirname(\dirname(__DIR__))), true); 80 $errorReporting = error_reporting(); 81 82 $code = <<<EOF 83 <?php 84 85 error_reporting($errorReporting); 86 87 require_once $requirePath; 88 89 \$loader = new Symfony\Component\ClassLoader\ClassLoader(); 90 \$loader->addPrefix('Symfony', $symfonyPath); 91 \$loader->register(); 92 93 \$kernel = unserialize($kernel); 94 \$request = unserialize($request); 95 EOF; 96 97 return $code.$this->getHandleScript(); 98 } 99 100 protected function getHandleScript() 101 { 102 return <<<'EOF' 103 $response = $kernel->handle($request); 104 105 if ($kernel instanceof Symfony\Component\HttpKernel\TerminableInterface) { 106 $kernel->terminate($request, $response); 107 } 108 109 echo serialize($response); 110 EOF; 111 } 112 113 /** 114 * Converts the BrowserKit request to a HttpKernel request. 115 * 116 * @return Request A Request instance 117 */ 118 protected function filterRequest(DomRequest $request) 119 { 120 $httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent()); 121 122 foreach ($this->filterFiles($httpRequest->files->all()) as $key => $value) { 123 $httpRequest->files->set($key, $value); 124 } 125 126 return $httpRequest; 127 } 128 129 /** 130 * Filters an array of files. 131 * 132 * This method created test instances of UploadedFile so that the move() 133 * method can be called on those instances. 134 * 135 * If the size of a file is greater than the allowed size (from php.ini) then 136 * an invalid UploadedFile is returned with an error set to UPLOAD_ERR_INI_SIZE. 137 * 138 * @see UploadedFile 139 * 140 * @return array An array with all uploaded files marked as already moved 141 */ 142 protected function filterFiles(array $files) 143 { 144 $filtered = array(); 145 foreach ($files as $key => $value) { 146 if (\is_array($value)) { 147 $filtered[$key] = $this->filterFiles($value); 148 } elseif ($value instanceof UploadedFile) { 149 if ($value->isValid() && $value->getSize() > UploadedFile::getMaxFilesize()) { 150 $filtered[$key] = new UploadedFile( 151 '', 152 $value->getClientOriginalName(), 153 $value->getClientMimeType(), 154 0, 155 UPLOAD_ERR_INI_SIZE, 156 true 157 ); 158 } else { 159 $filtered[$key] = new UploadedFile( 160 $value->getPathname(), 161 $value->getClientOriginalName(), 162 $value->getClientMimeType(), 163 $value->getClientSize(), 164 $value->getError(), 165 true 166 ); 167 } 168 } 169 } 170 171 return $filtered; 172 } 173 174 /** 175 * Converts the HttpKernel response to a BrowserKit response. 176 * 177 * @return DomResponse A DomResponse instance 178 */ 179 protected function filterResponse($response) 180 { 181 $headers = $response->headers->all(); 182 if ($response->headers->getCookies()) { 183 $cookies = array(); 184 foreach ($response->headers->getCookies() as $cookie) { 185 $cookies[] = new DomCookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); 186 } 187 $headers['Set-Cookie'] = $cookies; 188 } 189 190 // this is needed to support StreamedResponse 191 ob_start(); 192 $response->sendContent(); 193 $content = ob_get_clean(); 194 195 return new DomResponse($content, $response->getStatusCode(), $headers); 196 } 197 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |