Skip to content

Commit

Permalink
Cache::save() with closure is deprecated (BC break)
Browse files Browse the repository at this point in the history
It was internal usage
  • Loading branch information
dg committed Oct 15, 2020
1 parent 34e4361 commit eb57c44
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Caching/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,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]);
Expand Down
6 changes: 3 additions & 3 deletions tests/Caching/Cache.save.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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';
});

Expand All @@ -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);

Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/Storages/FileStorage.closure.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand All @@ -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;
});

Expand Down

0 comments on commit eb57c44

Please sign in to comment.