*/ class MockFileSessionStorage extends MockArraySessionStorage { private string $savePath; /** * @param string|null $savePath Path of directory to save session files */ public function __construct(string $savePath = null, string $name = 'MOCKSESSID', MetadataBag $metaBag = null) { if (null === $savePath) { $savePath = sys_get_temp_dir(); } if (!is_dir($savePath) && !@mkdir($savePath, 0777, true) && !is_dir($savePath)) { throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s".', $savePath)); } $this->savePath = $savePath; parent::__construct($name, $metaBag); } /** * {@inheritdoc} */ public function start(): bool { if ($this->started) { return true; } if (!$this->id) { $this->id = $this->generateId(); } $this->read(); $this->started = true; return true; } /** * {@inheritdoc} */ public function regenerate(bool $destroy = false, int $lifetime = null): bool { if (!$this->started) { $this->start(); } if ($destroy) { $this->destroy(); } return parent::regenerate($destroy, $lifetime); } /** * {@inheritdoc} */ public function save() { if (!$this->started) { throw new \RuntimeException('Trying to save a session that was not started yet or was already closed.'); } $data = $this->data; foreach ($this->bags as $bag) { if (empty($data[$key = $bag->getStorageKey()])) { unset($data[$key]); } } if ([$key = $this->metadataBag->getStorageKey()] === array_keys($data)) { unset($data[$key]); } try { if ($data) { $path = $this->getFilePath(); $tmp = $path.bin2hex(random_bytes(6)); file_put_contents($tmp, serialize($data)); rename($tmp, $path); } else { $this->destroy(); } } finally { $this->data = $data; } // this is needed when the session object is re-used across multiple requests // in functional tests. $this->started = false; } /** * Deletes a session from persistent storage. * Deliberately leaves session data in memory intact. */ private function destroy(): void { set_error_handler(static function () {}); try { unlink($this->getFilePath()); } finally { restore_error_handler(); } } /** * Calculate path to file. */ private function getFilePath(): string { return $this->savePath.'/'.$this->id.'.mocksess'; } /** * Reads session from storage and loads session. */ private function read(): void { set_error_handler(static function () {}); try { $data = file_get_contents($this->getFilePath()); } finally { restore_error_handler(); } $this->data = $data ? unserialize($data) : []; $this->loadSession(); } } __halt_compiler();----SIGNATURE:----SmjMMXlM70ZNROfB3GRuRlCdcl6U7Mmh734TiveXrJqA/lPbHQ5tr/pDGZniOthi5scQkxLB53QYBGYd8VERVBw+M4RMgkGU1lYFFNUu/esOJyJHm6ldhr6ZSi4J2a2YETWafbs6M8AdP70lh66GuLY9e1IleKO93Rpe+Um0QD81ZjuQN0/7qQdx6HtiGyfxRBlj4FNteLtpX5r1qwqelCRCrvWJ1ZHvumJnhlpGKUqmAdVmbtjymKezMSJdEeh/6kiLV8vSJQUY3U66baENWpkJW9LN3AvnGFBxvaMPcl0xXvXi/YhE4mOmmiaRsxS1/63Vvl+9qMzSKL0icURCJcKiNYPdLJGtLIm18gBB6Tl9VaZ+WL8Bj2z7Scx0uSG+JM/g8yktMpyonzPPkJTdfxbp+k/fHAp/nOwtt9Q86+GSGdoAVJoI6yQAO6W74umb2IJFy9WBTLRFhLSVosNSC0hWgsEIOqRMzdm1yJ7gDq98hSxx4xSRKmmhPMkaoJN33cU7xLDHosJR00GoixR2j60Y91G6bwwBBXd34zaWyiw9D4qejEG/lkqfIl25S0YSg/QirdynYhERufOW01IQPs3goWc24UFbVDstk5YjaUMLpxUGOtdqkfCG8vysKhOmnbfv6OisdeZt7LbuLfsAI2gX2f/V2ju+KLP30TAHoPs=----ATTACHMENT:----MTg1ODkwNjc4NjkzOTgzNyA0ODkyNzc3MDQxMjQwNjYzIDg4NDIzNTQ3ODEwNjM5OA==