|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
6
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
7
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
8
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
9
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
10
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
11
|
|
|
* THE SOFTWARE. |
|
12
|
|
|
* |
|
13
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
14
|
|
|
* and is licensed under the MIT license. |
|
15
|
|
|
* |
|
16
|
|
|
* Copyright (c) 2014-2019 Yuuki Takezawa |
|
17
|
|
|
* |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Ytake\LaravelSmarty\Cache; |
|
21
|
|
|
|
|
22
|
|
|
use Ytake\LaravelSmarty\Smarty; |
|
23
|
|
|
use Illuminate\Contracts\Config\Repository as ConfigContract; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class Storage |
|
27
|
|
|
* |
|
28
|
|
|
* @author yuuki.takezawa<[email protected]> |
|
29
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
|
30
|
|
|
*/ |
|
31
|
|
|
class Storage |
|
32
|
|
|
{ |
|
33
|
|
|
/** @var Smarty */ |
|
34
|
|
|
protected $smarty; |
|
35
|
|
|
|
|
36
|
|
|
/** @var ConfigContract */ |
|
37
|
|
|
protected $repository; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param Smarty $smarty |
|
41
|
|
|
* @param ConfigContract $repository |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct(Smarty $smarty, ConfigContract $repository) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->smarty = $smarty; |
|
46
|
|
|
$this->repository = $repository; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
*/ |
|
51
|
|
|
public function cacheStorageManaged() |
|
52
|
|
|
{ |
|
53
|
|
|
$driver = $this->repository->get('ytake-laravel-smarty.cache_driver', 'file'); |
|
54
|
|
|
if ($driver !== 'file') { |
|
55
|
|
|
$storage = $driver . "Storage"; |
|
56
|
|
|
$this->smarty->registerCacheResource($driver, $this->$storage()); |
|
57
|
|
|
} |
|
58
|
|
|
$this->smarty->caching_type = $driver; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return Redis |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function redisStorage() |
|
65
|
|
|
{ |
|
66
|
|
|
return new Redis($this->repository->get('ytake-laravel-smarty.redis')); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return Memcached |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function memcachedStorage() |
|
73
|
|
|
{ |
|
74
|
|
|
return new Memcached( |
|
75
|
|
|
new \Memcached(), |
|
76
|
|
|
$this->repository->get('ytake-laravel-smarty.memcached') |
|
77
|
|
|
); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|