name; $description = $composerJson->description; $version = $composerJson->version; $buildNumber = $composerJson->build_number; $authors = $composerJson->authors; // currently only one author, so just handle only first entry $authorName = $authors[0]->name; $authorEmail = $authors[0]->email; echo "Name: $name" . PHP_EOL; echo "Description: $description" . PHP_EOL; echo "Version: $version" . PHP_EOL; echo "Build Number: $buildNumber" . PHP_EOL; echo "Author: $authorName ($authorEmail)" . PHP_EOL; 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; } try { $app = new BindAPI(quiet: $quiet); } catch (Exception $e) { echo 'Could not initialize the application: ' . $e->getMessage() . PHP_EOL; exit(1); } try { $app->runCommand(arguments: $arguments); } catch (Exception $e) { $exceptionMessage = $e->getMessage(); preg_match(pattern: '/\[1045]/', subject: $exceptionMessage, matches: $matches); if (!empty($matches)) { echo 'Access was denied for a user when trying to access the database.' . PHP_EOL; } else { echo 'The error message could not be parsed.'; echo $exceptionMessage . 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; }