Passed
Push — master ( 8be542...031438 )
by Alexander
10:57
created

CacheProvider::register()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Provider;
6
7
use Psr\Container\ContainerInterface;
8
use Psr\SimpleCache\CacheInterface;
9
use Yiisoft\Aliases\Aliases;
10
use Yiisoft\Cache\Cache;
11
use Yiisoft\Cache\CacheInterface as YiiCacheInterface;
12
use Yiisoft\Cache\File\FileCache;
13
use Yiisoft\Di\Container;
14
use Yiisoft\Di\Support\ServiceProvider;
15
16
final class CacheProvider extends ServiceProvider
17
{
18
    private string $cachePath;
19
20
    public function __construct(string $cachePath = '@runtime/cache')
21
    {
22
        $this->cachePath = $cachePath;
23
    }
24
25
    public function register(Container $container): void
26
    {
27
        $container->set(CacheInterface::class, function (ContainerInterface $container) {
28
            $aliases = $container->get(Aliases::class);
29
30
            return new FileCache($aliases->get($this->cachePath));
31
        });
32
33
        $container->set(YiiCacheInterface::class, Cache::class);
34
    }
35
}
36