Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

AbstractTestSessionListener.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 3.11 KiB


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\EventListener;
013   
014  use Symfony\Component\EventDispatcher\EventSubscriberInterface;
015  use Symfony\Component\HttpFoundation\Cookie;
016  use Symfony\Component\HttpFoundation\Session\Session;
017  use Symfony\Component\HttpFoundation\Session\SessionInterface;
018  use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
019  use Symfony\Component\HttpKernel\Event\GetResponseEvent;
020  use Symfony\Component\HttpKernel\KernelEvents;
021   
022  /**
023   * TestSessionListener.
024   *
025   * Saves session in test environment.
026   *
027   * @author Bulat Shakirzyanov <mallluhuct@gmail.com>
028   * @author Fabien Potencier <fabien@symfony.com>
029   */
030  abstract class AbstractTestSessionListener implements EventSubscriberInterface
031  {
032      private $sessionId;
033   
034      public function onKernelRequest(GetResponseEvent $event)
035      {
036          if (!$event->isMasterRequest()) {
037              return;
038          }
039   
040          // bootstrap the session
041          $session = $this->getSession();
042          if (!$session) {
043              return;
044          }
045   
046          $cookies = $event->getRequest()->cookies;
047   
048          if ($cookies->has($session->getName())) {
049              $this->sessionId = $cookies->get($session->getName());
050              $session->setId($this->sessionId);
051          }
052      }
053   
054      /**
055       * Checks if session was initialized and saves if current request is master
056       * Runs on 'kernel.response' in test environment.
057       */
058      public function onKernelResponse(FilterResponseEvent $event)
059      {
060          if (!$event->isMasterRequest()) {
061              return;
062          }
063   
064          if (!$session = $event->getRequest()->getSession()) {
065              return;
066          }
067   
068          if ($wasStarted = $session->isStarted()) {
069              $session->save();
070          }
071   
072          if ($session instanceof Session ? !$session->isEmpty() || (null !== $this->sessionId && $session->getId() !== $this->sessionId) : $wasStarted) {
073              $params = session_get_cookie_params();
074   
075              foreach ($event->getResponse()->headers->getCookies() as $cookie) {
076                  if ($session->getName() === $cookie->getName() && $params['path'] === $cookie->getPath() && $params['domain'] == $cookie->getDomain()) {
077                      return;
078                  }
079              }
080   
081              $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']));
082              $this->sessionId = $session->getId();
083          }
084      }
085   
086      public static function getSubscribedEvents()
087      {
088          return [
089              KernelEvents::REQUEST => ['onKernelRequest', 192],
090              KernelEvents::RESPONSE => ['onKernelResponse', -128],
091          ];
092      }
093   
094      /**
095       * Gets the session object.
096       *
097       * @return SessionInterface|null A SessionInterface instance or null if no session is available
098       */
099      abstract protected function getSession();
100  }
101