Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Client.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\HttpKernel;
013
014 use Symfony\Component\BrowserKit\Client as BaseClient;
015 use Symfony\Component\BrowserKit\CookieJar;
016 use Symfony\Component\BrowserKit\History;
017 use Symfony\Component\BrowserKit\Request as DomRequest;
018 use Symfony\Component\BrowserKit\Response as DomResponse;
019 use Symfony\Component\HttpFoundation\File\UploadedFile;
020 use Symfony\Component\HttpFoundation\Request;
021 use Symfony\Component\HttpFoundation\Response;
022
023 /**
024 * Client simulates a browser and makes requests to a Kernel object.
025 *
026 * @author Fabien Potencier <fabien@symfony.com>
027 *
028 * @method Request|null getRequest() A Request instance
029 * @method Response|null getResponse() A Response instance
030 */
031 class Client extends BaseClient
032 {
033 protected $kernel;
034 private $catchExceptions = true;
035
036 /**
037 * @param HttpKernelInterface $kernel An HttpKernel instance
038 * @param array $server The server parameters (equivalent of $_SERVER)
039 * @param History $history A History instance to store the browser history
040 * @param CookieJar $cookieJar A CookieJar instance to store the cookies
041 */
042 public function __construct(HttpKernelInterface $kernel, array $server = [], History $history = null, CookieJar $cookieJar = null)
043 {
044 // These class properties must be set before calling the parent constructor, as it may depend on it.
045 $this->kernel = $kernel;
046 $this->followRedirects = false;
047
048 parent::__construct($server, $history, $cookieJar);
049 }
050
051 /**
052 * Sets whether to catch exceptions when the kernel is handling a request.
053 *
054 * @param bool $catchExceptions Whether to catch exceptions
055 */
056 public function catchExceptions($catchExceptions)
057 {
058 $this->catchExceptions = $catchExceptions;
059 }
060
061 /**
062 * Makes a request.
063 *
064 * @return Response A Response instance
065 */
066 protected function doRequest($request)
067 {
068 $response = $this->kernel->handle($request, HttpKernelInterface::MASTER_REQUEST, $this->catchExceptions);
069
070 if ($this->kernel instanceof TerminableInterface) {
071 $this->kernel->terminate($request, $response);
072 }
073
074 return $response;
075 }
076
077 /**
078 * Returns the script to execute when the request must be insulated.
079 *
080 * @return string
081 */
082 protected function getScript($request)
083 {
084 $kernel = var_export(serialize($this->kernel), true);
085 $request = var_export(serialize($request), true);
086
087 $errorReporting = error_reporting();
088
089 $requires = '';
090 foreach (get_declared_classes() as $class) {
091 if (0 === strpos($class, 'ComposerAutoloaderInit')) {
092 $r = new \ReflectionClass($class);
093 $file = \dirname(\dirname($r->getFileName())).'/autoload.php';
094 if (file_exists($file)) {
095 $requires .= 'require_once '.var_export($file, true).";\n";
096 }
097 }
098 }
099
100 if (!$requires) {
101 throw new \RuntimeException('Composer autoloader not found.');
102 }
103
104 $code = <<<EOF
105 <?php
106
107 error_reporting($errorReporting);
108
109 $requires
110
111 \$kernel = unserialize($kernel);
112 \$request = unserialize($request);
113 EOF;
114
115
116 return $code.$this->getHandleScript();
117 }
118
119 protected function getHandleScript()
120 {
121 return <<<'EOF'
122 $response = $kernel->handle($request);
123
124 if ($kernel instanceof Symfony\Component\HttpKernel\TerminableInterface) {
125 $kernel->terminate($request, $response);
126 }
127
128 echo serialize($response);
129 EOF;
130
131 }
132
133 /**
134 * Converts the BrowserKit request to a HttpKernel request.
135 *
136 * @return Request A Request instance
137 */
138 protected function filterRequest(DomRequest $request)
139 {
140 $httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent());
141
142 foreach ($this->filterFiles($httpRequest->files->all()) as $key => $value) {
143 $httpRequest->files->set($key, $value);
144 }
145
146 return $httpRequest;
147 }
148
149 /**
150 * Filters an array of files.
151 *
152 * This method created test instances of UploadedFile so that the move()
153 * method can be called on those instances.
154 *
155 * If the size of a file is greater than the allowed size (from php.ini) then
156 * an invalid UploadedFile is returned with an error set to UPLOAD_ERR_INI_SIZE.
157 *
158 * @see UploadedFile
159 *
160 * @return array An array with all uploaded files marked as already moved
161 */
162 protected function filterFiles(array $files)
163 {
164 $filtered = [];
165 foreach ($files as $key => $value) {
166 if (\is_array($value)) {
167 $filtered[$key] = $this->filterFiles($value);
168 } elseif ($value instanceof UploadedFile) {
169 if ($value->isValid() && $value->getSize() > UploadedFile::getMaxFilesize()) {
170 $filtered[$key] = new UploadedFile(
171 '',
172 $value->getClientOriginalName(),
173 $value->getClientMimeType(),
174 0,
175 \UPLOAD_ERR_INI_SIZE,
176 true
177 );
178 } else {
179 $filtered[$key] = new UploadedFile(
180 $value->getPathname(),
181 $value->getClientOriginalName(),
182 $value->getClientMimeType(),
183 $value->getClientSize(),
184 $value->getError(),
185 true
186 );
187 }
188 }
189 }
190
191 return $filtered;
192 }
193
194 /**
195 * Converts the HttpKernel response to a BrowserKit response.
196 *
197 * @return DomResponse A DomResponse instance
198 */
199 protected function filterResponse($response)
200 {
201 // this is needed to support StreamedResponse
202 ob_start();
203 $response->sendContent();
204 $content = ob_get_clean();
205
206 return new DomResponse($content, $response->getStatusCode(), $response->headers->all());
207 }
208 }
209