DualCacheServiceProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 6
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
A registerCacheDriver() 0 14 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Istyle\LaravelDualCache;
5
6
use Illuminate\Support\ServiceProvider;
7
use Illuminate\Cache\CacheManager;
8
use Illuminate\Cache\Repository;
9
use Illuminate\Session\CacheBasedSessionHandler;
10
11
/**
12
 * Class DualCacheServiceProvider
13
 */
14
final class DualCacheServiceProvider extends ServiceProvider
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function boot()
20
    {
21
        $this->registerCacheDriver();
22
    }
23
24
    /**
25
     * register fusion cache
26
     */
27
    public function registerCacheDriver()
28
    {
29
        $this->app['cache']->extend('dual-cache', function ($app, $config) {
30
            /** @var CacheManager $cacheManager */
31
            $cacheManager = $app['cache'];
32
            return new Repository(
33
                new DualCacheStore(
34
                    $cacheManager->store($config['primary'])->getStore(),
35
                    $cacheManager->store($config['secondary'])->getStore(),
36
                    new DualCacheHandler()
37
                )
38
            );
39
        });
40
    }
41
}
42