tebru /
gson-php
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | namespace Tebru\Gson\Internal; |
||||
| 6 | |||||
| 7 | use Psr\SimpleCache\CacheInterface; |
||||
| 8 | use Symfony\Component\Cache\Adapter\ArrayAdapter; |
||||
| 9 | use Symfony\Component\Cache\Adapter\ChainAdapter; |
||||
| 10 | use Symfony\Component\Cache\Adapter\NullAdapter; |
||||
| 11 | use Symfony\Component\Cache\Adapter\PhpFilesAdapter; |
||||
| 12 | use Symfony\Component\Cache\Adapter\Psr16Adapter; |
||||
| 13 | use Symfony\Component\Cache\Psr16Cache; |
||||
| 14 | use Symfony\Component\Cache\Simple\ArrayCache; |
||||
| 15 | use Symfony\Component\Cache\Simple\ChainCache; |
||||
| 16 | use Symfony\Component\Cache\Simple\NullCache; |
||||
| 17 | use Symfony\Component\Cache\Simple\PhpFilesCache; |
||||
| 18 | |||||
| 19 | /** |
||||
| 20 | * @codeCoverageIgnore |
||||
| 21 | */ |
||||
| 22 | final class CacheProvider |
||||
| 23 | { |
||||
| 24 | /** |
||||
| 25 | * Create a "file cache", chained to a "memory cache" depending on symfony/cache version |
||||
| 26 | * |
||||
| 27 | * @param string $cacheDir |
||||
| 28 | * @return CacheInterface |
||||
| 29 | * @throws \Symfony\Component\Cache\Exception\CacheException |
||||
| 30 | */ |
||||
| 31 | public static function createFileCache(string $cacheDir): CacheInterface |
||||
| 32 | { |
||||
| 33 | // >= Symfony 4.3 |
||||
| 34 | if (class_exists('Symfony\Component\Cache\Psr16Cache')) { |
||||
| 35 | return new Psr16Cache(new ChainAdapter([ |
||||
| 36 | new Psr16Adapter(self::createMemoryCache()), |
||||
| 37 | new PhpFilesAdapter('', 0, $cacheDir), |
||||
| 38 | ])); |
||||
| 39 | } |
||||
| 40 | |||||
| 41 | return new ChainCache([ |
||||
|
0 ignored issues
–
show
Deprecated Code
introduced
by
Loading history...
|
|||||
| 42 | self::createMemoryCache(), |
||||
| 43 | new PhpFilesCache('', 0, $cacheDir) |
||||
|
0 ignored issues
–
show
The class
Symfony\Component\Cache\Simple\PhpFilesCache has been deprecated: since Symfony 4.3, use PhpFilesAdapter and type-hint for CacheInterface instead.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 44 | ]); |
||||
| 45 | } |
||||
| 46 | |||||
| 47 | /** |
||||
| 48 | * Create a "memory cache" depending on symfony/cache version |
||||
| 49 | * |
||||
| 50 | * @return CacheInterface |
||||
| 51 | */ |
||||
| 52 | public static function createMemoryCache(): CacheInterface |
||||
| 53 | { |
||||
| 54 | // >= Symfony 4.3 |
||||
| 55 | if (class_exists('Symfony\Component\Cache\Psr16Cache')) { |
||||
| 56 | return new Psr16Cache(new ArrayAdapter(0, false)); |
||||
| 57 | } |
||||
| 58 | |||||
| 59 | return new ArrayCache(0, false); |
||||
|
0 ignored issues
–
show
The class
Symfony\Component\Cache\Simple\ArrayCache has been deprecated: since Symfony 4.3, use ArrayAdapter and type-hint for CacheInterface instead.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 60 | } |
||||
| 61 | |||||
| 62 | /** |
||||
| 63 | * Create a "null" cache (for annotations) depending on symfony/cache version |
||||
| 64 | * |
||||
| 65 | * @return CacheInterface |
||||
| 66 | */ |
||||
| 67 | public static function createNullCache(): CacheInterface |
||||
| 68 | { |
||||
| 69 | // >= Symfony 4.3 |
||||
| 70 | if (class_exists('Symfony\Component\Cache\Psr16Cache')) { |
||||
| 71 | return new Psr16Cache(new NullAdapter()); |
||||
| 72 | } |
||||
| 73 | |||||
| 74 | return new NullCache(); |
||||
|
0 ignored issues
–
show
The class
Symfony\Component\Cache\Simple\NullCache has been deprecated: since Symfony 4.3, use NullAdapter and type-hint for CacheInterface instead.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 75 | } |
||||
| 76 | } |
||||
| 77 |