1 | <?php |
||
31 | class Util |
||
32 | { |
||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | const DATE_FORMAT = 'YmdHis'; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | const MIGRATION_FILE_NAME_PATTERN = '/^\d+_([\w_]+).php$/i'; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | const SEED_FILE_NAME_PATTERN = '/^([A-Z][a-z0-9]+).php$/i'; |
||
47 | |||
48 | /** |
||
49 | * Gets the current timestamp string, in UTC. |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | 15 | public static function getCurrentTimestamp() |
|
59 | |||
60 | /** |
||
61 | * Gets an array of all the existing migration class names. |
||
62 | * |
||
63 | * @return string[] |
||
64 | 15 | */ |
|
65 | public static function getExistingMigrationClassNames($path) |
||
84 | |||
85 | /** |
||
86 | * Get the version from the beginning of a file name. |
||
87 | * |
||
88 | * @param string $fileName File Name |
||
89 | * @return string |
||
90 | 395 | */ |
|
91 | public static function getVersionFromFileName($fileName) |
||
98 | |||
99 | /** |
||
100 | * Turn migration names like 'CreateUserTable' into file names like |
||
101 | * '12345678901234_create_user_table.php' or 'LimitResourceNamesTo30Chars' into |
||
102 | * '12345678901234_limit_resource_names_to_30_chars.php'. |
||
103 | * |
||
104 | * @param string $className Class Name |
||
105 | 14 | * @return string |
|
106 | */ |
||
107 | 14 | public static function mapClassNameToFileName($className) |
|
115 | |||
116 | /** |
||
117 | * Turn file names like '12345678901234_create_user_table.php' into class |
||
118 | * names like 'CreateUserTable'. |
||
119 | * |
||
120 | 391 | * @param string $fileName File Name |
|
121 | * @return string |
||
122 | 391 | */ |
|
123 | 391 | public static function mapFileNameToClassName($fileName) |
|
132 | |||
133 | /** |
||
134 | * Check if a migration class name is unique regardless of the |
||
135 | * timestamp. |
||
136 | * |
||
137 | * This method takes a class name and a path to a migrations directory. |
||
138 | * |
||
139 | * Migration class names must be in CamelCase format. |
||
140 | * e.g: CreateUserTable or AddIndexToPostsTable. |
||
141 | * |
||
142 | * Single words are not allowed on their own. |
||
143 | * |
||
144 | * @param string $className Class Name |
||
145 | 13 | * @param string $path Path |
|
146 | * @return bool |
||
147 | 13 | */ |
|
148 | 13 | public static function isUniqueMigrationClassName($className, $path) |
|
154 | |||
155 | /** |
||
156 | * Check if a migration/seed class name is valid. |
||
157 | * |
||
158 | * Migration & Seed class names must be in CamelCase format. |
||
159 | * e.g: CreateUserTable, AddIndexToPostsTable or UserSeeder. |
||
160 | * |
||
161 | * Single words are not allowed on their own. |
||
162 | 16 | * |
|
163 | * @param string $className Class Name |
||
164 | 16 | * @return bool |
|
165 | */ |
||
166 | public static function isValidPhinxClassName($className) |
||
170 | |||
171 | /** |
||
172 | * Check if a migration file name is valid. |
||
173 | 387 | * |
|
174 | * @param string $fileName File Name |
||
175 | 387 | * @return bool |
|
176 | 387 | */ |
|
177 | public static function isValidMigrationFileName($fileName) |
||
183 | |||
184 | /** |
||
185 | 11 | * Check if a seed file name is valid. |
|
186 | * |
||
187 | 11 | * @param string $fileName File Name |
|
188 | 11 | * @return bool |
|
189 | */ |
||
190 | public static function isValidSeedFileName($fileName) |
||
196 | |||
197 | 33 | /** |
|
198 | * Expands a set of paths with curly braces (if supported by the OS). |
||
199 | 33 | * |
|
200 | * @param array $paths |
||
201 | 33 | * @return array |
|
202 | 33 | */ |
|
203 | 33 | public static function globAll(array $paths) |
|
204 | { |
||
205 | 33 | $result = []; |
|
206 | |||
207 | foreach ($paths as $path) { |
||
208 | $result = array_merge($result, static::glob($path)); |
||
209 | } |
||
210 | |||
211 | return $result; |
||
212 | } |
||
213 | |||
214 | 431 | /** |
|
215 | * Expands a path with curly braces (if supported by the OS). |
||
216 | 431 | * |
|
217 | * @param string $path |
||
218 | * @return array |
||
219 | */ |
||
220 | public static function glob($path) |
||
221 | { |
||
222 | return glob($path, defined('GLOB_BRACE') ? GLOB_BRACE : 0); |
||
223 | } |
||
224 | |||
225 | /** |
||
226 | * Takes the path to a php file and attempts to include it if readable |
||
227 | * |
||
228 | * @return string |
||
229 | */ |
||
230 | public static function loadPhpFile($filename) |
||
249 | |||
250 | /** |
||
251 | * Given an array of paths, return all unique PHP files that are in them |
||
252 | * |
||
253 | * @param string[] $paths array of paths to get php files |
||
254 | * @return string[] |
||
255 | */ |
||
256 | public static function getFiles($paths) |
||
269 | } |
||
270 |