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