Skip to content

Commit 8bcf543

Browse files
committed
Validate the new version during self-update
1 parent 5aed043 commit 8bcf543

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

box.json.dist

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"KevinGH\\Box\\Compactor\\Json",
55
"KevinGH\\Box\\Compactor\\Php"
66
],
7-
"check-requirements": false,
87
"force-autodiscovery": true,
98
"directories": [
109
"shell"

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"bin/phpbrew"
2323
],
2424
"require": {
25+
"php": "^5.3.9||^7.0||^8.0",
2526
"corneltek/cliframework": "3.0.x-dev#2650a53433854d43b91955e8f967c62ce07869d7",
2627
"corneltek/pearx": "^1.3.5",
2728
"corneltek/curlkit": "^1.0.11",

composer.lock

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/PhpBrew/Command/SelfUpdateCommand.php

+22-1
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,34 @@ public function execute()
5656
chmod($tempFile, 0755);
5757
//todo we can check the hash here in order to make sure we have download the phar successfully
5858

59+
if (!$this->checkRequirements($tempFile)) {
60+
unlink($tempFile);
61+
62+
throw new RuntimeException('Update failed');
63+
}
64+
5965
//move the tmp file to executable path
6066
if (!rename($tempFile, $script)) {
6167
throw new RuntimeException('Update Failed', 3);
6268
}
6369

6470
$this->logger->info('Version updated.');
6571
system($script . ' init');
66-
system($script . ' --version');
72+
}
73+
74+
/**
75+
* Check if the new version is compatible with the current runtime.
76+
*
77+
* This assumes that the binary will check the runtime requirements for any sub-command including `--version`.
78+
*
79+
* @param string $binary The path to the new PHPBrew version binary
80+
*
81+
* @return bool
82+
*/
83+
private function checkRequirements($binary)
84+
{
85+
system(escapeshellcmd($binary) . ' --version', $code);
86+
87+
return $code === 0;
6788
}
6889
}

0 commit comments

Comments
 (0)