[ Index ] |
PHP Cross Reference of phpBB-3.2.11-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\EventListener; 13 14 use Symfony\Component\EventDispatcher\EventSubscriberInterface; 15 use Symfony\Component\HttpFoundation\Cookie; 16 use Symfony\Component\HttpFoundation\Session\SessionInterface; 17 use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 18 use Symfony\Component\HttpKernel\Event\GetResponseEvent; 19 use Symfony\Component\HttpKernel\KernelEvents; 20 21 /** 22 * TestSessionListener. 23 * 24 * Saves session in test environment. 25 * 26 * @author Bulat Shakirzyanov <mallluhuct@gmail.com> 27 * @author Fabien Potencier <fabien@symfony.com> 28 */ 29 abstract class TestSessionListener implements EventSubscriberInterface 30 { 31 public function onKernelRequest(GetResponseEvent $event) 32 { 33 if (!$event->isMasterRequest()) { 34 return; 35 } 36 37 // bootstrap the session 38 $session = $this->getSession(); 39 if (!$session) { 40 return; 41 } 42 43 $cookies = $event->getRequest()->cookies; 44 45 if ($cookies->has($session->getName())) { 46 $session->setId($cookies->get($session->getName())); 47 } 48 } 49 50 /** 51 * Checks if session was initialized and saves if current request is master 52 * Runs on 'kernel.response' in test environment. 53 */ 54 public function onKernelResponse(FilterResponseEvent $event) 55 { 56 if (!$event->isMasterRequest()) { 57 return; 58 } 59 60 $session = $event->getRequest()->getSession(); 61 if ($session && $session->isStarted()) { 62 $session->save(); 63 $params = session_get_cookie_params(); 64 $event->getResponse()->headers->setCookie(new Cookie($session->getName(), $session->getId(), 0 === $params['lifetime'] ? 0 : time() + $params['lifetime'], $params['path'], $params['domain'], $params['secure'], $params['httponly'])); 65 } 66 } 67 68 public static function getSubscribedEvents() 69 { 70 return array( 71 KernelEvents::REQUEST => array('onKernelRequest', 192), 72 KernelEvents::RESPONSE => array('onKernelResponse', -128), 73 ); 74 } 75 76 /** 77 * Gets the session object. 78 * 79 * @return SessionInterface|null A SessionInterface instance or null if no session is available 80 */ 81 abstract protected function getSession(); 82 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |