Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
MockFileSessionStorage.php
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 /**
028 * @var string
029 */
030 private $savePath;
031
032 /**
033 * Constructor.
034 *
035 * @param string $savePath Path of directory to save session files
036 * @param string $name Session name
037 * @param MetadataBag $metaBag MetadataBag instance
038 */
039 public function __construct($savePath = null, $name = 'MOCKSESSID', MetadataBag $metaBag = null)
040 {
041 if (null === $savePath) {
042 $savePath = sys_get_temp_dir();
043 }
044
045 if (!is_dir($savePath) && !@mkdir($savePath, 0777, true) && !is_dir($savePath)) {
046 throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s"', $savePath));
047 }
048
049 $this->savePath = $savePath;
050
051 parent::__construct($name, $metaBag);
052 }
053
054 /**
055 * {@inheritdoc}
056 */
057 public function start()
058 {
059 if ($this->started) {
060 return true;
061 }
062
063 if (!$this->id) {
064 $this->id = $this->generateId();
065 }
066
067 $this->read();
068
069 $this->started = true;
070
071 return true;
072 }
073
074 /**
075 * {@inheritdoc}
076 */
077 public function regenerate($destroy = false, $lifetime = null)
078 {
079 if (!$this->started) {
080 $this->start();
081 }
082
083 if ($destroy) {
084 $this->destroy();
085 }
086
087 return parent::regenerate($destroy, $lifetime);
088 }
089
090 /**
091 * {@inheritdoc}
092 */
093 public function save()
094 {
095 if (!$this->started) {
096 throw new \RuntimeException('Trying to save a session that was not started yet or was already closed');
097 }
098
099 file_put_contents($this->getFilePath(), serialize($this->data));
100
101 // this is needed for Silex, where the session object is re-used across requests
102 // in functional tests. In Symfony, the container is rebooted, so we don't have
103 // this issue
104 $this->started = false;
105 }
106
107 /**
108 * Deletes a session from persistent storage.
109 * Deliberately leaves session data in memory intact.
110 */
111 private function destroy()
112 {
113 if (is_file($this->getFilePath())) {
114 unlink($this->getFilePath());
115 }
116 }
117
118 /**
119 * Calculate path to file.
120 *
121 * @return string File path
122 */
123 private function getFilePath()
124 {
125 return $this->savePath.'/'.$this->id.'.mocksess';
126 }
127
128 /**
129 * Reads session from storage and loads session.
130 */
131 private function read()
132 {
133 $filePath = $this->getFilePath();
134 $this->data = is_readable($filePath) && is_file($filePath) ? unserialize(file_get_contents($filePath)) : array();
135
136 $this->loadSession();
137 }
138 }
139