[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <[email protected]> 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\WebLink\EventListener; 13 14 use Psr\Link\LinkProviderInterface; 15 use Symfony\Component\EventDispatcher\EventSubscriberInterface; 16 use Symfony\Component\HttpKernel\Event\ResponseEvent; 17 use Symfony\Component\HttpKernel\KernelEvents; 18 use Symfony\Component\WebLink\HttpHeaderSerializer; 19 20 // Help opcache.preload discover always-needed symbols 21 class_exists(HttpHeaderSerializer::class); 22 23 /** 24 * Adds the Link HTTP header to the response. 25 * 26 * @author Kévin Dunglas <[email protected]> 27 * 28 * @final 29 */ 30 class AddLinkHeaderListener implements EventSubscriberInterface 31 { 32 private $serializer; 33 34 public function __construct() 35 { 36 $this->serializer = new HttpHeaderSerializer(); 37 } 38 39 public function onKernelResponse(ResponseEvent $event) 40 { 41 if (!$event->isMainRequest()) { 42 return; 43 } 44 45 $linkProvider = $event->getRequest()->attributes->get('_links'); 46 if (!$linkProvider instanceof LinkProviderInterface || !$links = $linkProvider->getLinks()) { 47 return; 48 } 49 50 $event->getResponse()->headers->set('Link', $this->serializer->serialize($links), false); 51 } 52 53 /** 54 * {@inheritdoc} 55 */ 56 public static function getSubscribedEvents(): array 57 { 58 return [KernelEvents::RESPONSE => 'onKernelResponse']; 59 } 60 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |