diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 5a39324e..8af71c68 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.1 coverage: none - run: composer install --no-progress --prefer-dist diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 15b406ee..c01fd025 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['8.0', '8.1', '8.2', '8.3', '8.4'] + php: ['8.1', '8.2', '8.3', '8.4'] fail-fast: false @@ -37,7 +37,7 @@ jobs: - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.1 coverage: none - run: composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable @@ -52,7 +52,7 @@ jobs: - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.1 coverage: none - run: composer install --no-progress --prefer-dist diff --git a/composer.json b/composer.json index d4782dac..890a3591 100644 --- a/composer.json +++ b/composer.json @@ -15,25 +15,28 @@ } ], "require": { - "php": "8.0 - 8.4", + "php": "8.1 - 8.4", "nette/utils": "^4.0" }, "require-dev": { "nette/tester": "^2.4", "nette/di": "^3.1 || ^4.0", - "latte/latte": "^2.11 || ^3.0.12", + "latte/latte": "^3.0.12", "tracy/tracy": "^2.9", - "phpstan/phpstan": "^1.0", - "psr/simple-cache": "^2.0 || ^3.0" + "psr/simple-cache": "^2.0 || ^3.0", + "phpstan/phpstan-nette": "^2.0@stable" }, "conflict": { - "latte/latte": ">=3.0.0 <3.0.12" + "latte/latte": "<3.0.12" }, "suggest": { "ext-pdo_sqlite": "to use SQLiteStorage or SQLiteJournal" }, "autoload": { - "classmap": ["src/"] + "classmap": ["src/"], + "psr-4": { + "Nette\\": "src" + } }, "minimum-stability": "dev", "scripts": { @@ -42,7 +45,7 @@ }, "extra": { "branch-alias": { - "dev-master": "3.3-dev" + "dev-master": "4.0-dev" } } } diff --git a/readme.md b/readme.md index 77a0953e..bb2ccd08 100644 --- a/readme.md +++ b/readme.md @@ -33,7 +33,7 @@ Installation composer require nette/caching ``` -It requires PHP version 8.0 and supports PHP up to 8.4. +It requires PHP version 8.1 and supports PHP up to 8.4. Basic Usage diff --git a/src/Bridges/CacheDI/CacheExtension.php b/src/Bridges/CacheDI/CacheExtension.php index da6b1f89..5d1ff9d2 100644 --- a/src/Bridges/CacheDI/CacheExtension.php +++ b/src/Bridges/CacheDI/CacheExtension.php @@ -45,13 +45,5 @@ public function loadConfiguration(): void $builder->addDefinition($this->prefix('storage')) ->setType(Nette\Caching\Storage::class) ->setFactory(Nette\Caching\Storages\FileStorage::class, [$this->tempDir]); - - if ($this->name === 'cache') { - if (extension_loaded('pdo_sqlite')) { - $builder->addAlias('nette.cacheJournal', $this->prefix('journal')); - } - - $builder->addAlias('cacheStorage', $this->prefix('storage')); - } } } diff --git a/src/Bridges/CacheLatte/CacheMacro.php b/src/Bridges/CacheLatte/CacheMacro.php deleted file mode 100644 index d6aeb5db..00000000 --- a/src/Bridges/CacheLatte/CacheMacro.php +++ /dev/null @@ -1,168 +0,0 @@ -used = false; - } - - - /** - * Finishes template parsing. - * @return array(prolog, epilog) - */ - public function finalize() - { - if ($this->used) { - return ['Nette\Bridges\CacheLatte\CacheMacro::initRuntime($this);']; - } - } - - - /** - * New node is found. - * @return bool - */ - public function nodeOpened(Latte\MacroNode $node) - { - if ($node->modifiers) { - throw new Latte\CompileException('Modifiers are not allowed in ' . $node->getNotation()); - } - - $this->used = true; - $node->empty = false; - $node->openingCode = Latte\PhpWriter::using($node) - ->write( - 'global->cacheStorage, %var, $this->global->cacheStack, %node.array?)) /* line %var */ try { ?>', - Nette\Utils\Random::generate(), - $node->startLine, - ); - } - - - /** - * Node is closed. - * @return void - */ - public function nodeClosed(Latte\MacroNode $node) - { - $node->closingCode = Latte\PhpWriter::using($node) - ->write( - 'global->cacheStack, %node.array?) /* line %var */; - } catch (\Throwable $ʟ_e) { - Nette\Bridges\CacheLatte\CacheMacro::rollback($this->global->cacheStack); throw $ʟ_e; - } ?>', - $node->startLine, - ); - } - - - /********************* run-time helpers ****************d*g**/ - - - public static function initRuntime(Latte\Runtime\Template $template): void - { - if (!empty($template->global->cacheStack)) { - $file = (new \ReflectionClass($template))->getFileName(); - if (@is_file($file)) { // @ - may trigger error - end($template->global->cacheStack)->dependencies[Cache::Files][] = $file; - } - } - } - - - /** - * Starts the output cache. Returns Nette\Caching\OutputHelper object if buffering was started. - */ - public static function createCache( - Nette\Caching\Storage $cacheStorage, - string $key, - ?array &$parents, - ?array $args = null, - ): Nette\Caching\OutputHelper|\stdClass|null - { - if ($args) { - if (array_key_exists('if', $args) && !$args['if']) { - return $parents[] = new \stdClass; - } - - $key = array_merge([$key], array_intersect_key($args, range(0, count($args)))); - } - - if ($parents) { - end($parents)->dependencies[Cache::Items][] = $key; - } - - $cache = new Cache($cacheStorage, 'Nette.Templating.Cache'); - if ($helper = $cache->capture($key)) { - $parents[] = $helper; - } - - return $helper; - } - - - /** - * Ends the output cache. - * @param Nette\Caching\OutputHelper[] $parents - */ - public static function endCache(array &$parents, ?array $args = null): void - { - $helper = array_pop($parents); - if (!$helper instanceof Nette\Caching\OutputHelper) { - return; - } - - if (isset($args['dependencies'])) { - $args += $args['dependencies'](); - } - - if (isset($args['expire'])) { - $args['expiration'] = $args['expire']; // back compatibility - } - - $helper->dependencies[Cache::Tags] = $args['tags'] ?? null; - $helper->dependencies[Cache::Expire] = $args['expiration'] ?? '+ 7 days'; - $helper->end(); - } - - - /** - * @param Nette\Caching\OutputHelper[] $parents - */ - public static function rollback(array &$parents): void - { - $helper = array_pop($parents); - if ($helper instanceof Nette\Caching\OutputHelper) { - $helper->rollback(); - } - } -} diff --git a/src/Bridges/CacheLatte/Runtime.php b/src/Bridges/CacheLatte/Runtime.php index d0546699..8b3c8cb6 100644 --- a/src/Bridges/CacheLatte/Runtime.php +++ b/src/Bridges/CacheLatte/Runtime.php @@ -13,6 +13,7 @@ use Nette; use Nette\Caching\Cache; use Nette\Caching\OutputHelper; +use function array_intersect_key, array_key_exists, array_merge, array_pop, count, end, is_file, range; /** diff --git a/src/Caching/Cache.php b/src/Caching/Cache.php index 4f4df05b..e7f42d38 100644 --- a/src/Caching/Cache.php +++ b/src/Caching/Cache.php @@ -10,6 +10,7 @@ namespace Nette\Caching; use Nette; +use function array_keys, array_map, array_shift, array_slice, array_unique, array_values, constant, count, defined, filemtime, func_get_args, get_class, is_array, is_object, is_scalar, md5, serialize, substr, time; /** @@ -64,9 +65,7 @@ class Cache public const ALL = self::All; /** @internal */ - public const - NamespaceSeparator = "\x00", - NAMESPACE_SEPARATOR = self::NamespaceSeparator; + public const NamespaceSeparator = "\x00"; private Storage $storage; private string $namespace; @@ -385,6 +384,7 @@ public function capture(mixed $key): ?OutputHelper */ public function start($key): ?OutputHelper { + trigger_error(__METHOD__ . '() was renamed to capture()', E_USER_DEPRECATED); return $this->capture($key); } @@ -394,7 +394,7 @@ public function start($key): ?OutputHelper */ protected function generateKey($key): string { - return $this->namespace . md5(is_scalar($key) ? (string) $key : serialize($key)); + return $this->namespace . hash('xxh128', is_scalar($key) ? (string) $key : serialize($key)); } diff --git a/src/Caching/Storage.php b/src/Caching/Storage.php index e9565d8b..16b80942 100644 --- a/src/Caching/Storage.php +++ b/src/Caching/Storage.php @@ -17,9 +17,8 @@ interface Storage { /** * Read from cache. - * @return mixed */ - function read(string $key); + function read(string $key): mixed; /** * Prevents item reading and writing. Lock is released by write() or remove(). diff --git a/src/Caching/Storages/FileStorage.php b/src/Caching/Storages/FileStorage.php index f0400135..19eff36a 100644 --- a/src/Caching/Storages/FileStorage.php +++ b/src/Caching/Storages/FileStorage.php @@ -11,6 +11,8 @@ use Nette; use Nette\Caching\Cache; +use function dirname, fclose, filemtime, flock, fopen, fseek, ftruncate, fwrite, is_dir, is_string, microtime, mkdir, mt_getrandmax, mt_rand, rmdir, serialize, str_pad, str_repeat, stream_get_contents, strlen, strrpos, substr_replace, time, touch, unlink, unserialize, urlencode; +use const LOCK_EX, LOCK_SH, LOCK_UN, STR_PAD_LEFT; /** @@ -32,7 +34,7 @@ class FileStorage implements Nette\Caching\Storage /** @internal cache file structure: meta-struct size + serialized meta-struct + data */ private const MetaHeaderLen = 6, - // meta structure: array of + // meta structure: array of MetaTime = 'time', // timestamp MetaSerialized = 'serialized', // is content serialized? MetaExpire = 'expire', // expiration timestamp diff --git a/src/Caching/Storages/MemcachedStorage.php b/src/Caching/Storages/MemcachedStorage.php index 6fe9ce43..b9430f11 100644 --- a/src/Caching/Storages/MemcachedStorage.php +++ b/src/Caching/Storages/MemcachedStorage.php @@ -11,6 +11,7 @@ use Nette; use Nette\Caching\Cache; +use function array_combine, array_map, extension_loaded, time, urlencode; /** @@ -105,7 +106,7 @@ public function bulkRead(array $keys): array { $prefixedKeys = array_map(fn($key) => urlencode($this->prefix . $key), $keys); $keys = array_combine($prefixedKeys, $keys); - $metas = $this->memcached->getMulti($prefixedKeys); + $metas = $this->memcached->getMulti($prefixedKeys) ?: []; $result = []; $deleteKeys = []; foreach ($metas as $prefixedKey => $meta) { diff --git a/src/Caching/Storages/SQLiteJournal.php b/src/Caching/Storages/SQLiteJournal.php index 26747834..4de19120 100644 --- a/src/Caching/Storages/SQLiteJournal.php +++ b/src/Caching/Storages/SQLiteJournal.php @@ -11,6 +11,7 @@ use Nette; use Nette\Caching\Cache; +use function count, extension_loaded, implode, is_file, str_repeat, touch; /** @@ -40,7 +41,6 @@ private function open(): void } $this->pdo = new \PDO('sqlite:' . $this->path); - $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $this->pdo->exec(' PRAGMA foreign_keys = OFF; PRAGMA journal_mode = WAL; diff --git a/src/Caching/Storages/SQLiteStorage.php b/src/Caching/Storages/SQLiteStorage.php index 5301a4e7..35f01138 100644 --- a/src/Caching/Storages/SQLiteStorage.php +++ b/src/Caching/Storages/SQLiteStorage.php @@ -11,6 +11,7 @@ use Nette; use Nette\Caching\Cache; +use function array_merge, count, is_file, serialize, str_repeat, time, touch, unserialize; /** @@ -20,6 +21,8 @@ class SQLiteStorage implements Nette\Caching\Storage, Nette\Caching\BulkReader { private \PDO $pdo; + /** probability that the clean() routine is started */ + public static float $gcProbability = 0.001; public function __construct(string $path) { @@ -28,7 +31,6 @@ public function __construct(string $path) } $this->pdo = new \PDO('sqlite:' . $path); - $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $this->pdo->exec(' PRAGMA foreign_keys = ON; CREATE TABLE IF NOT EXISTS cache ( @@ -46,6 +48,12 @@ public function __construct(string $path) CREATE INDEX IF NOT EXISTS tags_tag ON tags(tag); PRAGMA synchronous = OFF; '); + + // should we run the clean function to remove expired cached items? + if (mt_rand() / mt_getrandmax() < static::$gcProbability) { + $this->clean([]); + } + } diff --git a/tests/Bridges.DI/CacheExtension.phpt b/tests/Bridges.DI/CacheExtension.phpt index cc735739..9f4c4703 100644 --- a/tests/Bridges.DI/CacheExtension.phpt +++ b/tests/Bridges.DI/CacheExtension.phpt @@ -28,8 +28,4 @@ test('', function () { $storage = $container->getService('cache.storage'); Assert::type(Nette\Caching\Storages\FileStorage::class, $storage); - - // aliases - Assert::same($journal, $container->getService('nette.cacheJournal')); - Assert::same($storage, $container->getService('cacheStorage')); }); diff --git a/tests/Bridges.Latte2/CacheMacro.cache.phpt b/tests/Bridges.Latte2/CacheMacro.cache.phpt deleted file mode 100644 index 8dfa099f..00000000 --- a/tests/Bridges.Latte2/CacheMacro.cache.phpt +++ /dev/null @@ -1,48 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - - -$latte = new Latte\Engine; -$latte->setTempDirectory(getTempDir()); -$latte->addMacro('cache', new CacheMacro($latte->getCompiler())); -$latte->addProvider('cacheStorage', new Nette\Caching\Storages\MemoryStorage); - -$params['title'] = 'Hello'; -$params['id'] = 456; - -Assert::matchFile( - __DIR__ . '/expected/CacheMacro.cache.php', - $latte->compile(__DIR__ . '/templates/cache.latte'), -); -Assert::matchFile( - __DIR__ . '/expected/CacheMacro.cache.html', - $latte->renderToString( - __DIR__ . '/templates/cache.latte', - $params, - ), -); -Assert::matchFile( - __DIR__ . '/expected/CacheMacro.cache.html', - $latte->renderToString( - __DIR__ . '/templates/cache.latte', - $params, - ), -); -Assert::matchFile( - __DIR__ . '/expected/CacheMacro.cache.inc.php', - file_get_contents($latte->getCacheFile(__DIR__ . strtr('/templates/include.cache.latte', '/', DIRECTORY_SEPARATOR))), -); diff --git a/tests/Bridges.Latte2/CacheMacro.createCache.phpt b/tests/Bridges.Latte2/CacheMacro.createCache.phpt deleted file mode 100644 index 5cd26089..00000000 --- a/tests/Bridges.Latte2/CacheMacro.createCache.phpt +++ /dev/null @@ -1,49 +0,0 @@ -')) { - Tester\Environment::skip('Test for Latte 2'); -} - - -test('', function () { - $parents = []; - $dp = [Cache::Tags => ['rum', 'cola']]; - $outputHelper = CacheMacro::createCache(new DevNullStorage, 'test', $parents); - Assert::type(Nette\Caching\OutputHelper::class, $outputHelper); - CacheMacro::endCache($parents, $dp); - Assert::same($dp + [Cache::Expire => '+ 7 days'], $outputHelper->dependencies); -}); - -test('', function () { - $parents = []; - $dp = [Cache::Tags => ['rum', 'cola']]; - $dpFallback = fn() => $dp; - $outputHelper = CacheMacro::createCache(new DevNullStorage, 'test', $parents); - CacheMacro::endCache($parents, ['dependencies' => $dpFallback]); - Assert::same($dp + [Cache::Expire => '+ 7 days'], $outputHelper->dependencies); -}); - -test('', function () { - $parents = []; - $dp = [ - Cache::Tags => ['rum', 'cola'], - Cache::Expire => '+ 1 days', - ]; - $dpFallback = fn() => $dp; - $outputHelper = CacheMacro::createCache(new DevNullStorage, 'test', $parents); - CacheMacro::endCache($parents, ['dependencies' => $dpFallback]); - Assert::same($dp, $outputHelper->dependencies); -}); diff --git a/tests/Bridges.Latte2/expected/CacheMacro.cache.html b/tests/Bridges.Latte2/expected/CacheMacro.cache.html deleted file mode 100644 index 0fe8eebc..00000000 --- a/tests/Bridges.Latte2/expected/CacheMacro.cache.html +++ /dev/null @@ -1,8 +0,0 @@ -Noncached content - - -
Included file (11)
- - hello diff --git a/tests/Bridges.Latte2/expected/CacheMacro.cache.inc.php b/tests/Bridges.Latte2/expected/CacheMacro.cache.inc.php deleted file mode 100644 index af95b58b..00000000 --- a/tests/Bridges.Latte2/expected/CacheMacro.cache.inc.php +++ /dev/null @@ -1,12 +0,0 @@ -global->cacheStorage, '%[\w]+%', $this->global->cacheStack)) /* line %d% */ try { - echo ' '; - echo LR\Filters::escapeHtmlText(($this->filters->lower)($title)) /* line %d% */; - echo "\n"; - Nette\Bridges\CacheLatte\CacheMacro::endCache($this->global->cacheStack) /* line %d% */; - } catch (\Throwable $ʟ_e) { - Nette\Bridges\CacheLatte\CacheMacro::rollback($this->global->cacheStack); - throw $ʟ_e; - } -%A% diff --git a/tests/Bridges.Latte2/expected/CacheMacro.cache.php b/tests/Bridges.Latte2/expected/CacheMacro.cache.php deleted file mode 100644 index 491297ec..00000000 --- a/tests/Bridges.Latte2/expected/CacheMacro.cache.php +++ /dev/null @@ -1,28 +0,0 @@ -global->cacheStorage, '%[\w]+%', $this->global->cacheStack, [$id, 'tags' => 'mytag'])) /* line %d% */ try { - echo ' -Included file ({$localvar})
- -{cache} - {$title|lower} -{/cache} diff --git a/tests/Bridges.Latte3/Runtime.phpt b/tests/Bridges.Latte3/Runtime.phpt index 83a5121b..2360125e 100644 --- a/tests/Bridges.Latte3/Runtime.phpt +++ b/tests/Bridges.Latte3/Runtime.phpt @@ -9,10 +9,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - test('', function () { $runtime = new Runtime(new DevNullStorage); diff --git a/tests/Bridges.Latte3/{cache}.phpt b/tests/Bridges.Latte3/{cache}.phpt index e275b259..cb5ea876 100644 --- a/tests/Bridges.Latte3/{cache}.phpt +++ b/tests/Bridges.Latte3/{cache}.phpt @@ -11,10 +11,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - $latte = new Latte\Engine; $latte->setTempDirectory(getTempDir()); diff --git a/tests/Caching/Cache.php b/tests/Caching/Cache.php index c5e14368..47750ec3 100644 --- a/tests/Caching/Cache.php +++ b/tests/Caching/Cache.php @@ -75,7 +75,6 @@ public function bulkRead(array $keys): array public function bulkRemove(array $keys): void { - } diff --git a/tests/Storages/SQLiteJournal.permissions.phpt b/tests/Storages/SQLiteJournal.permissions.phpt index 396f6eb1..03f92c59 100644 --- a/tests/Storages/SQLiteJournal.permissions.phpt +++ b/tests/Storages/SQLiteJournal.permissions.phpt @@ -26,7 +26,7 @@ test('', function () { umask(0); (new SQLiteJournal($file))->write('foo', []); - Assert::same(0666, fileperms($file) & 0777); + Assert::same(0o666, fileperms($file) & 0o777); }); @@ -34,8 +34,8 @@ test('', function () { $file = getTempDir() . '/sqlitejournal.permissions.2.sqlite'; Assert::false(file_exists($file)); - umask(0077); + umask(0o077); (new SQLiteJournal($file))->write('foo', []); - Assert::same(0600, fileperms($file) & 0777); + Assert::same(0o600, fileperms($file) & 0o777); }); diff --git a/tests/Storages/SQLiteStorage.clean.phpt b/tests/Storages/SQLiteStorage.clean.phpt new file mode 100644 index 00000000..d0a440d6 --- /dev/null +++ b/tests/Storages/SQLiteStorage.clean.phpt @@ -0,0 +1,81 @@ +save($key, 'rulez', [ + Cache::Expire => time() + 1 +]); + +// there should be one entry in the cache +Assert::same(1, countStorageEntries($storage), 'Test cache entry should be saved'); + +// wait until the item expires +sleep(2); + +// expired item should still be present in the database +Assert::same(1, countStorageEntries($storage), 'Expired item should still be in DB prior to cleanup'); + +// PHASE 2 + +// Now we will reload the storage object on the same DB file, with garbage collection probability set to 1 (100%) +SQLiteStorage::$gcProbability = 1; + +// The storage constructor should run the clean() function. +$fresh_storage = new SQLiteStorage($db_file); + +// cache DB should now be empty (zero rows) +Assert::same(0, countStorageEntries($fresh_storage), 'Expired item should be cleaned up'); + +// ok, all done + +// clean up our test file +if (file_exists($db_file) && !unlink($db_file)) { + trigger_error("Failed to clean up test database: $db_file", E_USER_WARNING); +} + + +function countStorageEntries(SQLiteStorage $storage): int { + + // because we are checking EXPIRED cache entries, we need to access the SQLite file directly, rather than use the standard SqliteStorage methods + try { + + // we use Reflection to access the private 'pdo' property of the SQLiteStorage object + $reflection = new ReflectionProperty(SQLiteStorage::class, 'pdo'); + $reflection->setAccessible(true); + $pdo = $reflection->getValue($storage); + + // Now we use the storage object's own PDO connection to count the number of rows in the cache + $stmt = $pdo->prepare('SELECT COUNT(*) FROM cache'); + $stmt->execute(); + return (int) $stmt->fetchColumn(); + } catch (ReflectionException $e) { + Assert::fail('Unable to access PDO property: ' . $e->getMessage()); + } + +} \ No newline at end of file diff --git a/tests/Storages/SQLiteStorage.permissions.phpt b/tests/Storages/SQLiteStorage.permissions.phpt index 331b2861..153ac19a 100644 --- a/tests/Storages/SQLiteStorage.permissions.phpt +++ b/tests/Storages/SQLiteStorage.permissions.phpt @@ -26,7 +26,7 @@ test('', function () { umask(0); (new SQLiteStorage($file))->write('foo', 'bar', []); - Assert::same(0666, fileperms($file) & 0777); + Assert::same(0o666, fileperms($file) & 0o777); }); @@ -34,8 +34,8 @@ test('', function () { $file = getTempDir() . '/sqlitestorage.permissions.2.sqlite'; Assert::false(file_exists($file)); - umask(0077); + umask(0o077); (new SQLiteStorage($file))->write('foo', 'bar', []); - Assert::same(0600, fileperms($file) & 0777); + Assert::same(0o600, fileperms($file) & 0o777); }); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 9093ae2c..02cd1ef2 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -20,9 +20,9 @@ function getTempDir(): string { $dir = __DIR__ . '/tmp/' . getmypid(); - if (empty($GLOBALS['\\lock'])) { + if (empty($GLOBALS['\lock'])) { // garbage collector - $GLOBALS['\\lock'] = $lock = fopen(__DIR__ . '/lock', 'w'); + $GLOBALS['\lock'] = $lock = fopen(__DIR__ . '/lock', 'w'); if (rand(0, 100)) { flock($lock, LOCK_SH); @mkdir(dirname($dir));