1 | <?php namespace Limoncello\Passport\Adaptors\MySql; |
||
27 | trait DatabaseSchemaMigrationTrait |
||
28 | { |
||
29 | use BaseDatabaseSchemaMigrationTrait { |
||
30 | BaseDatabaseSchemaMigrationTrait::createDatabaseSchema as createDatabaseTables; |
||
31 | BaseDatabaseSchemaMigrationTrait::removeDatabaseSchema as removeDatabaseTables; |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @param Connection $connection |
||
36 | * @param DatabaseSchemaInterface $schema |
||
37 | * |
||
38 | * @throws DBALException |
||
39 | * |
||
40 | * @return void |
||
41 | */ |
||
42 | 2 | protected function createDatabaseSchema(Connection $connection, DatabaseSchemaInterface $schema): void |
|
43 | { |
||
44 | try { |
||
45 | 2 | $this->createDatabaseTables($connection, $schema); |
|
|
|||
46 | 2 | $this->createDatabaseViews($connection, $schema); |
|
47 | 2 | } catch (DBALException $exception) { |
|
48 | 2 | if ($connection->isConnected() === true) { |
|
49 | 2 | $this->removeDatabaseSchema($connection, $schema); |
|
50 | } |
||
51 | |||
52 | 2 | throw $exception; |
|
53 | } |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @param Connection $connection |
||
58 | * @param DatabaseSchemaInterface $schema |
||
59 | * |
||
60 | * @return void |
||
61 | */ |
||
62 | 2 | protected function removeDatabaseSchema(Connection $connection, DatabaseSchemaInterface $schema): void |
|
63 | { |
||
64 | 2 | $this->removeDatabaseTables($connection, $schema); |
|
65 | 2 | $this->removeDatabaseViews($connection, $schema); |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * @param Connection $connection |
||
70 | * @param DatabaseSchemaInterface $schema |
||
71 | * |
||
72 | * @return void |
||
73 | */ |
||
74 | 2 | protected function createDatabaseViews(Connection $connection, DatabaseSchemaInterface $schema): void |
|
81 | |||
82 | /** |
||
83 | * @param Connection $connection |
||
84 | * @param DatabaseSchemaInterface $schema |
||
85 | * |
||
86 | * @return void |
||
87 | */ |
||
88 | 2 | protected function removeDatabaseViews(Connection $connection, DatabaseSchemaInterface $schema): void |
|
95 | |||
96 | /** |
||
97 | * @param Connection $connection |
||
98 | * @param DatabaseSchemaInterface $schema |
||
99 | * |
||
100 | * @throws DBALException |
||
101 | * |
||
102 | * @return void |
||
103 | */ |
||
104 | 1 | protected function createTokensView(Connection $connection, DatabaseSchemaInterface $schema): void |
|
125 | |||
126 | /** |
||
127 | * @param Connection $connection |
||
128 | * @param DatabaseSchemaInterface $schema |
||
129 | * |
||
130 | * @throws DBALException |
||
131 | * |
||
132 | * @return void |
||
133 | */ |
||
134 | 2 | protected function removeTokensView(Connection $connection, DatabaseSchemaInterface $schema) |
|
140 | |||
141 | /** |
||
142 | * @param Connection $connection |
||
143 | * @param DatabaseSchemaInterface $schema |
||
144 | * |
||
145 | * @throws DBALException |
||
146 | * |
||
147 | * @return void |
||
148 | */ |
||
149 | 1 | protected function createPassportView(Connection $connection, DatabaseSchemaInterface $schema): void |
|
164 | |||
165 | /** |
||
166 | * @param Connection $connection |
||
167 | * @param DatabaseSchemaInterface $schema |
||
168 | * |
||
169 | * @throws DBALException |
||
170 | * |
||
171 | * @return void |
||
172 | */ |
||
173 | 2 | protected function removePassportView(Connection $connection, DatabaseSchemaInterface $schema): void |
|
179 | |||
180 | /** |
||
181 | * @param Connection $connection |
||
182 | * @param DatabaseSchemaInterface $schema |
||
183 | * |
||
184 | * @throws DBALException |
||
185 | * |
||
186 | * @return void |
||
187 | */ |
||
188 | 2 | protected function createClientsView(Connection $connection, DatabaseSchemaInterface $schema) |
|
214 | |||
215 | /** |
||
216 | * @param Connection $connection |
||
217 | * @param DatabaseSchemaInterface $schema |
||
218 | * |
||
219 | * @throws DBALException |
||
220 | * |
||
221 | * @return void |
||
222 | */ |
||
223 | 2 | protected function removeClientsView(Connection $connection, DatabaseSchemaInterface $schema) |
|
229 | |||
230 | /** |
||
231 | * @param Connection $connection |
||
232 | * @param DatabaseSchemaInterface $schema |
||
233 | * |
||
234 | * @throws DBALException |
||
235 | * |
||
236 | * @return void |
||
237 | */ |
||
238 | 1 | protected function createUsersView(Connection $connection, DatabaseSchemaInterface $schema) |
|
262 | |||
263 | /** |
||
264 | * @param Connection $connection |
||
265 | * @param DatabaseSchemaInterface $schema |
||
266 | * |
||
267 | * @throws DBALException |
||
268 | * |
||
269 | * @return void |
||
270 | */ |
||
271 | 2 | protected function removeUsersView(Connection $connection, DatabaseSchemaInterface $schema) |
|
277 | } |
||
278 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.