Completed
Pull Request — master (#105)
by Tim
11:17
created

EavAttributeOptionValueCacheWarmer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Repositories\CacheWarmer\EavAttributeOptionValueCacheWarmer
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\Repositories\CacheWarmer;
22
23
use TechDivision\Import\Utils\MemberNames;
24
use TechDivision\Import\Repositories\EavAttributeOptionValueRepositoryInterface;
25
26
/**
27
 * Cache warmer implementation to pre-load EAV attribute option value data.
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 EavAttributeOptionValueCacheWarmer implements CacheWarmerInterface
36
{
37
38
    /**
39
     * The repository with the cache that has to be warmed.
40
     *
41
     * @var \TechDivision\Import\Repositories\EavAttributeOptionValueRepositoryInterface
42
     */
43
    protected $repository;
44
45
    /**
46
     * Initialize the cache warmer with the repository that has to be warmed.
47
     *
48
     * @param \TechDivision\Import\Repositories\EavAttributeOptionValueRepositoryInterface $repository The repository to warm
49
     */
50
    public function __construct(EavAttributeOptionValueRepositoryInterface $repository)
51
    {
52
        $this->repository = $repository;
53
    }
54
55
    /**
56
     * Warms the cache for the passed repository.
57
     *
58
     * @return void
59
     */
60
    public function warm()
61
    {
62
63
        // prepare the caches for the statements
64
        foreach ($this->repository->findAll() as $optionValue) {
65
            // the parameters of the EAV attribute option to load
66
            $params = array(
67
                MemberNames::STORE_ID       => $optionValue[MemberNames::STORE_ID],
68
                MemberNames::OPTION_ID      => $optionValue[MemberNames::OPTION_ID]
69
            );
70
71
            // load the repositories utility class name
72
            $utilityClassName = $this->repository->getUtilityClassName();
73
74
            // prepare the cache key and add the option value to the cache
75
            $cacheKey = $this->repository->cacheKey($utilityClassName::EAV_ATTRIBUTE_OPTION_VALUE_BY_OPTION_ID_AND_STORE_ID, $params);
76
            $this->repository->toCache($cacheKey, $optionValue);
77
        }
78
    }
79
}
80