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

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

InlineFragmentRenderer.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 5.34 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\Fragment;
013   
014  use Symfony\Component\HttpFoundation\Request;
015  use Symfony\Component\HttpFoundation\Response;
016  use Symfony\Component\HttpKernel\HttpKernelInterface;
017  use Symfony\Component\HttpKernel\Controller\ControllerReference;
018  use Symfony\Component\HttpKernel\KernelEvents;
019  use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
020  use Symfony\Component\EventDispatcher\EventDispatcherInterface;
021   
022  /**
023   * Implements the inline rendering strategy where the Request is rendered by the current HTTP kernel.
024   *
025   * @author Fabien Potencier <fabien@symfony.com>
026   */
027  class InlineFragmentRenderer extends RoutableFragmentRenderer
028  {
029      private $kernel;
030      private $dispatcher;
031   
032      /**
033       * Constructor.
034       *
035       * @param HttpKernelInterface      $kernel     A HttpKernelInterface instance
036       * @param EventDispatcherInterface $dispatcher A EventDispatcherInterface instance
037       */
038      public function __construct(HttpKernelInterface $kernel, EventDispatcherInterface $dispatcher = null)
039      {
040          $this->kernel = $kernel;
041          $this->dispatcher = $dispatcher;
042      }
043   
044      /**
045       * {@inheritdoc}
046       *
047       * Additional available options:
048       *
049       *  * alt: an alternative URI to render in case of an error
050       */
051      public function render($uri, Request $request, array $options = array())
052      {
053          $reference = null;
054          if ($uri instanceof ControllerReference) {
055              $reference = $uri;
056   
057              // Remove attributes from the generated URI because if not, the Symfony
058              // routing system will use them to populate the Request attributes. We don't
059              // want that as we want to preserve objects (so we manually set Request attributes
060              // below instead)
061              $attributes = $reference->attributes;
062              $reference->attributes = array();
063   
064              // The request format and locale might have been overridden by the user
065              foreach (array('_format', '_locale') as $key) {
066                  if (isset($attributes[$key])) {
067                      $reference->attributes[$key] = $attributes[$key];
068                  }
069              }
070   
071              $uri = $this->generateFragmentUri($uri, $request, false, false);
072   
073              $reference->attributes = array_merge($attributes, $reference->attributes);
074          }
075   
076          $subRequest = $this->createSubRequest($uri, $request);
077   
078          // override Request attributes as they can be objects (which are not supported by the generated URI)
079          if (null !== $reference) {
080              $subRequest->attributes->add($reference->attributes);
081          }
082   
083          $level = ob_get_level();
084          try {
085              return $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false);
086          } catch (\Exception $e) {
087              // we dispatch the exception event to trigger the logging
088              // the response that comes back is simply ignored
089              if (isset($options['ignore_errors']) && $options['ignore_errors'] && $this->dispatcher) {
090                  $event = new GetResponseForExceptionEvent($this->kernel, $request, HttpKernelInterface::SUB_REQUEST, $e);
091   
092                  $this->dispatcher->dispatch(KernelEvents::EXCEPTION, $event);
093              }
094   
095              // let's clean up the output buffers that were created by the sub-request
096              Response::closeOutputBuffers($level, false);
097   
098              if (isset($options['alt'])) {
099                  $alt = $options['alt'];
100                  unset($options['alt']);
101   
102                  return $this->render($alt, $request, $options);
103              }
104   
105              if (!isset($options['ignore_errors']) || !$options['ignore_errors']) {
106                  throw $e;
107              }
108   
109              return new Response();
110          }
111      }
112   
113      protected function createSubRequest($uri, Request $request)
114      {
115          $cookies = $request->cookies->all();
116          $server = $request->server->all();
117   
118          // Override the arguments to emulate a sub-request.
119          // Sub-request object will point to localhost as client ip and real client ip
120          // will be included into trusted header for client ip
121          try {
122              if ($trustedHeaderName = Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP)) {
123                  $currentXForwardedFor = $request->headers->get($trustedHeaderName, '');
124   
125                  $server['HTTP_'.$trustedHeaderName] = ($currentXForwardedFor ? $currentXForwardedFor.', ' : '').$request->getClientIp();
126              }
127          } catch (\InvalidArgumentException $e) {
128              // Do nothing
129          }
130   
131          $server['REMOTE_ADDR'] = '127.0.0.1';
132          unset($server['HTTP_IF_MODIFIED_SINCE']);
133          unset($server['HTTP_IF_NONE_MATCH']);
134   
135          $subRequest = Request::create($uri, 'get', array(), $cookies, array(), $server);
136          if ($request->headers->has('Surrogate-Capability')) {
137              $subRequest->headers->set('Surrogate-Capability', $request->headers->get('Surrogate-Capability'));
138          }
139   
140          if ($session = $request->getSession()) {
141              $subRequest->setSession($session);
142          }
143   
144          return $subRequest;
145      }
146   
147      /**
148       * {@inheritdoc}
149       */
150      public function getName()
151      {
152          return 'inline';
153      }
154  }
155