From 5ffe263752af5ccf3866a28305e7b2669ab4da82 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 31 Mar 2020 17:03:19 +0200 Subject: [PATCH] Cache::save() with closure is deprecated (BC break) It was internal usage --- src/Caching/Cache.php | 1 + tests/Caching/Cache.save.phpt | 6 +++--- tests/Storages/FileStorage.closure.phpt | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Caching/Cache.php b/src/Caching/Cache.php index da5898d7..8566022b 100644 --- a/src/Caching/Cache.php +++ b/src/Caching/Cache.php @@ -169,6 +169,7 @@ public function save($key, $data, array $dependencies = null) $key = $this->generateKey($key); if ($data instanceof \Closure) { + trigger_error(__METHOD__ . '() closure argument is deprecated.', E_USER_WARNING); $this->storage->lock($key); try { $data = $data(...[&$dependencies]); diff --git a/tests/Caching/Cache.save.phpt b/tests/Caching/Cache.save.phpt index 519ed53a..aa4f6a0a 100644 --- a/tests/Caching/Cache.save.phpt +++ b/tests/Caching/Cache.save.phpt @@ -31,7 +31,7 @@ Assert::same($dependencies, $res['dependencies']); $storage = new testStorage; $cache = new Cache($storage, 'ns'); -$cache->save('key', function () { +@$cache->save('key', function () { // @ deprecated return 'value'; }); @@ -45,7 +45,7 @@ $storage = new testStorage; $cache = new Cache($storage, 'ns'); $dependencies = [Cache::TAGS => ['tag']]; -$cache->save('key', function () { +@$cache->save('key', function () { // @ deprecated return 'value'; }, $dependencies); @@ -59,7 +59,7 @@ $storage = new testStorage; $cache = new Cache($storage, 'ns'); $dependencies = [Cache::EXPIRATION => new DateTime]; -$res = $cache->save('key', function () { +@$res = $cache->save('key', function () { // @ deprecated return 'value'; }, $dependencies); Assert::same('value', $res); diff --git a/tests/Storages/FileStorage.closure.phpt b/tests/Storages/FileStorage.closure.phpt index f3437101..243f9ea7 100644 --- a/tests/Storages/FileStorage.closure.phpt +++ b/tests/Storages/FileStorage.closure.phpt @@ -24,7 +24,7 @@ Assert::null($cache->load($key)); // Writing cache using Closure... -$res = $cache->save($key, function () use ($value) { +$res = @$cache->save($key, function () use ($value) { // @ deprecated return $value; }); @@ -34,7 +34,7 @@ Assert::same($cache->load($key), $value); // Removing from cache using null callback... -$cache->save($key, function () { +@$cache->save($key, function () { // @ deprecated return null; });