1 | <?php |
||
10 | class Pdo implements StorageInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var BasePdo |
||
14 | */ |
||
15 | private $pdo; |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | private $tableName; |
||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | private $sqlQueries = [ |
||
26 | 'clear' => 'DELETE FROM %tablename%', |
||
27 | 'delete' => 'DELETE FROM %tablename% WHERE LOWER(LEFT(`key`, ?)) = ?', |
||
28 | 'load' => 'SELECT `key`, `value` FROM %tablename%', |
||
29 | 'save' => 'INSERT INTO %tablename% (`key`, `value`) VALUES (?,?)' |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * constructor |
||
34 | * |
||
35 | * @param BasePdo $pdo instance of pdo to execute the queries against |
||
36 | * @param string $tableName the table name to reference |
||
37 | * @param array $sqlQueries custom queries |
||
38 | */ |
||
39 | public function __construct(BasePdo $pdo, $tableName = 'config', array $sqlQueries = []) |
||
45 | /** |
||
46 | * Set the sql queries to be used |
||
47 | * |
||
48 | * @param array $queries additional queries to be used. Overrides the base |
||
49 | * ones provided with this storage adapter |
||
50 | */ |
||
51 | public function setSqlQueries(array $queries) |
||
55 | |||
56 | /** |
||
57 | * @inheritdoc |
||
58 | */ |
||
59 | public function save($key, $value) |
||
72 | |||
73 | /** |
||
74 | * Save the specific key into the database |
||
75 | * |
||
76 | * @param string $key |
||
77 | * @param string|int|float $value |
||
78 | */ |
||
79 | private function saveKey($key, $value) |
||
85 | |||
86 | /** |
||
87 | * @inheritdoc |
||
88 | */ |
||
89 | public function load() |
||
101 | |||
102 | /** |
||
103 | * @inheritdoc |
||
104 | */ |
||
105 | public function clear() |
||
109 | |||
110 | /** |
||
111 | * Generate the requested sql statement based on the provided name |
||
112 | * |
||
113 | * @param string $name the query as referenced by it's name |
||
114 | * @param array $vars any additional variables needed to generate the sql |
||
115 | * @return string |
||
116 | */ |
||
117 | private function getSqlQuery($name, array $vars = []) |
||
127 | |||
128 | /** |
||
129 | * Delete the requested key from the database storage |
||
130 | * |
||
131 | * @param string $key |
||
132 | */ |
||
133 | private function delKey($key) |
||
140 | } |
||
141 |