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

SimpleCacheServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 15 4
A boot() 0 3 1
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