Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / caxy / php-htmldiff / lib / Caxy / HtmlDiff / DiffCache.php
1 <?php
2
3 namespace Caxy\HtmlDiff;
4
5 use Doctrine\Common\Cache\Cache;
6
7 /**
8  * Class DiffCache.
9  */
10 class DiffCache
11 {
12     /**
13      * @var Cache
14      */
15     protected $cacheProvider;
16
17     /**
18      * DiffCache constructor.
19      *
20      * @param Cache $cacheProvider
21      */
22     public function __construct(Cache $cacheProvider)
23     {
24         $this->cacheProvider = $cacheProvider;
25     }
26
27     /**
28      * @return Cache
29      */
30     public function getCacheProvider()
31     {
32         return $this->cacheProvider;
33     }
34
35     /**
36      * @param Cache $cacheProvider
37      *
38      * @return DiffCache
39      */
40     public function setCacheProvider($cacheProvider)
41     {
42         $this->cacheProvider = $cacheProvider;
43
44         return $this;
45     }
46
47     /**
48      * @param string $oldText
49      * @param string $newText
50      *
51      * @return bool
52      */
53     public function contains($oldText, $newText)
54     {
55         return $this->cacheProvider->contains($this->getHashKey($oldText, $newText));
56     }
57
58     /**
59      * @param string $oldText
60      * @param string $newText
61      *
62      * @return string
63      */
64     public function fetch($oldText, $newText)
65     {
66         return $this->cacheProvider->fetch($this->getHashKey($oldText, $newText));
67     }
68
69     /**
70      * @param string $oldText
71      * @param string $newText
72      * @param string $data
73      * @param int    $lifeTime
74      *
75      * @return bool
76      */
77     public function save($oldText, $newText, $data, $lifeTime = 0)
78     {
79         return $this->cacheProvider->save($this->getHashKey($oldText, $newText), $data, $lifeTime);
80     }
81
82     /**
83      * @param string $oldText
84      * @param string $newText
85      *
86      * @return bool
87      */
88     public function delete($oldText, $newText)
89     {
90         return $this->cacheProvider->delete($this->getHashKey($oldText, $newText));
91     }
92
93     /**
94      * @return array|null
95      */
96     public function getStats()
97     {
98         return $this->cacheProvider->getStats();
99     }
100
101     /**
102      * @param string $oldText
103      * @param string $newText
104      *
105      * @return string
106      */
107     protected function getHashKey($oldText, $newText)
108     {
109         return sprintf('%s_%s', md5($oldText), md5($newText));
110     }
111 }