ZendStorageCache::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
/**
4
 * BsbFlystem
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @see       https://bushbaby.nl/
10
 *
11
 * @copyright Copyright (c) 2014-2021 bushbaby multimedia. (https://bushbaby.nl)
12
 * @author    Bas Kamer <[email protected]>
13
 * @license   MIT
14
 *
15
 * @package   bushbaby/flysystem
16
 */
17
18
declare(strict_types=1);
19
20
namespace BsbFlysystem\Cache;
21
22
use Laminas\Cache\Storage\StorageInterface;
23
use League\Flysystem\Cached\Storage\AbstractCache;
24
25 7
/**
26
 * Wrapper class that allows usage of a Zend Cache as a Flysystem Cache.
27 7
 */
28 7
class ZendStorageCache extends AbstractCache
29 7
{
30
    /**
31 5
     * @var string storage key
32
     */
33 5
    protected $key;
34
35 5
    /**
36 1
     * @var StorageInterface
37
     */
38 5
    protected $storage;
39
40 2
    public function __construct(StorageInterface $storage, string $key = 'bsbflysystem')
41
    {
42 2
        $this->storage = $storage;
43 2
        $this->key = $key;
44 2
    }
45
46
    public function load(): void
47
    {
48
        $contents = $this->storage->getItem($this->key);
49
50
        if (null !== $contents) {
51
            $this->setFromStorage($contents);
52
        }
53
    }
54
55
    public function save(): void
56
    {
57
        $contents = $this->getForStorage();
58
        $this->storage->setItem($this->key, $contents);
59
    }
60
}
61