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