Skip to content

Commit

Permalink
[CMS-449] Graceful version handling (#2267)
Browse files Browse the repository at this point in the history
* Print message and exit for PHP <7.0 or >=8.1

* Encourage updating PHP, soft 8.1 incompatibility msg

* Semi-firm PHP 8.1+ support fail
  • Loading branch information
namespacebrian authored Dec 6, 2021
1 parent c4c5495 commit 7a3a448
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions bin/terminus
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@
* - Exits with a status code
*/

// Version compatibility check and messaging
if (version_compare(PHP_VERSION, '7.4.0', '<') === true) {
echo "\n";
echo 'Sorry, your PHP version (' . PHP_VERSION . ') is no longer supported.' . "\n";
echo 'Upgrade to PHP 7.4 or newer to use Terminus 3. For PHP versions prior to 7.4, downgrade to Terminus 2.x.'; echo "\n\n";
exit(1);
} elseif (version_compare(PHP_VERSION, '8.1.0', '>=') === true) {
echo "\n";
echo 'PHP 8.1+ is not supported by this version of Terminus.' . "\n";
echo 'Check for new versions at https://github.com/pantheon-systems/terminus/releases' . "\n";
echo "\n";
if (!getenv('TERMINUS_ALLOW_UNSUPPORTED_NEWER_PHP')) {
echo 'Set environment variable TERMINUS_ALLOW_UNSUPPORTED_NEWER_PHP to try continuing anyway.' . "\n";
echo "Stopping.\n\n";
exit(1);
}
}

// This variable is automatically managed via updateDependenciesversion() in /RoboFile.php,
// which is run after every call to composer update.
$terminusPluginsDependenciesVersion = '2512c16';
Expand All @@ -31,10 +49,6 @@ if (empty($home) && !empty($_SERVER['HOMEDRIVE']) && !empty($_SERVER['HOMEPATH']
}

$pharPath = \Phar::running(true);
if (version_compare(PHP_VERSION, '7.4.0', '<=') === true) {
throw new \PharIo\Version\InvalidVersionException("Sorry, but you need to upgrade PHP to version 7.4 or greater.");
}

if ($pharPath) {
include_once("$pharPath/vendor/autoload.php");
} elseif (file_exists($path = __DIR__ . '/../vendor/autoload.php')
Expand Down

0 comments on commit 7a3a448

Please sign in to comment.