Completed
Push — master ( b2ff41...3eced2 )
by Tim
14s
created

CacheWarmerPlugin   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 36
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 17 3
1
<?php
2
3
/**
4
 * TechDivision\Import\Plugins\CacheWarmerPlugin
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Plugins;
22
23
use TechDivision\Import\Utils\ConfigurationKeys;
24
use TechDivision\Import\Utils\DependencyInjectionKeys;
25
26
/**
27
 * Plugin implementation to warm the repository caches.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2016 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/techdivision/import
33
 * @link      http://www.techdivision.com
34
 */
35
class CacheWarmerPlugin extends AbstractPlugin
36
{
37
38
    /**
39
     * Array with the default cache warmers.
40
     *
41
     * @var array
42
     */
43
    protected $cacheWarmers = array(
44
        DependencyInjectionKeys::IMPORT_CACHE_WARMER_EAV_ATTRIBUTE_OPTION_VALUE_REPOSITORY
45
    );
46
47
    /**
48
     * Process the plugin functionality.
49
     *
50
     * @return void
51
     * @throws \Exception Is thrown, if the plugin can not be processed
52
     */
53
    public function process()
54
    {
55
56
        // query whether or not additional cache warmers has been configured
57
        if ($this->getPluginConfiguration()->hasParam(ConfigurationKeys::CACHE_WARMERS)) {
58
            // try ot load the cache warmers and merge them with the default ones
59
            $this->cacheWarmers = array_merge(
60
                $this->cacheWarmers,
61
                $this->getPluginConfiguration()->getParam(ConfigurationKeys::CACHE_WARMERS)
62
            );
63
        }
64
65
        // create the instances and warm the repository caches
66
        foreach ($this->cacheWarmers as $id) {
67
            $this->getApplication()->getContainer()->get($id)->warm();
68
        }
69
    }
70
}
71