Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
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\Request as DomRequest;
016 use Symfony\Component\BrowserKit\Response as DomResponse;
017 use Symfony\Component\BrowserKit\Cookie as DomCookie;
018 use Symfony\Component\BrowserKit\History;
019 use Symfony\Component\BrowserKit\CookieJar;
020 use Symfony\Component\HttpFoundation\File\UploadedFile;
021 use Symfony\Component\HttpFoundation\Request;
022 use Symfony\Component\HttpFoundation\Response;
023
024 /**
025 * Client simulates a browser and makes requests to a Kernel object.
026 *
027 * @author Fabien Potencier <fabien@symfony.com>
028 */
029 class Client extends BaseClient
030 {
031 protected $kernel;
032
033 /**
034 * Constructor.
035 *
036 * @param HttpKernelInterface $kernel An HttpKernel instance
037 * @param array $server The server parameters (equivalent of $_SERVER)
038 * @param History $history A History instance to store the browser history
039 * @param CookieJar $cookieJar A CookieJar instance to store the cookies
040 */
041 public function __construct(HttpKernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null)
042 {
043 // These class properties must be set before calling the parent constructor, as it may depend on it.
044 $this->kernel = $kernel;
045 $this->followRedirects = false;
046
047 parent::__construct($server, $history, $cookieJar);
048 }
049
050 /**
051 * {@inheritdoc}
052 *
053 * @return Request|null A Request instance
054 */
055 public function getRequest()
056 {
057 return parent::getRequest();
058 }
059
060 /**
061 * {@inheritdoc}
062 *
063 * @return Response|null A Response instance
064 */
065 public function getResponse()
066 {
067 return parent::getResponse();
068 }
069
070 /**
071 * Makes a request.
072 *
073 * @param Request $request A Request instance
074 *
075 * @return Response A Response instance
076 */
077 protected function doRequest($request)
078 {
079 $response = $this->kernel->handle($request);
080
081 if ($this->kernel instanceof TerminableInterface) {
082 $this->kernel->terminate($request, $response);
083 }
084
085 return $response;
086 }
087
088 /**
089 * Returns the script to execute when the request must be insulated.
090 *
091 * @param Request $request A Request instance
092 *
093 * @return string
094 */
095 protected function getScript($request)
096 {
097 $kernel = str_replace("'", "\\'", serialize($this->kernel));
098 $request = str_replace("'", "\\'", serialize($request));
099
100 $r = new \ReflectionClass('\\Symfony\\Component\\ClassLoader\\ClassLoader');
101 $requirePath = str_replace("'", "\\'", $r->getFileName());
102 $symfonyPath = str_replace("'", "\\'", dirname(dirname(dirname(__DIR__))));
103 $errorReporting = error_reporting();
104
105 $code = <<<EOF
106 <?php
107
108 error_reporting($errorReporting);
109
110 require_once '$requirePath';
111
112 \$loader = new Symfony\Component\ClassLoader\ClassLoader();
113 \$loader->addPrefix('Symfony', '$symfonyPath');
114 \$loader->register();
115
116 \$kernel = unserialize('$kernel');
117 \$request = unserialize('$request');
118 EOF;
119
120
121 return $code.$this->getHandleScript();
122 }
123
124 protected function getHandleScript()
125 {
126 return <<<'EOF'
127 $response = $kernel->handle($request);
128
129 if ($kernel instanceof Symfony\Component\HttpKernel\TerminableInterface) {
130 $kernel->terminate($request, $response);
131 }
132
133 echo serialize($response);
134 EOF;
135
136 }
137
138 /**
139 * Converts the BrowserKit request to a HttpKernel request.
140 *
141 * @param DomRequest $request A DomRequest instance
142 *
143 * @return Request A Request instance
144 */
145 protected function filterRequest(DomRequest $request)
146 {
147 $httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent());
148
149 foreach ($this->filterFiles($httpRequest->files->all()) as $key => $value) {
150 $httpRequest->files->set($key, $value);
151 }
152
153 return $httpRequest;
154 }
155
156 /**
157 * Filters an array of files.
158 *
159 * This method created test instances of UploadedFile so that the move()
160 * method can be called on those instances.
161 *
162 * If the size of a file is greater than the allowed size (from php.ini) then
163 * an invalid UploadedFile is returned with an error set to UPLOAD_ERR_INI_SIZE.
164 *
165 * @see UploadedFile
166 *
167 * @param array $files An array of files
168 *
169 * @return array An array with all uploaded files marked as already moved
170 */
171 protected function filterFiles(array $files)
172 {
173 $filtered = array();
174 foreach ($files as $key => $value) {
175 if (is_array($value)) {
176 $filtered[$key] = $this->filterFiles($value);
177 } elseif ($value instanceof UploadedFile) {
178 if ($value->isValid() && $value->getSize() > UploadedFile::getMaxFilesize()) {
179 $filtered[$key] = new UploadedFile(
180 '',
181 $value->getClientOriginalName(),
182 $value->getClientMimeType(),
183 0,
184 UPLOAD_ERR_INI_SIZE,
185 true
186 );
187 } else {
188 $filtered[$key] = new UploadedFile(
189 $value->getPathname(),
190 $value->getClientOriginalName(),
191 $value->getClientMimeType(),
192 $value->getClientSize(),
193 $value->getError(),
194 true
195 );
196 }
197 }
198 }
199
200 return $filtered;
201 }
202
203 /**
204 * Converts the HttpKernel response to a BrowserKit response.
205 *
206 * @param Response $response A Response instance
207 *
208 * @return DomResponse A DomResponse instance
209 */
210 protected function filterResponse($response)
211 {
212 $headers = $response->headers->all();
213 if ($response->headers->getCookies()) {
214 $cookies = array();
215 foreach ($response->headers->getCookies() as $cookie) {
216 $cookies[] = new DomCookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
217 }
218 $headers['Set-Cookie'] = $cookies;
219 }
220
221 // this is needed to support StreamedResponse
222 ob_start();
223 $response->sendContent();
224 $content = ob_get_clean();
225
226 return new DomResponse($content, $response->getStatusCode(), $headers);
227 }
228 }
229