8000 [Cache] deprecate all PSR-16 adapters, provide Psr16Cache instead · symfony/symfony@a322860 · GitHub
[go: up one dir, main page]

Skip to content

Commit a322860

Browse files
[Cache] deprecate all PSR-16 adapters, provide Psr16Cache instead
1 parent cd4b031 commit a322860

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+784
-385
lines changed

UPGRADE-4.3.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ BrowserKit
88
* Deprecated `Response::buildHeader()`
99
* Deprecated `Response::getStatus()`, use `Response::getStatusCode()` instead
1010

11+
Cache
12+
-----
13+
14+
* The `psr/simple-cache` dependency has been removed - run `composer require psr/simple-cache` if you need it.
15+
* Deprecated all PSR-16 adapters, use `Psr16Cache` or `Symfony\Contracts\Cache\CacheInterface` implementations instead.
16+
* Deprecated `SimpleCacheAdapter`, use `Psr16Adapter instead.
17+
1118
Config
1219
------
1320

@@ -18,6 +25,7 @@ FrameworkBundle
1825

1926
* Not passing the project directory to the constructor of the `AssetsInstallCommand` is deprecated. This argument will
2027
be mandatory in 5.0.
28+
* Deprecated the "Psr\SimpleCache\CacheInterface" / "cache.app.simple" service, use "Symfony\Contracts\Cache\CacheInterface" / "cache.app" instead.
2129

2230
HttpFoundation
2331
--------------

UPGRADE-5.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Cache
1313
-----
1414

1515
* Removed `CacheItem::getPreviousTags()`, use `CacheItem::getMetadata()` instead.
16+
* Removed all PSR-16 adapters, use `Psr16Cache` or `Symfony\Contracts\Cache\CacheInterface` implementations instead.
17+
* Removed `SimpleCacheAdapter`, use `Psr16Adapter instead.
1618

1719
Config
1820
------
@@ -163,6 +165,7 @@ FrameworkBundle
163165
* The `Templating\Helper\TranslatorHelper::transChoice()` method has been removed, use the `trans()` one instead with a `%count%` parameter.
164166
* Removed support for legacy translations directories `src/Resources/translations/` and `src/Resources/<BundleName>/translations/`, use `translations/` instead.
165167
* Support for the legacy directory structure in `translation:update` and `debug:translation` commands has been removed.
168+
* Removed the "Psr\SimpleCache\CacheInterface" / "cache.app.simple" service, use "Symfony\Contracts\Cache\CacheInterface" / "cache.app" instead.
166169

167170
HttpFoundation
168171
--------------

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
be mandatory in 5.0.
99
* Added `ControllerTrait::isFormValid()`
1010
* Added an `help_html` form option to display the `help` text as HTML
11+
* Deprecated the "Psr\SimpleCache\CacheInterface" / "cache.app.simple" service, use "Symfony\Contracts\Cache\CacheInterface" / "cache.app" instead
1112

1213
4.2.0
1314
-----

src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
<tag name="cache.pool" clearer="cache.app_clearer" reset="reset" />
1212
</service>
1313

14-
<service id="cache.app.simple" class="Symfony\Component\Cache\Simple\Psr6Cache">
14+
<service id="cache.app.simple" class="Symfony\Component\Cache\Psr16Cache">
15+
<deprecated>The "Psr\SimpleCache\CacheInterface" / "%service_id%" service is deprecated since Symfony 4.3. Use "Symfony\Contracts\Cache\CacheInterface" / "cache.app" instead.</deprecated>
1516
<argument type="service" id="cache.app" />
1617
</service>
1718

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": "^7.1.3",
2020
"ext-xml": "*",
21-
"symfony/cache": "~4.2",
21+
"symfony/cache": "~4.3",
2222
"symfony/config": "~4.2",
2323
"symfony/contracts": "^1.0.2",
2424
"symfony/dependency-injection": "^4.2",
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Adapter;
13+
14+
use Psr\SimpleCache\CacheInterface;
15+
use Symfony\Component\Cache\PruneableInterface;
16+
use Symfony\Component\Cache\ResettableInterface;
17+
use Symfony\Component\Cache\Traits\ProxyTrait;
18+
19+
/**
20+
* Turns a PSR-16 cache into a PSR-6 one.
21+
*
22+
* @author Nicolas Grekas <p@tchwork.com>
23+
*/
24+
class Psr16Adapter extends AbstractAdapter implements PruneableInterface, ResettableInterface
25+
{
26+
use ProxyTrait;
27+
28+
private $miss;
29+
30+
public function __construct(CacheInterface $pool, string $namespace = '', int $defaultLifetime = 0)
31+
{
32+
parent::__construct($namespace, $defaultLifetime);
33+
34+
$this->pool = $pool;
35+
$this->miss = new \stdClass();
36+
}
37+
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
protected function doFetch(array $ids)
42+
{
43+
foreach ($this->pool->getMultiple($ids, $this->miss) as $key => $value) {
44+
if ($this->miss !== $value) {
45+
yield $key => $value;
46+
}
47+
}
48+
}
49+
50+
/**
51+
* {@inheritdoc}
52+
*/
53+
protected function doHave($id)
54+
{
55+
return $this->pool->has($id);
56+
}
57+
58+
/**
59+
* {@inheritdoc}
60+
*/
61+
protected function doClear($namespace)
62+
{
63+
return $this->pool->clear();
64+
}
65+
66+
/**
67+
* {@inheritdoc}
68+
*/
69+
protected function doDelete(array $ids)
70+
{
71+
return $this->pool->deleteMultiple($ids);
72+
}
73+
74+
/**
75+
* {@inheritdoc}
76+
*/
77+
protected function doSave(array $values, $lifetime)
78+
{
79+
return $this->pool->setMultiple($values, 0 === $lifetime ? null : $lifetime);
80+
}
81+
}

