1 | <?php |
||
27 | class Writer |
||
28 | { |
||
29 | /** |
||
30 | * List of tables patterns to ignore |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $ignoredTables = []; |
||
35 | |||
36 | /** |
||
37 | * Should I protect the cols ? That will also protect the Primary Keys |
||
38 | * |
||
39 | * @var boolean |
||
40 | */ |
||
41 | protected $protectCols = true; |
||
42 | |||
43 | /** |
||
44 | * List the cols to protected. Could containe regexp |
||
45 | * |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $protectedCols = ['id', 'parent_id']; |
||
49 | |||
50 | /** |
||
51 | * Store the tables added to the conf |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $tablesInConf = []; |
||
56 | |||
57 | /** |
||
58 | * Doctrine conection handler |
||
59 | * @var \Doctrine\DBAL\Connection |
||
60 | */ |
||
61 | private $conn; |
||
62 | |||
63 | |||
64 | /** |
||
65 | * Generate the configuration by reading tables + cols |
||
66 | * |
||
67 | * @param DB $db |
||
68 | * @param GuesserInterface $guesser |
||
69 | * @return array |
||
70 | */ |
||
71 | public function generateConfFromDB(DB $db, GuesserInterface $guesser): array |
||
103 | |||
104 | |||
105 | /** |
||
106 | * Get Tables List added to the conf |
||
107 | * |
||
108 | * @return array |
||
109 | */ |
||
110 | public function getTablesInConf(): array |
||
114 | |||
115 | |||
116 | /** |
||
117 | * Set a flat to protect cols (Primary Key is protected by default) |
||
118 | * |
||
119 | * @param bool $protectCols |
||
120 | * @return Writer |
||
121 | */ |
||
122 | public function protectCols(bool $protectCols): Writer |
||
128 | |||
129 | |||
130 | /** |
||
131 | * Save the data to the file as YAML |
||
132 | * |
||
133 | * @param array $data |
||
134 | * @param string $filename |
||
135 | */ |
||
136 | public function save(array $data, string $filename) |
||
144 | |||
145 | |||
146 | /** |
||
147 | * Set protected cols |
||
148 | * |
||
149 | * @param array $ignoredTables |
||
150 | * @return Writer |
||
151 | */ |
||
152 | public function setIgnoredTables(array $ignoredTables): Writer |
||
158 | |||
159 | |||
160 | /** |
||
161 | * Set protected cols |
||
162 | * |
||
163 | * @param array $protectedCols |
||
164 | * @return Writer |
||
165 | */ |
||
166 | public function setProtectedCols(array $protectedCols): Writer |
||
172 | |||
173 | |||
174 | /** |
||
175 | * Check if that col has to be ignored |
||
176 | * |
||
177 | * @param string $table |
||
178 | * @param string $col |
||
179 | * @return bool |
||
180 | */ |
||
181 | protected function colIgnored(string $table, string $col): bool |
||
195 | |||
196 | |||
197 | /** |
||
198 | * Get the cols lists from a connection + table |
||
199 | * |
||
200 | * @param string $table |
||
201 | * @return array |
||
202 | */ |
||
203 | protected function getColsList(string $table): array |
||
230 | |||
231 | |||
232 | /** |
||
233 | * Get the table lists from a connection |
||
234 | * |
||
235 | * @return array |
||
236 | */ |
||
237 | protected function getTablesList(): array |
||
253 | |||
254 | |||
255 | /** |
||
256 | * Guess the cols with the guesser |
||
257 | * |
||
258 | * @param string $table |
||
259 | * @param array $cols |
||
260 | * @param GuesserInterface $guesser |
||
261 | * @return array |
||
262 | */ |
||
263 | protected function guessColsAnonType(string $table, array $cols, GuesserInterface $guesser): array |
||
272 | |||
273 | |||
274 | /** |
||
275 | * Check if that table has to be ignored |
||
276 | * |
||
277 | * @param string $table |
||
278 | * @return bool |
||
279 | */ |
||
280 | protected function tableIgnored(string $table): bool |
||
290 | } |
||
291 |