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 |
InlineFragmentRenderer.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\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|null $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 overriden 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);
072 $reference->attributes = array_merge($attributes, $reference->attributes);
073 }
074
075 $subRequest = $this->createSubRequest($uri, $request);
076
077 // override Request attributes as they can be objects (which are not supported by the generated URI)
078 if (null !== $reference) {
079 $subRequest->attributes->add($reference->attributes);
080 }
081
082 $level = ob_get_level();
083 try {
084 return $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false);
085 } catch (\Exception $e) {
086 // we dispatch the exception event to trigger the logging
087 // the response that comes back is simply ignored
088 if (isset($options['ignore_errors']) && $options['ignore_errors'] && $this->dispatcher) {
089 $event = new GetResponseForExceptionEvent($this->kernel, $request, HttpKernelInterface::SUB_REQUEST, $e);
090
091 $this->dispatcher->dispatch(KernelEvents::EXCEPTION, $event);
092 }
093
094 // let's clean up the output buffers that were created by the sub-request
095 while (ob_get_level() > $level) {
096 ob_get_clean();
097 }
098
099 if (isset($options['alt'])) {
100 $alt = $options['alt'];
101 unset($options['alt']);
102
103 return $this->render($alt, $request, $options);
104 }
105
106 if (!isset($options['ignore_errors']) || !$options['ignore_errors']) {
107 throw $e;
108 }
109
110 return new Response();
111 }
112 }
113
114 protected function createSubRequest($uri, Request $request)
115 {
116 $cookies = $request->cookies->all();
117 $server = $request->server->all();
118
119 // Override the arguments to emulate a sub-request.
120 // Sub-request object will point to localhost as client ip and real client ip
121 // will be included into trusted header for client ip
122 try {
123 if ($trustedHeaderName = Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP)) {
124 $currentXForwardedFor = $request->headers->get($trustedHeaderName, '');
125
126 $server['HTTP_'.$trustedHeaderName] = ($currentXForwardedFor ? $currentXForwardedFor.', ' : '').$request->getClientIp();
127 }
128 } catch (\InvalidArgumentException $e) {
129 // Do nothing
130 }
131
132 $server['REMOTE_ADDR'] = '127.0.0.1';
133
134 $subRequest = $request::create($uri, 'get', array(), $cookies, array(), $server);
135 if ($request->headers->has('Surrogate-Capability')) {
136 $subRequest->headers->set('Surrogate-Capability', $request->headers->get('Surrogate-Capability'));
137 }
138
139 if ($session = $request->getSession()) {
140 $subRequest->setSession($session);
141 }
142
143 return $subRequest;
144 }
145
146 /**
147 * {@inheritdoc}
148 */
149 public function getName()
150 {
151 return 'inline';
152 }
153 }
154