1 | <?php |
||
27 | class Writer |
||
28 | { |
||
29 | /** |
||
30 | * Should I protect the cols ? That will also protect the Primary Keys |
||
31 | * |
||
32 | * @var boolean |
||
33 | */ |
||
34 | protected $protectCols = true; |
||
35 | |||
36 | /** |
||
37 | * List the cols to protected. Could containe regexp |
||
38 | * |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $protectedCols = ['id', 'parent_id']; |
||
42 | |||
43 | /** |
||
44 | * List of tables patterns to ignore |
||
45 | * |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $ignoredTables = []; |
||
49 | |||
50 | /** |
||
51 | * Store the tables added to the conf |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $tablesInConf = []; |
||
56 | |||
57 | /** |
||
58 | * Set Change Id to ask the writer to ignore (or not) the protectedCols |
||
59 | * |
||
60 | * @param bool |
||
61 | */ |
||
62 | public function protectCols(bool $protect): Writer |
||
68 | |||
69 | /** |
||
70 | * Set protected cols |
||
71 | * |
||
72 | * @param array $cols |
||
73 | */ |
||
74 | public function setProtectedCols(array $cols): Writer |
||
80 | |||
81 | /** |
||
82 | * Set protected cols |
||
83 | * |
||
84 | * @param array $tables |
||
85 | */ |
||
86 | public function setIgnoredTables(array $tables): Writer |
||
92 | |||
93 | /** |
||
94 | * Get Tables List added to the conf |
||
95 | * |
||
96 | * @return array |
||
97 | */ |
||
98 | public function getTablesInConf(): array |
||
102 | |||
103 | /** |
||
104 | * Generate the configuration by reading tables + cols |
||
105 | * |
||
106 | * @param \PDO $pdo |
||
107 | * @param GuesserInterface $guesser |
||
108 | * |
||
109 | * @return array |
||
110 | */ |
||
111 | public function generateConfFromDB(\PDO $pdo, GuesserInterface $guesser): array |
||
138 | |||
139 | /** |
||
140 | * Save the data to the file as YAML |
||
141 | * |
||
142 | * @param array $data |
||
143 | * @param string $filename |
||
144 | */ |
||
145 | public function save(array $data, string $filename) |
||
153 | |||
154 | /** |
||
155 | * Check if that col has to be ignored |
||
156 | * |
||
157 | * @param string $table |
||
158 | * @param string $col |
||
159 | * @param bool $isPrimary |
||
160 | * |
||
161 | * @return bool |
||
162 | */ |
||
163 | protected function colIgnored(string $table, string $col, bool $isPrimary): bool |
||
177 | |||
178 | /** |
||
179 | * Get the table lists from a connection |
||
180 | * |
||
181 | * @param \PDO $pdo |
||
182 | * |
||
183 | * @return array |
||
184 | */ |
||
185 | protected function getTablesList(\PDO $pdo): array |
||
201 | |||
202 | /** |
||
203 | * Get the cols lists from a connection + table |
||
204 | * |
||
205 | * @param \PDO $pdo |
||
206 | * @param string $table |
||
207 | * |
||
208 | * @return array |
||
209 | */ |
||
210 | protected function getColsList(\PDO $pdo, string $table): array |
||
253 | |||
254 | /** |
||
255 | * Guess the cols with the guesser |
||
256 | * |
||
257 | * @param string $table |
||
258 | * @param array $cols |
||
259 | * @param GuesserInterface $guesser |
||
260 | * |
||
261 | * @return array |
||
262 | */ |
||
263 | protected function guessColsAnonType(string $table, array $cols, GuesserInterface $guesser): array |
||
272 | |||
273 | /** |
||
274 | * Check if that table has to be ignored |
||
275 | * |
||
276 | * @param string $table |
||
277 | * |
||
278 | * @return bool |
||
279 | */ |
||
280 | protected function tableIgnored(string $table): bool |
||
290 | } |
||
291 |