ci4
46 строк · 1.1 Кб
1<?php
2
3declare(strict_types=1);
4
5/**
6* This file is part of CodeIgniter 4 framework.
7*
8* (c) CodeIgniter Foundation <admin@codeigniter.com>
9*
10* For the full copyright and license information, please view
11* the LICENSE file that was distributed with this source code.
12*/
13
14namespace CodeIgniter\Cache\FactoriesCache;
15
16final class FileVarExportHandler
17{
18private string $path = WRITEPATH . 'cache';
19
20/**
21* @param array|bool|float|int|object|string|null $val
22*/
23public function save(string $key, $val): void
24{
25$val = var_export($val, true);
26
27// Write to temp file first to ensure atomicity
28$tmp = $this->path . "/{$key}." . uniqid('', true) . '.tmp';
29file_put_contents($tmp, '<?php return ' . $val . ';', LOCK_EX);
30
31rename($tmp, $this->path . "/{$key}");
32}
33
34public function delete(string $key): void
35{
36@unlink($this->path . "/{$key}");
37}
38
39/**
40* @return array|bool|float|int|object|string|null
41*/
42public function get(string $key)
43{
44return @include $this->path . "/{$key}";
45}
46}
47