1 | <?php |
||
20 | abstract class Table |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * @var \PDO Connection |
||
25 | */ |
||
26 | protected $pdo; |
||
27 | |||
28 | /** |
||
29 | * @var string Table name |
||
30 | */ |
||
31 | protected $tableName; |
||
32 | |||
33 | /** |
||
34 | * @var String Entity class |
||
35 | */ |
||
36 | protected $entityClass; |
||
37 | |||
38 | /** |
||
39 | * @var SQLCommand SQL Command |
||
40 | */ |
||
41 | protected $sqlCommand; |
||
42 | |||
43 | /** |
||
44 | * @param \PDO $pdo |
||
45 | * |
||
46 | * @throws TableNameNotDefinedException If table name is not defined in subclass |
||
47 | * @throws EntityClassNotDefinedException If entity class is not defined in subclass |
||
48 | * @throws EntityClassNonexistentException If entity class is nonexistent |
||
49 | */ |
||
50 | 1 | public function __construct(\PDO $pdo) |
|
68 | |||
69 | /** |
||
70 | * Get table name |
||
71 | * |
||
72 | * @return string Table name |
||
73 | */ |
||
74 | 1 | public function getTableName(): string |
|
78 | |||
79 | /** |
||
80 | * Find all entities |
||
81 | * |
||
82 | * @return Entity[] Entities |
||
83 | */ |
||
84 | 1 | public function findAll(): array |
|
91 | |||
92 | /** |
||
93 | * Find all entities where key is equal to the given value |
||
94 | * |
||
95 | * @param string $key Entity key |
||
96 | * @param mixed $value Value to search for |
||
97 | * |
||
98 | * @throws InvalidEntityPropertyException If entity does not have that property |
||
99 | * |
||
100 | * @return Entity[] Entities |
||
101 | */ |
||
102 | 4 | public function findBy(string $key, $value): array |
|
134 | |||
135 | /** |
||
136 | * Insert entity into database |
||
137 | * |
||
138 | * @param Entity $entity Entity object |
||
139 | * |
||
140 | * @return Entity Inserted entity |
||
141 | */ |
||
142 | 1 | public function insert(Entity $entity): Entity |
|
157 | |||
158 | /** |
||
159 | * Update entity in the database |
||
160 | * |
||
161 | * @param Entity $entity Entity object |
||
162 | * |
||
163 | * @return bool True if row was affected, otherwise false |
||
164 | */ |
||
165 | 1 | public function update(Entity $entity): bool |
|
190 | |||
191 | public function delete(Entity $entity) |
||
195 | |||
196 | /** |
||
197 | * Creates an array of Entity objects from statement |
||
198 | * |
||
199 | * @param \PDOStatement $statement |
||
200 | * |
||
201 | * @return Entity[] Entities from statement |
||
202 | */ |
||
203 | protected function createEntitiesFromStatement(\PDOStatement $statement): array |
||
215 | |||
216 | /** |
||
217 | * Create SQLCommand for this Table with provided Entity |
||
218 | * |
||
219 | * @return SQLCommand |
||
220 | */ |
||
221 | protected function createCommand(): SQLCommand |
||
231 | } |
||
232 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.