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 string $value Value to search for |
||
96 | * |
||
97 | * @throws InvalidEntityPropertyException If entity does not have that property |
||
98 | * |
||
99 | * @return Entity[] Entities |
||
100 | */ |
||
101 | 3 | public function findBy(string $key, string $value): array |
|
122 | |||
123 | /** |
||
124 | * Insert entity into database |
||
125 | * |
||
126 | * @param Entity $entity Entity object |
||
127 | * |
||
128 | * @return int Inserted entity ID |
||
129 | */ |
||
130 | 1 | public function insert(Entity $entity): int |
|
145 | |||
146 | /** |
||
147 | * Update entity in the database |
||
148 | * |
||
149 | * @param Entity $entity Entity object |
||
150 | * |
||
151 | * @return bool True if row was affected, otherwise false |
||
152 | */ |
||
153 | 1 | public function update(Entity $entity): bool |
|
178 | |||
179 | public function delete(Entity $entity) |
||
183 | |||
184 | /** |
||
185 | * Creates an array of Entity objects from statement |
||
186 | * |
||
187 | * @param \PDOStatement $statement |
||
188 | * |
||
189 | * @return Entity[] Entities from statement |
||
190 | */ |
||
191 | protected function createEntitiesFromStatement(\PDOStatement $statement): array |
||
203 | |||
204 | /** |
||
205 | * Create SQLCommand for this Table with provided Entity |
||
206 | * |
||
207 | * @return SQLCommand |
||
208 | */ |
||
209 | protected function createCommand(): SQLCommand |
||
219 | } |
||
220 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.