Completed
Push — master ( 5db45c...f208af )
by Arthur
02:39
created

FileCacheDriver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Arthem\GraphQLMapper\Mapping\Cache;
4
5
use Arthem\GraphQLMapper\Mapping\SchemaContainer;
6
7
class FileCacheDriver implements CacheDriverInterface
8
{
9
    /**
10
     * @var string
11
     */
12
    private $cacheFile;
13
14
    /**
15
     * @param string $cacheFile
16
     */
17
    public function __construct($cacheFile)
18
    {
19
        $this->cacheFile = $cacheFile;
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function load()
26
    {
27
        if (!is_file($this->cacheFile)) {
28
            return false;
29
        }
30
31
        return unserialize(file_get_contents($this->cacheFile));
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function save(SchemaContainer $container)
38
    {
39
        file_put_contents($this->cacheFile, serialize($container));
40
    }
41
42
}
43