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

MockFileSessionStorage.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 3.81 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\HttpFoundation\Session\Storage;
013   
014  /**
015   * MockFileSessionStorage is used to mock sessions for
016   * functional testing when done in a single PHP process.
017   *
018   * No PHP session is actually started since a session can be initialized
019   * and shutdown only once per PHP execution cycle and this class does
020   * not pollute any session related globals, including session_*() functions
021   * or session.* PHP ini directives.
022   *
023   * @author Drak <drak@zikula.org>
024   */
025  class MockFileSessionStorage extends MockArraySessionStorage
026  {
027      private $savePath;
028   
029      /**
030       * @param string      $savePath Path of directory to save session files
031       * @param string      $name     Session name
032       * @param MetadataBag $metaBag  MetadataBag instance
033       */
034      public function __construct($savePath = null, $name = 'MOCKSESSID', MetadataBag $metaBag = null)
035      {
036          if (null === $savePath) {
037              $savePath = sys_get_temp_dir();
038          }
039   
040          if (!is_dir($savePath) && !@mkdir($savePath, 0777, true) && !is_dir($savePath)) {
041              throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s".', $savePath));
042          }
043   
044          $this->savePath = $savePath;
045   
046          parent::__construct($name, $metaBag);
047      }
048   
049      /**
050       * {@inheritdoc}
051       */
052      public function start()
053      {
054          if ($this->started) {
055              return true;
056          }
057   
058          if (!$this->id) {
059              $this->id = $this->generateId();
060          }
061   
062          $this->read();
063   
064          $this->started = true;
065   
066          return true;
067      }
068   
069      /**
070       * {@inheritdoc}
071       */
072      public function regenerate($destroy = false, $lifetime = null)
073      {
074          if (!$this->started) {
075              $this->start();
076          }
077   
078          if ($destroy) {
079              $this->destroy();
080          }
081   
082          return parent::regenerate($destroy, $lifetime);
083      }
084   
085      /**
086       * {@inheritdoc}
087       */
088      public function save()
089      {
090          if (!$this->started) {
091              throw new \RuntimeException('Trying to save a session that was not started yet or was already closed.');
092          }
093   
094          $data = $this->data;
095   
096          foreach ($this->bags as $bag) {
097              if (empty($data[$key = $bag->getStorageKey()])) {
098                  unset($data[$key]);
099              }
100          }
101          if ([$key = $this->metadataBag->getStorageKey()] === array_keys($data)) {
102              unset($data[$key]);
103          }
104   
105          try {
106              if ($data) {
107                  file_put_contents($this->getFilePath(), serialize($data));
108              } else {
109                  $this->destroy();
110              }
111          } finally {
112              $this->data = $data;
113          }
114   
115          // this is needed for Silex, where the session object is re-used across requests
116          // in functional tests. In Symfony, the container is rebooted, so we don't have
117          // this issue
118          $this->started = false;
119      }
120   
121      /**
122       * Deletes a session from persistent storage.
123       * Deliberately leaves session data in memory intact.
124       */
125      private function destroy()
126      {
127          if (is_file($this->getFilePath())) {
128              unlink($this->getFilePath());
129          }
130      }
131   
132      /**
133       * Calculate path to file.
134       *
135       * @return string File path
136       */
137      private function getFilePath()
138      {
139          return $this->savePath.'/'.$this->id.'.mocksess';
140      }
141   
142      /**
143       * Reads session from storage and loads session.
144       */
145      private function read()
146      {
147          $filePath = $this->getFilePath();
148          $this->data = is_readable($filePath) && is_file($filePath) ? unserialize(file_get_contents($filePath)) : [];
149   
150          $this->loadSession();
151      }
152  }
153