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 | 7 | */ |
|
62 | public function protectCols(bool $protect): Writer |
||
68 | |||
69 | /** |
||
70 | * Set protected cols |
||
71 | * |
||
72 | * @param array $cols |
||
73 | 5 | */ |
|
74 | public function setProtectedCols(array $cols): Writer |
||
80 | |||
81 | /** |
||
82 | * Set protected cols |
||
83 | * |
||
84 | * @param array $tables |
||
85 | 5 | */ |
|
86 | public function setIgnoredTables(array $tables): Writer |
||
92 | |||
93 | /** |
||
94 | * Get Tables List added to the conf |
||
95 | * |
||
96 | * @return array |
||
97 | 1 | */ |
|
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 | 11 | */ |
|
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 | 5 | */ |
|
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 | 10 | * |
|
161 | * @return bool |
||
162 | 10 | */ |
|
163 | 2 | protected function colIgnored(string $table, string $col, bool $isPrimary): bool |
|
177 | |||
178 | /** |
||
179 | * Get the table lists from a connection |
||
180 | 8 | * |
|
181 | * @param \PDO $pdo |
||
182 | 8 | * |
|
183 | 2 | * @return array |
|
184 | */ |
||
185 | protected function getTablesList(\PDO $pdo): array |
||
201 | |||
202 | 11 | /** |
|
203 | * Get the cols lists from a connection + table |
||
204 | 11 | * |
|
205 | * @param \PDO $pdo |
||
206 | 11 | * @param string $table |
|
207 | 11 | * |
|
208 | 10 | * @return array |
|
209 | 2 | */ |
|
210 | 2 | protected function getColsList(\PDO $pdo, string $table): array |
|
253 | 4 | ||
254 | /** |
||
255 | 7 | * Guess the cols with the guesser |
|
256 | 7 | * |
|
257 | 7 | * @param string $table |
|
258 | 7 | * @param array $cols |
|
259 | 7 | * @param GuesserInterface $guesser |
|
260 | * |
||
261 | 8 | * @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 | 6 | protected function tableIgnored(string $table): bool |
|
290 | } |
||
291 |