1 | <?php |
||
2 | /** |
||
3 | * This file is part of the O2System Framework package. |
||
4 | * |
||
5 | * For the full copyright and license information, please view the LICENSE |
||
6 | * file that was distributed with this source code. |
||
7 | * |
||
8 | * @author Steeve Andrian Salim |
||
9 | * @copyright Copyright (c) Steeve Andrian Salim |
||
10 | */ |
||
11 | |||
12 | // ------------------------------------------------------------------------ |
||
13 | |||
14 | namespace O2System\Cache\Abstracts; |
||
15 | |||
16 | // ------------------------------------------------------------------------ |
||
17 | |||
18 | use O2System\Cache\DataStructures\Config; |
||
19 | use O2System\Spl\Exceptions\Logic\BadFunctionCall\BadDependencyCallException; |
||
20 | |||
21 | /** |
||
22 | * Class AbstractAdapter |
||
23 | * |
||
24 | * @package O2System\Cache\Abstracts |
||
25 | */ |
||
26 | abstract class AbstractAdapter extends AbstractItemPool |
||
27 | { |
||
28 | /** |
||
29 | * AbstractAdapter::$platform |
||
30 | * |
||
31 | * Adapter Platform Name |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $platform; |
||
36 | |||
37 | /** |
||
38 | * Adapter Config |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | protected $config = []; |
||
43 | |||
44 | /** |
||
45 | * AbstractAdapter::$config |
||
46 | * |
||
47 | * Adapter Prefix Key |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $prefixKey; |
||
52 | |||
53 | // ------------------------------------------------------------------------ |
||
54 | |||
55 | /** |
||
56 | * AbstractAdapter::__construct |
||
57 | * |
||
58 | * @param \O2System\Cache\DataStructures\Config|NULL $config |
||
59 | * |
||
60 | * @return AbstractAdapter |
||
61 | * @throws BadDependencyCallException |
||
62 | */ |
||
63 | public function __construct(Config $config = null) |
||
64 | { |
||
65 | language() |
||
66 | ->addFilePath(str_replace('Abstracts', '', __DIR__) . DIRECTORY_SEPARATOR) |
||
67 | ->loadFile('cache'); |
||
68 | |||
69 | if (isset($config)) { |
||
70 | if ($this->isSupported()) { |
||
71 | $this->connect($config->getArrayCopy()); |
||
72 | |||
73 | if ($config->offsetExists('prefixKey')) { |
||
74 | $this->setPrefixKey($config->prefixKey); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
75 | } |
||
76 | } else { |
||
77 | throw new BadDependencyCallException('E_UNSUPPORTED_ADAPTER_CACHE_EXCEPTION', 0, [$this->platform]); |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | |||
82 | // ------------------------------------------------------------------------ |
||
83 | |||
84 | /** |
||
85 | * AbstractAdapter::isSupported |
||
86 | * |
||
87 | * Checks if this adapter is supported on this system. |
||
88 | * |
||
89 | * @return bool Returns FALSE if not supported. |
||
90 | */ |
||
91 | abstract public function isSupported(); |
||
92 | |||
93 | // ------------------------------------------------------------------------ |
||
94 | |||
95 | /** |
||
96 | * AbstractAdapter::setPrefixKey |
||
97 | * |
||
98 | * Sets item prefix key. |
||
99 | * |
||
100 | * @param $prefixKey |
||
101 | */ |
||
102 | public function setPrefixKey($prefixKey) |
||
103 | { |
||
104 | $this->prefixKey = rtrim($prefixKey, ':') . ':'; |
||
105 | } |
||
106 | |||
107 | // ------------------------------------------------------------------------ |
||
108 | |||
109 | /** |
||
110 | * AbstractAdapter::getPlatform |
||
111 | * |
||
112 | * Gets item pool adapter platform name. |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | public function getPlatform() |
||
117 | { |
||
118 | return $this->platform; |
||
119 | } |
||
120 | |||
121 | // ------------------------------------------------------------------------ |
||
122 | |||
123 | /** |
||
124 | * AbstractAdapter::isConnected |
||
125 | * |
||
126 | * Checks if this adapter has a successful connection. |
||
127 | * |
||
128 | * @return bool Returns FALSE if not supported. |
||
129 | */ |
||
130 | abstract public function isConnected(); |
||
131 | } |