1 | <?php |
||
23 | class PDOAdapter implements DataAdapterInterface |
||
24 | { |
||
25 | /** @var PDO */ |
||
26 | private $dataStorage; |
||
27 | /** @var string */ |
||
28 | private $dataGroup = null; |
||
29 | /** @var string */ |
||
30 | private $idKey = null; |
||
31 | |||
32 | /** |
||
33 | * PDOAdapter constructor. |
||
34 | * |
||
35 | * @param PDO $dataStorage |
||
36 | * |
||
37 | * @throws InvalidArgumentException |
||
38 | */ |
||
39 | public function __construct($dataStorage = null) |
||
59 | |||
60 | /** |
||
61 | * Returns the Data Storage instance. |
||
62 | * |
||
63 | * @return PDO |
||
64 | */ |
||
65 | public function getDataStorage() |
||
69 | |||
70 | /** |
||
71 | * Set adapter data group. For Databases this can be the Tables. |
||
72 | * |
||
73 | * @param string $dataGroup |
||
74 | * |
||
75 | * @throws InitException |
||
76 | * |
||
77 | * @return PDOAdapter |
||
78 | */ |
||
79 | public function setDataGroup($dataGroup) |
||
89 | |||
90 | /** |
||
91 | * Set adapter ID key. For Databases this can be the Primary key. Only simple key is allowed. |
||
92 | * |
||
93 | * @param string $idKey |
||
94 | * |
||
95 | * @throws InitException |
||
96 | * |
||
97 | * @return PDOAdapter |
||
98 | */ |
||
99 | public function setIdKey($idKey) |
||
109 | |||
110 | /** |
||
111 | * Get exactly one "row" of data according to the expression. |
||
112 | * |
||
113 | * @param mixed $identifier |
||
114 | * |
||
115 | * @return array |
||
116 | */ |
||
117 | public function getData($identifier) |
||
124 | |||
125 | /** |
||
126 | * Get a set of data according to the expression and the chunk. |
||
127 | * |
||
128 | * @param array $expression |
||
129 | * @param int $limit |
||
130 | * @param int $offset |
||
131 | * |
||
132 | * @return array |
||
133 | */ |
||
134 | public function getDataSet(array $expression, $limit = null, $offset = null) |
||
141 | |||
142 | /** |
||
143 | * Get the number of matched data in the set according to the expression. |
||
144 | * |
||
145 | * @param array $expression |
||
146 | * |
||
147 | * @return int |
||
148 | */ |
||
149 | public function getDataCardinality(array $expression) |
||
156 | |||
157 | /** |
||
158 | * Build query statement from the expression. |
||
159 | * |
||
160 | * @param array $expression |
||
161 | * @param int $limit |
||
162 | * @param int $offset |
||
163 | * |
||
164 | * @return PDOStatement |
||
165 | */ |
||
166 | private function getStatementForExpression(array $expression, $limit = null, $offset = null) |
||
200 | |||
201 | /** |
||
202 | * Insert or update entity in the storage. |
||
203 | * |
||
204 | * @param mixed $identifier |
||
205 | * @param array $data |
||
206 | * |
||
207 | * @return mixed The ID of the saved entity in the storage |
||
208 | */ |
||
209 | public function saveData($identifier, array $data) |
||
238 | |||
239 | /** |
||
240 | * Binds values to the statement. |
||
241 | * |
||
242 | * @param PDOStatement $statement |
||
243 | * @param array $queryBind |
||
244 | */ |
||
245 | private function bindValuesToStatement(PDOStatement &$statement, array $queryBind) |
||
259 | |||
260 | /** |
||
261 | * Removes an entity from the storage. |
||
262 | * |
||
263 | * @param mixed $identifier |
||
264 | * |
||
265 | * @return bool |
||
266 | */ |
||
267 | public function deleteData($identifier) |
||
273 | } |
||
274 |