[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\HttpKernel\Fragment; 13 14 use Symfony\Component\HttpFoundation\Request; 15 use Symfony\Component\HttpFoundation\Response; 16 use Symfony\Component\HttpKernel\HttpKernelInterface; 17 use Symfony\Component\HttpKernel\Controller\ControllerReference; 18 use Symfony\Component\HttpKernel\KernelEvents; 19 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; 20 use Symfony\Component\EventDispatcher\EventDispatcherInterface; 21 22 /** 23 * Implements the inline rendering strategy where the Request is rendered by the current HTTP kernel. 24 * 25 * @author Fabien Potencier <fabien@symfony.com> 26 */ 27 class InlineFragmentRenderer extends RoutableFragmentRenderer 28 { 29 private $kernel; 30 private $dispatcher; 31 32 /** 33 * Constructor. 34 * 35 * @param HttpKernelInterface $kernel A HttpKernelInterface instance 36 * @param EventDispatcherInterface|null $dispatcher A EventDispatcherInterface instance 37 */ 38 public function __construct(HttpKernelInterface $kernel, EventDispatcherInterface $dispatcher = null) 39 { 40 $this->kernel = $kernel; 41 $this->dispatcher = $dispatcher; 42 } 43 44 /** 45 * {@inheritdoc} 46 * 47 * Additional available options: 48 * 49 * * alt: an alternative URI to render in case of an error 50 */ 51 public function render($uri, Request $request, array $options = array()) 52 { 53 $reference = null; 54 if ($uri instanceof ControllerReference) { 55 $reference = $uri; 56 57 // Remove attributes from the generated URI because if not, the Symfony 58 // routing system will use them to populate the Request attributes. We don't 59 // want that as we want to preserve objects (so we manually set Request attributes 60 // below instead) 61 $attributes = $reference->attributes; 62 $reference->attributes = array(); 63 64 // The request format and locale might have been overriden by the user 65 foreach (array('_format', '_locale') as $key) { 66 if (isset($attributes[$key])) { 67 $reference->attributes[$key] = $attributes[$key]; 68 } 69 } 70 71 $uri = $this->generateFragmentUri($uri, $request); 72 $reference->attributes = array_merge($attributes, $reference->attributes); 73 } 74 75 $subRequest = $this->createSubRequest($uri, $request); 76 77 // override Request attributes as they can be objects (which are not supported by the generated URI) 78 if (null !== $reference) { 79 $subRequest->attributes->add($reference->attributes); 80 } 81 82 $level = ob_get_level(); 83 try { 84 return $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false); 85 } catch (\Exception $e) { 86 // we dispatch the exception event to trigger the logging 87 // the response that comes back is simply ignored 88 if (isset($options['ignore_errors']) && $options['ignore_errors'] && $this->dispatcher) { 89 $event = new GetResponseForExceptionEvent($this->kernel, $request, HttpKernelInterface::SUB_REQUEST, $e); 90 91 $this->dispatcher->dispatch(KernelEvents::EXCEPTION, $event); 92 } 93 94 // let's clean up the output buffers that were created by the sub-request 95 while (ob_get_level() > $level) { 96 ob_get_clean(); 97 } 98 99 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 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |