Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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

FragmentHandler.php

Zuletzt modifiziert: 01.05.2026, 11:26 - Dateigröße: 3.79 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\RequestStack;
 015  use Symfony\Component\HttpFoundation\Response;
 016  use Symfony\Component\HttpFoundation\StreamedResponse;
 017  use Symfony\Component\HttpKernel\Controller\ControllerReference;
 018   
 019  /**
 020   * Renders a URI that represents a resource fragment.
 021   *
 022   * This class handles the rendering of resource fragments that are included into
 023   * a main resource. The handling of the rendering is managed by specialized renderers.
 024   *
 025   * @author Fabien Potencier <fabien@symfony.com>
 026   *
 027   * @see FragmentRendererInterface
 028   */
 029  class FragmentHandler
 030  {
 031      private $debug;
 032      private $renderers = [];
 033      private $requestStack;
 034   
 035      /**
 036       * @param RequestStack                $requestStack The Request stack that controls the lifecycle of requests
 037       * @param FragmentRendererInterface[] $renderers    An array of FragmentRendererInterface instances
 038       * @param bool                        $debug        Whether the debug mode is enabled or not
 039       */
 040      public function __construct(RequestStack $requestStack, array $renderers = [], $debug = false)
 041      {
 042          $this->requestStack = $requestStack;
 043          foreach ($renderers as $renderer) {
 044              $this->addRenderer($renderer);
 045          }
 046          $this->debug = $debug;
 047      }
 048   
 049      /**
 050       * Adds a renderer.
 051       */
 052      public function addRenderer(FragmentRendererInterface $renderer)
 053      {
 054          $this->renderers[$renderer->getName()] = $renderer;
 055      }
 056   
 057      /**
 058       * Renders a URI and returns the Response content.
 059       *
 060       * Available options:
 061       *
 062       *  * ignore_errors: true to return an empty string in case of an error
 063       *
 064       * @param string|ControllerReference $uri      A URI as a string or a ControllerReference instance
 065       * @param string                     $renderer The renderer name
 066       * @param array                      $options  An array of options
 067       *
 068       * @return string|null The Response content or null when the Response is streamed
 069       *
 070       * @throws \InvalidArgumentException when the renderer does not exist
 071       * @throws \LogicException           when no master request is being handled
 072       */
 073      public function render($uri, $renderer = 'inline', array $options = [])
 074      {
 075          if (!isset($options['ignore_errors'])) {
 076              $options['ignore_errors'] = !$this->debug;
 077          }
 078   
 079          if (!isset($this->renderers[$renderer])) {
 080              throw new \InvalidArgumentException(sprintf('The "%s" renderer does not exist.', $renderer));
 081          }
 082   
 083          if (!$request = $this->requestStack->getCurrentRequest()) {
 084              throw new \LogicException('Rendering a fragment can only be done when handling a Request.');
 085          }
 086   
 087          return $this->deliver($this->renderers[$renderer]->render($uri, $request, $options));
 088      }
 089   
 090      /**
 091       * Delivers the Response as a string.
 092       *
 093       * When the Response is a StreamedResponse, the content is streamed immediately
 094       * instead of being returned.
 095       *
 096       * @return string|null The Response content or null when the Response is streamed
 097       *
 098       * @throws \RuntimeException when the Response is not successful
 099       */
 100      protected function deliver(Response $response)
 101      {
 102          if (!$response->isSuccessful()) {
 103              throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %d).', $this->requestStack->getCurrentRequest()->getUri(), $response->getStatusCode()));
 104          }
 105   
 106          if (!$response instanceof StreamedResponse) {
 107              return $response->getContent();
 108          }
 109   
 110          $response->sendContent();
 111   
 112          return null;
 113      }
 114  }
 115