| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | function patch_composer_json(string $branchname): void |
||
| 6 | { |
||
| 7 | if (!file_exists('symfony/composer.json')) { |
||
| 8 | echo 'symfony/composer.json not found!'.PHP_EOL; |
||
| 9 | exit(-1); |
||
|
0 ignored issues
–
show
|
|||
| 10 | } |
||
| 11 | |||
| 12 | $contents = file_get_contents('symfony/composer.json'); |
||
| 13 | if ($contents === false) { |
||
| 14 | exit(-1); |
||
|
0 ignored issues
–
show
|
|||
| 15 | } |
||
| 16 | |||
| 17 | $json = json_decode($contents, true); |
||
| 18 | $json['repositories'] = [[ |
||
| 19 | 'type' => 'vcs', |
||
| 20 | 'url' => '../', |
||
| 21 | ]]; |
||
| 22 | $json['require']['artprima/prometheus-metrics-bundle'] = 'dev-'.$branchname; |
||
| 23 | $json['require-dev'] = (object)$json['require-dev']; |
||
| 24 | $data = json_encode($json, JSON_PRETTY_PRINT); |
||
| 25 | if ($data === false) { |
||
| 26 | exit(-1); |
||
|
0 ignored issues
–
show
|
|||
| 27 | } |
||
| 28 | |||
| 29 | $result = file_put_contents('symfony/composer.json', $data); |
||
| 30 | if ($result === false) { |
||
| 31 | exit(-1); |
||
|
0 ignored issues
–
show
|
|||
| 32 | } |
||
| 33 | } |
||
| 34 | |||
| 35 | // https://stackoverflow.com/questions/7447472/how-could-i-display-the-current-git-branch-name-at-the-top-of-the-page-of-my-de |
||
| 36 | function get_branch_name(): string |
||
| 37 | { |
||
| 38 | $stringfromfile = file('.git/HEAD', FILE_USE_INCLUDE_PATH); |
||
| 39 | $firstLine = $stringfromfile[0]; //get the string from the array |
||
| 40 | $explodedstring = explode("/", $firstLine, 3); //seperate out by the "/" in the string |
||
| 41 | $branchname = $explodedstring[2]; //get the one that is always the branch name |
||
| 42 | |||
| 43 | return $branchname; |
||
| 44 | } |
||
| 45 | |||
| 46 | patch_composer_json(get_branch_name()); |
||
| 47 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.