Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 24 |
| Scripts | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 24 |
| postAutoloadDump | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
| changeOccurenceOnFile | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 7 |
|||
| changeConsoleKernelOnBootstrapAppFile | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| addTimeZoneVarToConfigApp | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| removeMigrationFromLaravelInstance | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 9 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace Qmp\Laravel\MicroService\Composer; |
| 4 | |
| 5 | use Composer\Script\Event; |
| 6 | use Illuminate\Foundation\Application; |
| 7 | |
| 8 | class Scripts |
| 9 | { |
| 10 | /** |
| 11 | * Handle the post-autoload-dump Composer event. |
| 12 | * |
| 13 | * @param \Composer\Script\Event $event |
| 14 | * @return void |
| 15 | */ |
| 16 | public static function postAutoloadDump(Event $event) |
| 17 | { |
| 18 | self::changeConsoleKernelOnBootstrapAppFile(); |
| 19 | self::addTimeZoneVarToConfigApp(); |
| 20 | self::removeMigrationFromLaravelInstance(); |
| 21 | } |
| 22 | |
| 23 | protected static function changeOccurenceOnFile(string $filename, string $toSearch, string $toReplace) |
| 24 | { |
| 25 | $file = getcwd() . $filename; |
| 26 | $originalContent = file_get_contents($file); |
| 27 | $modifiedContent = str_replace($toSearch,$toReplace,$originalContent); |
| 28 | |
| 29 | if ($modifiedContent !== $originalContent) { |
| 30 | echo "Set \033[0;34m'$toReplace'\033[0m to \033[0;32m'$filename'\033[0m file...\n"; |
| 31 | file_put_contents($file, $modifiedContent); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | protected static function changeConsoleKernelOnBootstrapAppFile() |
| 36 | { |
| 37 | self::changeOccurenceOnFile('/bootstrap/app.php', 'App\\Console\\Kernel', 'Qmp\\Laravel\\MicroService\\Console\\Kernel'); |
| 38 | } |
| 39 | |
| 40 | protected static function addTimeZoneVarToConfigApp() |
| 41 | { |
| 42 | self::changeOccurenceOnFile('/config/app.php', "'UTC'", "env('APP_TZ', 'Europe/Paris')"); |
| 43 | } |
| 44 | |
| 45 | protected static function removeMigrationFromLaravelInstance() |
| 46 | { |
| 47 | $path = getcwd() . '/database/migrations/*'; |
| 48 | $files = glob($path); // get all file names |
| 49 | if (count($files) > 0) { |
| 50 | echo "Remove files from \033[0;34m'$path'\033[0m ...\n"; |
| 51 | foreach($files as $file){ // iterate files |
| 52 | if(is_file($file)) { |
| 53 | echo "Remove \033[0;34m'$file'\033[0m ...\n"; |
| 54 | unlink($file); // delete file |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | } |
| 60 | } |