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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
FragmentHandler.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\Fragment;
013
014 use Symfony\Component\HttpFoundation\Request;
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 $request;
034
035 /**
036 * Constructor.
037 *
038 * @param FragmentRendererInterface[] $renderers An array of FragmentRendererInterface instances
039 * @param bool $debug Whether the debug mode is enabled or not
040 */
041 public function __construct(array $renderers = array(), $debug = false)
042 {
043 $this->renderers = array();
044 foreach ($renderers as $renderer) {
045 $this->addRenderer($renderer);
046 }
047 $this->debug = $debug;
048 }
049
050 /**
051 * Adds a renderer.
052 *
053 * @param FragmentRendererInterface $renderer A FragmentRendererInterface instance
054 */
055 public function addRenderer(FragmentRendererInterface $renderer)
056 {
057 $this->renderers[$renderer->getName()] = $renderer;
058 }
059
060 /**
061 * Sets the current Request.
062 *
063 * @param Request $request The current Request
064 */
065 public function setRequest(Request $request = null)
066 {
067 $this->request = $request;
068 }
069
070 /**
071 * Renders a URI and returns the Response content.
072 *
073 * Available options:
074 *
075 * * ignore_errors: true to return an empty string in case of an error
076 *
077 * @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
078 * @param string $renderer The renderer name
079 * @param array $options An array of options
080 *
081 * @return string|null The Response content or null when the Response is streamed
082 *
083 * @throws \InvalidArgumentException when the renderer does not exist
084 * @throws \LogicException when no master request is being handled
085 * @throws \RuntimeException when the Response is not successful
086 */
087 public function render($uri, $renderer = 'inline', array $options = array())
088 {
089 if (!isset($options['ignore_errors'])) {
090 $options['ignore_errors'] = !$this->debug;
091 }
092
093 if (!isset($this->renderers[$renderer])) {
094 throw new \InvalidArgumentException(sprintf('The "%s" renderer does not exist.', $renderer));
095 }
096
097 if (null === $this->request) {
098 throw new \LogicException('Rendering a fragment can only be done when handling a master Request.');
099 }
100
101 return $this->deliver($this->renderers[$renderer]->render($uri, $this->request, $options));
102 }
103
104 /**
105 * Delivers the Response as a string.
106 *
107 * When the Response is a StreamedResponse, the content is streamed immediately
108 * instead of being returned.
109 *
110 * @param Response $response A Response instance
111 *
112 * @return string|null The Response content or null when the Response is streamed
113 *
114 * @throws \RuntimeException when the Response is not successful
115 */
116 protected function deliver(Response $response)
117 {
118 if (!$response->isSuccessful()) {
119 throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $this->request->getUri(), $response->getStatusCode()));
120 }
121
122 if (!$response instanceof StreamedResponse) {
123 return $response->getContent();
124 }
125
126 $response->sendContent();
127 }
128 }
129