src/Symfony/Component/Cache/Adapter/SimpleCacheAdapter.php

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -11,69 +11,11 @@
1111

1212
namespace Symfony\Component\Cache\Adapter;
1313

14-
use Psr\SimpleCache\CacheInterface;
15-
use Symfony\Component\Cache\PruneableInterface;
16-
use Symfony\Component\Cache\ResettableInterface;
17-
use Symfony\Component\Cache\Traits\ProxyTrait;
14+
@trigger_error(sprintf('The "%s" class is @deprecated since Symfony 4.3, use "Psr16Adapter" instead.', SimpleCacheAdapter::class), E_USER_DEPRECATED);
1815

1916
/**
20-
* @author Nicolas Grekas <p@tchwork.com>
17+
* @deprecated since Symfony 4.3, use Psr16Adapter instead.
2118
*/
22-
class SimpleCacheAdapter extends AbstractAdapter implements PruneableInterface, ResettableInterface
19+
class SimpleCacheAdapter extends Psr16Adapter
2320
{
24-
use ProxyTrait;
25-
26-
private $miss;
27-
28-
public function __construct(CacheInterface $pool, string $namespace = '', int $defaultLifetime = 0)
29-
{
30-
parent::__construct($namespace, $defaultLifetime);
31-
32-
$this->pool = $pool;
33-
$this->miss = new \stdClass();
34-
}
35-
36-
/**
37-
* {@inheritdoc}
38-
*/
39-
protected function doFetch(array $ids)
40-
{
41-
foreach ($this->pool->getMultiple($ids, $this->miss) as $key => $value) {
42-
if ($this->miss !== $value) {
43-
yield $key => $value;
44-
}
45-
}
46-
}
47-
48-
/**
49-
* {@inheritdoc}
50-
*/
51-
protected function doHave($id)
52-
{
53-
return $this->pool->has($id);
54-
}
55-
56-
/**
57-
* {@inheritdoc}
58-
*/
59-
protected function doClear($namespace)
60-
{
61-
return $this->pool->clear();
62-
}
63-
64-
/**
65-
* {@inheritdoc}
66-
*/
67-
protected function doDelete(array $ids)
68-
{
69-
return $this->pool->deleteMultiple($ids);
70-
}
71-
72-
/**
73-
* {@inheritdoc}
74-
*/
75-
protected function doSave(array $values, $lifetime)
76-
{
77-
return $this->pool->setMultiple($values, 0 === $lifetime ? null : $lifetime);
78-
}
7921
}

src/Symfony/Component/Cache/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
CHANGELOG
22
=========
33

4+
4.3.0
5+
-----
6+
7+
* removed `psr/simple-cache` dependency, run `composer require psr/simple-cache` if you need it
8+
* deprecated all PSR-16 adapters, use `Psr16Cache` or `Symfony\Contracts\Cache\CacheInterface` implementations instead
9+
* deprecated `SimpleCacheAdapter`, use `Psr16Adapter instead
10+
411
4.2.0
512
-----
613

src/Symfony/Component/Cache/Exception/CacheException.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
use Psr\Cache\CacheException as Psr6CacheInterface;
1515
use Psr\SimpleCache\CacheException as SimpleCacheInterface;
1616

17-
class CacheException extends \Exception implements Psr6CacheInterface, SimpleCacheInterface
18-
{
17+
if (interface_exists(SimpleCacheInterface::class)) {
18+
class CacheException extends \Exception implements Psr6CacheInterface, SimpleCacheInterface
19+
{
20+
}
21+
} else {
22+
class CacheException extends \Exception implements Psr6CacheInterface
23+
{
24+
}
1925
}

src/Symfony/Component/Cache/Exception/InvalidArgumentException.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
use Psr\Cache\InvalidArgumentException as Psr6CacheInterface;
1515
use Psr\SimpleCache\InvalidArgumentException as SimpleCacheInterface;
1616

17-
class InvalidArgumentException extends \InvalidArgumentException implements Psr6CacheInterface, SimpleCacheInterface
18-
{
17+
if (interface_exists(SimpleCacheInterface::class)) {
18+
class InvalidArgumentException extends \InvalidArgumentException implements Psr6CacheInterface, SimpleCacheInterface
19+
{
20+
}
21+
} else {
22+
class InvalidArgumentException extends \InvalidArgumentException implements Psr6CacheInterface
23+
{
24+
}
1925
}

src/Symfony/Component/Cache/Exception/LogicException.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
use Psr\Cache\CacheException as Psr6CacheInterface;
1515
use Psr\SimpleCache\CacheException as SimpleCacheInterface;
1616

17-
class LogicException extends \LogicException implements Psr6CacheInterface, SimpleCacheInterface
18-
{
17+
if (interface_exists(SimpleCacheInterface::class)) {
18+
class LogicException extends \LogicException implements Psr6CacheInterface, SimpleCacheInterface
19+
{
20+
}
21+
} else {
22+
class LogicException extends \LogicException implements Psr6CacheInterface
23+
{
24+
}
1925
}

src/Symfony/Component/Cache/LockRegistry.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class LockRegistry
4545
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'PhpArrayAdapter.php',
4646
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'PhpFilesAdapter.php',
4747
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'ProxyAdapter.php',
48+
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'Psr16Adapter.php',
4849
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'RedisAdapter.php',
4950
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'SimpleCacheAdapter.php',
5051
__DIR__.\DIRECTORY_SEPARATOR.'Adapter'.\DIRECTORY_SEPARATOR.'TagAwareAdapter.php',

0 commit comments

Comments
 (0)
0