Completed
Push — master ( 452f3b...8b11af )
by Changwan
04:35
created

SimpleCacheServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Wandu\DI\Providers\Symfony;
3
4
use Memcached;
5
use Predis\Client;
6
use Psr\SimpleCache\CacheInterface;
7
use Symfony\Component\Cache\Simple\ApcuCache;
8
use Symfony\Component\Cache\Simple\FilesystemCache;
9
use Symfony\Component\Cache\Simple\MemcachedCache;
10
use Symfony\Component\Cache\Simple\RedisCache;
11
use Wandu\Config\Contracts\Config;
12
use Wandu\DI\ContainerInterface;
13
use Wandu\DI\ServiceProviderInterface;
14
15
class SimpleCacheServiceProvider implements ServiceProviderInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function register(ContainerInterface $app)
21
    {
22
        $app->closure(CacheInterface::class, function (Config $config, ContainerInterface $app) {
23
            switch ($config->get('cache.type')) {
24
                case 'apcu':
25
                    return new ApcuCache('wandu.');
26
                case 'memcached':
27
                    return new MemcachedCache($app->get(Memcached::class), 'wandu.');
28
                case 'redis':
29
                    return new RedisCache($app->get(Client::class), 'wandu.');
30
                default:
31
                    return new FilesystemCache('wandu.');
32
            }
33
        });
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function boot(ContainerInterface $app)
40
    {
41
    }
42
}
43