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