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 for given conditions |
||
96 | * |
||
97 | * ``` |
||
98 | * [ |
||
99 | * '{entity_property}' => '{property_value}' |
||
100 | * ] |
||
101 | * ``` |
||
102 | * |
||
103 | * @param array $conditions |
||
104 | * |
||
105 | * @throws InvalidEntityPropertyException If entity does not have that property |
||
106 | * |
||
107 | * @return Entity[] Entities |
||
108 | */ |
||
109 | 4 | public function findBy(array $conditions): array |
|
148 | |||
149 | /** |
||
150 | * Insert entity into database |
||
151 | * |
||
152 | * @param Entity $entity Entity object |
||
153 | * |
||
154 | * @return Entity Inserted entity |
||
155 | */ |
||
156 | 1 | public function insert(Entity $entity): Entity |
|
171 | |||
172 | /** |
||
173 | * Update entity in the database |
||
174 | * |
||
175 | * @param Entity $entity Entity object |
||
176 | * |
||
177 | * @return bool True if row was affected, otherwise false |
||
178 | */ |
||
179 | 1 | public function update(Entity $entity): bool |
|
204 | |||
205 | public function delete(Entity $entity) |
||
209 | |||
210 | /** |
||
211 | * Creates an array of Entity objects from statement |
||
212 | * |
||
213 | * @param \PDOStatement $statement |
||
214 | * |
||
215 | * @return Entity[] Entities from statement |
||
216 | */ |
||
217 | protected function createEntitiesFromStatement(\PDOStatement $statement): array |
||
229 | |||
230 | /** |
||
231 | * Create SQLCommand for this Table with provided Entity |
||
232 | * |
||
233 | * @return SQLCommand |
||
234 | */ |
||
235 | 1 | protected function createCommand(): SQLCommand |
|
245 | } |
||
246 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.