modified PHP version check
This commit is contained in:
parent
b877c78716
commit
3571e7888f
116
bin/console
116
bin/console
|
@ -8,118 +8,18 @@ use DI\DependencyException;
|
||||||
use DI\NotFoundException;
|
use DI\NotFoundException;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
error_reporting(error_level: E_ALL & ~E_DEPRECATED);
|
|
||||||
|
|
||||||
if (php_sapi_name() !== 'cli') {
|
if (php_sapi_name() !== 'cli') {
|
||||||
echo 'This application must be run on the command line.' . PHP_EOL;
|
echo 'This application must be run on the command line.' . PHP_EOL;
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check php version (must be >= 8.1)
|
||||||
if (!is_file(filename: dirname(path: __DIR__).'/vendor/autoload.php')) {
|
/** @noinspection PhpArgumentWithoutNamedIdentifierInspection */
|
||||||
die('Required runtime components are missing. Try running "composer install".' . PHP_EOL);
|
if (version_compare(PHP_VERSION, '8.1.0', '<')) {
|
||||||
}
|
echo 'This application requires PHP 8.1 or newer. You are running ' . PHP_VERSION . PHP_EOL;
|
||||||
|
echo 'If you are using KeyHelp, use keyhelp-php81 ' . $argv[0] . ' instead.' . PHP_EOL;
|
||||||
require dirname(path: __DIR__) . '/vendor/autoload.php';
|
exit;
|
||||||
|
|
||||||
|
|
||||||
$shortOpts = 'v::'; // version
|
|
||||||
$shortOpts .= 'q::'; // quiet
|
|
||||||
$shortOpts .= "V::"; // verbose
|
|
||||||
$shortOpts .= "h::"; // help
|
|
||||||
|
|
||||||
$longOpts = [
|
|
||||||
'version::',
|
|
||||||
'quiet::',
|
|
||||||
'verbose::',
|
|
||||||
'help::'
|
|
||||||
];
|
|
||||||
|
|
||||||
$options = getopt(short_options: $shortOpts, long_options: $longOpts, rest_index: $restIndex);
|
|
||||||
|
|
||||||
$arguments = array_slice(array: $argv, offset: $restIndex);
|
|
||||||
|
|
||||||
if (array_key_exists(key: 'v', array: $options) || array_key_exists(key: 'version', array: $options)) {
|
|
||||||
$arguments = 'showVersion';
|
|
||||||
|
|
||||||
$composerJson = json_decode(json: file_get_contents(filename: dirname(path: __DIR__) . '/composer.json'), associative: true);
|
|
||||||
$name = $composerJson['name'];
|
|
||||||
$description = $composerJson['description'];
|
|
||||||
$version = $composerJson['version'];
|
|
||||||
$buildNumber = $composerJson['build_number'];
|
|
||||||
$authorName = $composerJson['authors'][0]['name'];
|
|
||||||
$authorEmail = $composerJson['authors'][0]['email'];
|
|
||||||
|
|
||||||
echo "Name: $name\n";
|
|
||||||
echo "Description: $description\n";
|
|
||||||
echo "Version: $version\n";
|
|
||||||
echo "Build Number: $buildNumber\n";
|
|
||||||
echo "Author: $authorName ($authorEmail)\n";
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (array_key_exists(key: 'h', array: $options) || array_key_exists(key: 'help', array: $options)) {
|
|
||||||
$arguments = "showUsage";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (array_key_exists(key: 'q', array: $options) || array_key_exists(key: 'quiet', array: $options)) {
|
|
||||||
$quiet = true;
|
|
||||||
} else {
|
|
||||||
$quiet = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (array_key_exists(key: 'V', array: $options) || array_key_exists(key: 'verbose', array: $options)) {
|
|
||||||
$verbose = true;
|
|
||||||
} else {
|
|
||||||
$verbose = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
$app = new BindAPI(verbose: $verbose, quiet: $quiet);
|
|
||||||
$app->runCommand(arguments: $arguments);
|
|
||||||
|
|
||||||
} catch (DependencyException|NotFoundException|Exception $e) {
|
|
||||||
echo $e->getMessage() . PHP_EOL;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function confirm(string $message = 'Are you sure? ', array $options = ['y', 'n'], string $default = 'n'): bool
|
|
||||||
{
|
|
||||||
// first $options means true, any other false
|
|
||||||
echo $message, ' (';
|
|
||||||
$first = true;
|
|
||||||
foreach ($options as $option) {
|
|
||||||
// mark default
|
|
||||||
if ($option === $default) {
|
|
||||||
$option = strtoupper(string: $option);
|
|
||||||
}
|
|
||||||
if ($first) {
|
|
||||||
echo $option;
|
|
||||||
$first = false;
|
|
||||||
} else {
|
|
||||||
echo '/', $option;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
echo '): ';
|
|
||||||
|
|
||||||
$handle = fopen(filename: "php://stdin", mode: 'r');
|
|
||||||
$line = trim(string: fgetc(stream: $handle));
|
|
||||||
fclose(stream: $handle);
|
|
||||||
|
|
||||||
if ($line == '') {
|
|
||||||
// enter
|
|
||||||
$line = $default;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($line == $options[0]) {
|
|
||||||
$result = true;
|
|
||||||
} else {
|
|
||||||
$result = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @noinspection PhpArgumentWithoutNamedIdentifierInspection */
|
||||||
|
require dirname(__DIR__, 1) . '/src/Util/Console.php';
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"name": "24unix/bindapi",
|
"name": "24unix/bindapi",
|
||||||
"description": "manage Bind9 DNS server via REST API",
|
"description": "manage Bind9 DNS server via REST API",
|
||||||
"version": "2023.0.1",
|
"version": "2023.0.1",
|
||||||
"build_number": "323",
|
"build_number": "324",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Micha Espey",
|
"name": "Micha Espey",
|
||||||
|
@ -50,6 +50,6 @@
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"escapestudios/symfony2-coding-standard": "3.x-dev",
|
"escapestudios/symfony2-coding-standard": "3.x-dev",
|
||||||
"phpunit/phpunit": "^9.5"
|
"phpunit/phpunit": "10"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,115 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Controller\BindAPI;
|
||||||
|
use DI\DependencyException;
|
||||||
|
use DI\NotFoundException;
|
||||||
|
|
||||||
|
error_reporting(error_level: E_ALL & ~E_DEPRECATED);
|
||||||
|
|
||||||
|
if (!is_file(filename: dirname(path: __DIR__).'/vendor/autoload.php')) {
|
||||||
|
die('Required runtime components are missing. Try running "composer install".' . PHP_EOL);
|
||||||
|
}
|
||||||
|
|
||||||
|
require dirname(path: __DIR__) . '/vendor/autoload.php';
|
||||||
|
|
||||||
|
|
||||||
|
$shortOpts = 'v::'; // version
|
||||||
|
$shortOpts .= 'q::'; // quiet
|
||||||
|
$shortOpts .= "V::"; // verbose
|
||||||
|
$shortOpts .= "h::"; // help
|
||||||
|
|
||||||
|
$longOpts = [
|
||||||
|
'version::',
|
||||||
|
'quiet::',
|
||||||
|
'verbose::',
|
||||||
|
'help::'
|
||||||
|
];
|
||||||
|
|
||||||
|
$options = getopt(short_options: $shortOpts, long_options: $longOpts, rest_index: $restIndex);
|
||||||
|
|
||||||
|
$arguments = array_slice(array: $argv, offset: $restIndex);
|
||||||
|
|
||||||
|
if (array_key_exists(key: 'v', array: $options) || array_key_exists(key: 'version', array: $options)) {
|
||||||
|
$arguments = 'showVersion';
|
||||||
|
|
||||||
|
$composerJson = json_decode(json: file_get_contents(filename: dirname(path: __DIR__) . '/composer.json'), associative: true);
|
||||||
|
$name = $composerJson['name'];
|
||||||
|
$description = $composerJson['description'];
|
||||||
|
$version = $composerJson['version'];
|
||||||
|
$buildNumber = $composerJson['build_number'];
|
||||||
|
$authorName = $composerJson['authors'][0]['name'];
|
||||||
|
$authorEmail = $composerJson['authors'][0]['email'];
|
||||||
|
|
||||||
|
echo "Name: $name\n";
|
||||||
|
echo "Description: $description\n";
|
||||||
|
echo "Version: $version\n";
|
||||||
|
echo "Build Number: $buildNumber\n";
|
||||||
|
echo "Author: $authorName ($authorEmail)\n";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists(key: 'h', array: $options) || array_key_exists(key: 'help', array: $options)) {
|
||||||
|
$arguments = "showUsage";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists(key: 'q', array: $options) || array_key_exists(key: 'quiet', array: $options)) {
|
||||||
|
$quiet = true;
|
||||||
|
} else {
|
||||||
|
$quiet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (array_key_exists(key: 'V', array: $options) || array_key_exists(key: 'verbose', array: $options)) {
|
||||||
|
$verbose = true;
|
||||||
|
} else {
|
||||||
|
$verbose = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
$app = new BindAPI(verbose: $verbose, quiet: $quiet);
|
||||||
|
$app->runCommand(arguments: $arguments);
|
||||||
|
|
||||||
|
} catch (DependencyException|NotFoundException|Exception $e) {
|
||||||
|
echo $e->getMessage() . PHP_EOL;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function confirm(string $message = 'Are you sure? ', array $options = ['y', 'n'], string $default = 'n'): bool
|
||||||
|
{
|
||||||
|
// first $options means true, any other false
|
||||||
|
echo $message, ' (';
|
||||||
|
$first = true;
|
||||||
|
foreach ($options as $option) {
|
||||||
|
// mark default
|
||||||
|
if ($option === $default) {
|
||||||
|
$option = strtoupper(string: $option);
|
||||||
|
}
|
||||||
|
if ($first) {
|
||||||
|
echo $option;
|
||||||
|
$first = false;
|
||||||
|
} else {
|
||||||
|
echo '/', $option;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo '): ';
|
||||||
|
|
||||||
|
$handle = fopen(filename: "php://stdin", mode: 'r');
|
||||||
|
$line = trim(string: fgetc(stream: $handle));
|
||||||
|
fclose(stream: $handle);
|
||||||
|
|
||||||
|
if ($line == '') {
|
||||||
|
// enter
|
||||||
|
$line = $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($line == $options[0]) {
|
||||||
|
$result = true;
|
||||||
|
} else {
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue