Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/http-foundation/Session/Storage/MockFileSessionStorage.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
| author | Chris Cannam |
|---|---|
| date | Mon, 23 Apr 2018 09:46:53 +0100 |
| parents | 4c8ae668cc8c |
| children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
| 13:5fb285c0d0e3 | 14:1fec387a4317 |
|---|---|
| 22 * | 22 * |
| 23 * @author Drak <drak@zikula.org> | 23 * @author Drak <drak@zikula.org> |
| 24 */ | 24 */ |
| 25 class MockFileSessionStorage extends MockArraySessionStorage | 25 class MockFileSessionStorage extends MockArraySessionStorage |
| 26 { | 26 { |
| 27 /** | |
| 28 * @var string | |
| 29 */ | |
| 30 private $savePath; | 27 private $savePath; |
| 31 | 28 |
| 32 /** | 29 /** |
| 33 * Constructor. | |
| 34 * | |
| 35 * @param string $savePath Path of directory to save session files | 30 * @param string $savePath Path of directory to save session files |
| 36 * @param string $name Session name | 31 * @param string $name Session name |
| 37 * @param MetadataBag $metaBag MetadataBag instance | 32 * @param MetadataBag $metaBag MetadataBag instance |
| 38 */ | 33 */ |
| 39 public function __construct($savePath = null, $name = 'MOCKSESSID', MetadataBag $metaBag = null) | 34 public function __construct($savePath = null, $name = 'MOCKSESSID', MetadataBag $metaBag = null) |
| 94 { | 89 { |
| 95 if (!$this->started) { | 90 if (!$this->started) { |
| 96 throw new \RuntimeException('Trying to save a session that was not started yet or was already closed'); | 91 throw new \RuntimeException('Trying to save a session that was not started yet or was already closed'); |
| 97 } | 92 } |
| 98 | 93 |
| 99 file_put_contents($this->getFilePath(), serialize($this->data)); | 94 $data = $this->data; |
| 95 | |
| 96 foreach ($this->bags as $bag) { | |
| 97 if (empty($data[$key = $bag->getStorageKey()])) { | |
| 98 unset($data[$key]); | |
| 99 } | |
| 100 } | |
| 101 if (array($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 } | |
| 100 | 114 |
| 101 // this is needed for Silex, where the session object is re-used across requests | 115 // 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 | 116 // in functional tests. In Symfony, the container is rebooted, so we don't have |
| 103 // this issue | 117 // this issue |
| 104 $this->started = false; | 118 $this->started = false; |
