Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

Client.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 6.71 KiB


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