Completed
Push — signal_search_issues ( 5556b2...f328ba )
by André
63:06 queued 07:22
created

CacheServiceDecorator::getItem()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 3
nop 0
dl 0
loc 15
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the CacheServiceDecorator class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 *
9
 * @version //autogentag//
10
 */
11
namespace eZ\Publish\Core\Persistence\Cache;
12
13
use Stash\Interfaces\PoolInterface;
14
15
/**
16
 * Class CacheServiceDecorator.
17
 *
18
 * Wraps the Cache Service for Spi cache to apply key prefix for the cache
19
 */
20
class CacheServiceDecorator
21
{
22
    const SPI_CACHE_KEY_PREFIX = 'ez_spi';
23
24
    /**
25
     * @var \Stash\Interfaces\PoolInterface
26
     */
27
    protected $cachePool;
28
29
    /**
30
     * Constructs the cache service decorator.
31
     *
32
     * @param \Stash\Interfaces\PoolInterface $cachePool
33
     */
34
    public function __construct(PoolInterface $cachePool)
35
    {
36
        $this->cachePool = $cachePool;
37
    }
38
39
    /**
40
     * Returns a Cache item for the specified key. The key can be either a series of string arguments,
41
     * or an array.
42
     *
43
     * @internal param array|string $key , $key, $key...
44
     *
45
     * @return \Stash\Interfaces\ItemInterface
46
     */
47
    public function getItem()
48
    {
49
        $args = func_get_args();
50
51
        // check to see if a single array was used instead of multiple arguments, & check empty in case of empty clear()
52
        if (empty($args)) {
53
            $args = array();
54
        } elseif (!isset($args[1]) && is_array($args[0])) {
55
            $args = $args[0];
56
        }
57
58
        array_unshift($args, self::SPI_CACHE_KEY_PREFIX);
59
60
        return $this->cachePool->getItem($args);
61
    }
62
63
    /**
64
     * Clears the cache for the key, or if none is specified clears the entire cache. The key can be either
65
     * a series of string arguments, or an array.
66
     *
67
     * @internal param array|null|string $key , $key, $key...
68
     */
69
    public function clear()
70
    {
71
        $item = call_user_func_array(array($this, 'getItem'), func_get_args());
72
73
        return $item->clear();
74
    }
75
}
76