Passed
Pull Request — develop (#349)
by Schlaefer
15:02 queued 10s
created

Plugin::onPluginsLoaded()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3.0416

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 20
ccs 10
cts 12
cp 0.8333
crap 3.0416
rs 9.8333
1
<?php
2
/**
3
 * Plugin class
4
 */
5
namespace Phile\Plugin\Phile\PhpFastCache;
6
7
use Phile\Core\ServiceLocator;
8
use Phile\Plugin\AbstractPlugin;
9
10
/**
11
 * Class Plugin
12
 * Default Phile cache engine
13
 *
14
 * @author  PhileCMS
15
 * @link    https://philecms.github.io
16
 * @license http://opensource.org/licenses/MIT
17
 * @package Phile\Plugin\Phile\PhpFastCache
18
 */
19
class Plugin extends AbstractPlugin
20
{
21
    /**
22
     * {@inheritDoc}
23
     */
24
    protected $events = ['plugins_loaded' => 'onPluginsLoaded'];
25
26
    /**
27
     * onPluginsLoaded method
28
     *
29
     * @return void
30
     */
31 31
    public function onPluginsLoaded()
32
    {
33 31
        $storage = $this->settings['storage'];
34 31
        $config = $this->settings;
35
36 31
        if (!empty($config['phpFastCacheConfig'])) {
37
            $cacheConfig = $config['phpFastCacheConfig'];
38
        } else {
39
            // Remove options unknown to Phpfastcache triggering errors
40 31
            unset($config['active'], $config['storage']);
41 31
            if ($storage == 'files') {
42
                $cacheConfig = new \Phpfastcache\Drivers\Files\Config($config);
43
            } else {
44 31
                $cacheConfig = new \Phpfastcache\Config\ConfigurationOption($config);
45
            }
46
        }
47
48 31
        $psr16Cache = new \Phpfastcache\Helper\Psr16Adapter($storage, $cacheConfig);
49 31
        $phileCache = new PhileToPsr16CacheAdapter($psr16Cache);
50 31
        ServiceLocator::registerService('Phile_Cache', $phileCache);
51
    }
52
}
53