diff --git a/bin/php-scoper b/bin/php-scoper
index 0aef0ad95..16d7316d1 100755
--- a/bin/php-scoper
+++ b/bin/php-scoper
@@ -56,9 +56,13 @@ $isVeryVerbose = array_reduce(
false
);
-//if ('phar:' === substr(__FILE__, 0, 5)) {
- check_requirements($autoload, $isVeryVerbose);
-//}
+if ('phar:' === substr(__FILE__, 0, 5)) {
+ $checkPassed = check_requirements($autoload, $isVeryVerbose);
+
+ if (false === $checkPassed) {
+ exit(1);
+ }
+}
$app = create_application();
diff --git a/src/Autoload/Requirements.php b/src/Autoload/Requirements.php
index 216d47a63..1cbe916fd 100644
--- a/src/Autoload/Requirements.php
+++ b/src/Autoload/Requirements.php
@@ -63,19 +63,12 @@ private function addPhpVersionRequirement(array $composerConfig)
$this->addRequirement(
Semver::satisfies(phpversion(), $requiredPhpVersion),
sprintf(
- 'PHP version must satisfies %s (%s installed)',
+ 'PHP version must satisfies "%s" ("%s" installed)',
$requiredPhpVersion,
$installedPhpVersion
),
- '',
''
);
-
- $this->addRequirement(
- version_compare($installedPhpVersion, '5.3.16', '!='),
- 'PHP version must not be 5.3.16 as Symfony won\'t work properly with it',
- 'Install PHP 5.3.17 or newer (or downgrade to an earlier PHP version)'
- );
}
private function addExtensionRequirements(array $composerConfig)
@@ -95,10 +88,9 @@ private function addExtensionRequirement($extension)
$this->addRequirement(
extension_loaded($extension),
sprintf(
- 'The extension %s must be enabled.',
+ 'The extension "%s" must be enabled.',
$extension
),
- '',
''
);
}
diff --git a/src/check.php b/src/check.php
index 7281f3309..cc46e8976 100644
--- a/src/check.php
+++ b/src/check.php
@@ -29,18 +29,37 @@ function check_requirements($autoload, $verbose)
$requirements = new Requirements(dirname(dirname(realpath($autoload))));
$iniPath = $requirements->getPhpIniPath();
+ $checkPassed = array_reduce(
+ $requirements->getRequirements(),
+ /**
+ * @param bool $checkPassed
+ * @param Requirement $requirement
+ *
+ * @return bool
+ */
+ function ($checkPassed, Requirement $requirement) use ($lineSize) {
+ return $checkPassed || null ===get_error_message($requirement, $lineSize);
+ },
+ false
+ );
+
+ if (false === $checkPassed) {
+ // Override the default verbosity to output errors regardless of the verbosity asked by the user
+ $verbose = true;
+ }
+
echo_title('PHP-Scoper Requirements Checker', null, $verbose);
- echo '> PHP is using the following php.ini file:' . PHP_EOL;
+ vecho('> PHP is using the following php.ini file:' . PHP_EOL, $verbose);
+
if ($iniPath) {
echo_style('green', ' ' . $iniPath, $verbose);
} else {
echo_style('yellow', ' WARNING: No configuration file (php.ini) used by PHP!', $verbose);
}
- echo PHP_EOL . PHP_EOL;
-
- echo '> Checking PHP-Scoper requirements:' . PHP_EOL . ' ';
+ vecho(PHP_EOL . PHP_EOL, $verbose);
+ vecho('> Checking PHP-Scoper requirements:' . PHP_EOL . ' ', $verbose);
$messages = [];
@@ -53,8 +72,6 @@ function check_requirements($autoload, $verbose)
}
}
- $checkPassed = empty($messages['error']);
-
foreach ($requirements->getRecommendations() as $requirement) {
if ($helpText = get_error_message($requirement, $lineSize)) {
echo_style('yellow', 'W', $verbose);
@@ -67,12 +84,12 @@ function check_requirements($autoload, $verbose)
if ($checkPassed) {
echo_block('success', 'OK', 'Your system is ready to run PHP-Scoper.', $verbose);
} else {
- echo_block('error', 'ERROR', 'Your system is not ready to run Symfony projects', $verbose);
+ echo_block('error', 'ERROR', 'Your system is not ready to run PHP-Scoper', $verbose);
echo_title('Fix the following mandatory requirements', 'red', $verbose);
foreach ($messages['error'] as $helpText) {
- echo ' * ' . $helpText . PHP_EOL;
+ vecho(' * ' . $helpText . PHP_EOL, $verbose);
}
}
@@ -80,13 +97,22 @@ function check_requirements($autoload, $verbose)
echo_title('Optional recommendations to improve your setup', 'yellow', $verbose);
foreach ($messages['warning'] as $helpText) {
- echo ' * ' . $helpText . PHP_EOL;
+ vecho(' * ' . $helpText . PHP_EOL, $verbose);
}
}
return $checkPassed;
}
+function vecho($message, $verbose)
+{
+ if (false === $verbose) {
+ return;
+ }
+
+ echo $message;
+}
+
/**
* @param Requirement $requirement
* @param int $lineSize
@@ -99,7 +125,10 @@ function get_error_message(Requirement $requirement, $lineSize)
}
$errorMessage = wordwrap($requirement->getTestMessage(), $lineSize - 3, PHP_EOL.' ').PHP_EOL;
- $errorMessage .= ' > '.wordwrap($requirement->getHelpText(), $lineSize - 5, PHP_EOL.' > ').PHP_EOL;
+
+ if ('' !== $requirement->getHelpText()) {
+ $errorMessage .= ' > '.wordwrap($requirement->getHelpText(), $lineSize - 5, PHP_EOL.' > ').PHP_EOL;
+ }
return $errorMessage;
}