From 96c3da0761fab0800397fbb5154992c027750780 Mon Sep 17 00:00:00 2001 From: Aleku22 Date: Mon, 10 Oct 2016 00:06:18 +0200 Subject: [PATCH 1/3] - first commit --- bin/symfony_requirements | 13 +- var/SymfonyRequirements.php | 74 +++++++++--- web/config.php | 229 ++++++++++++++++++++++++++++++++++-- 3 files changed, 283 insertions(+), 33 deletions(-) diff --git a/bin/symfony_requirements b/bin/symfony_requirements index 8825a96..a7bf65a 100755 --- a/bin/symfony_requirements +++ b/bin/symfony_requirements @@ -22,7 +22,6 @@ echo '> Checking Symfony requirements:'.PHP_EOL.' '; $messages = array(); foreach ($symfonyRequirements->getRequirements() as $req) { - /** @var $req Requirement */ if ($helpText = get_error_message($req, $lineSize)) { echo_style('red', 'E'); $messages['error'][] = $helpText; @@ -121,10 +120,14 @@ function echo_block($style, $title, $message) echo PHP_EOL.PHP_EOL; - echo_style($style, str_repeat(' ', $width).PHP_EOL); - echo_style($style, str_pad(' ['.$title.']', $width, ' ', STR_PAD_RIGHT).PHP_EOL); - echo_style($style, str_pad($message, $width, ' ', STR_PAD_RIGHT).PHP_EOL); - echo_style($style, str_repeat(' ', $width).PHP_EOL); + echo_style($style, str_repeat(' ', $width)); + echo PHP_EOL; + echo_style($style, str_pad(' ['.$title.']', $width, ' ', STR_PAD_RIGHT)); + echo PHP_EOL; + echo_style($style, $message); + echo PHP_EOL; + echo_style($style, str_repeat(' ', $width)); + echo PHP_EOL; } function has_color_support() diff --git a/var/SymfonyRequirements.php b/var/SymfonyRequirements.php index 0a5de54..7e7723a 100644 --- a/var/SymfonyRequirements.php +++ b/var/SymfonyRequirements.php @@ -168,6 +168,9 @@ public function __construct($cfgName, $evaluation, $approveCfgAbsence = false, $ */ class RequirementCollection implements IteratorAggregate { + /** + * @var Requirement[] + */ private $requirements = array(); /** @@ -265,7 +268,7 @@ public function addCollection(RequirementCollection $collection) /** * Returns both requirements and recommendations. * - * @return array Array of Requirement instances + * @return Requirement[] */ public function all() { @@ -275,7 +278,7 @@ public function all() /** * Returns all mandatory requirements. * - * @return array Array of Requirement instances + * @return Requirement[] */ public function getRequirements() { @@ -292,7 +295,7 @@ public function getRequirements() /** * Returns the mandatory requirements that were not met. * - * @return array Array of Requirement instances + * @return Requirement[] */ public function getFailedRequirements() { @@ -309,7 +312,7 @@ public function getFailedRequirements() /** * Returns all optional recommendations. * - * @return array Array of Requirement instances + * @return Requirement[] */ public function getRecommendations() { @@ -326,7 +329,7 @@ public function getRecommendations() /** * Returns the recommendations that were not met. * - * @return array Array of Requirement instances + * @return Requirement[] */ public function getFailedRecommendations() { @@ -376,7 +379,8 @@ public function getPhpIniConfigPath() */ class SymfonyRequirements extends RequirementCollection { - const REQUIRED_PHP_VERSION = '5.3.3'; + const LEGACY_REQUIRED_PHP_VERSION = '5.3.3'; + const REQUIRED_PHP_VERSION = '5.5.9'; /** * Constructor that initializes the requirements. @@ -386,16 +390,26 @@ public function __construct() /* mandatory requirements follow */ $installedPhpVersion = phpversion(); + $requiredPhpVersion = $this->getPhpRequiredVersion(); - $this->addRequirement( - version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>='), - sprintf('PHP version must be at least %s (%s installed)', self::REQUIRED_PHP_VERSION, $installedPhpVersion), - sprintf('You are running PHP version "%s", but Symfony needs at least PHP "%s" to run. - Before using Symfony, upgrade your PHP installation, preferably to the latest version.', - $installedPhpVersion, self::REQUIRED_PHP_VERSION), - sprintf('Install PHP %s or newer (installed version is %s)', self::REQUIRED_PHP_VERSION, $installedPhpVersion) + $this->addRecommendation( + $requiredPhpVersion, + 'Vendors should be installed in order to check all requirements.', + 'Run the composer install command.', + 'Run the "composer install" command.' ); + if (false !== $requiredPhpVersion) { + $this->addRequirement( + version_compare($installedPhpVersion, $requiredPhpVersion, '>='), + sprintf('PHP version must be at least %s (%s installed)', $requiredPhpVersion, $installedPhpVersion), + sprintf('You are running PHP version "%s", but Symfony needs at least PHP "%s" to run. + Before using Symfony, upgrade your PHP installation, preferably to the latest version.', + $installedPhpVersion, $requiredPhpVersion), + sprintf('Install PHP %s or newer (installed version is %s)', $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', @@ -433,7 +447,7 @@ public function __construct() ); } - if (version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>=')) { + if (false !== $requiredPhpVersion && version_compare($installedPhpVersion, $requiredPhpVersion, '>=')) { $timezones = array(); foreach (DateTimeZone::listAbbreviations() as $abbreviations) { foreach ($abbreviations as $abbreviation) { @@ -689,7 +703,7 @@ function_exists('posix_isatty'), $this->addRecommendation( \Symfony\Component\Intl\Intl::getIcuDataVersion() === \Symfony\Component\Intl\Intl::getIcuVersion(), sprintf('intl ICU version installed on your system (%s) does not match the ICU data bundled with Symfony (%s)', \Symfony\Component\Intl\Intl::getIcuVersion(), \Symfony\Component\Intl\Intl::getIcuDataVersion()), - 'To avoid internationalization data incosistencies upgrade the symfony/intl component.' + 'To avoid internationalization data inconsistencies upgrade the symfony/intl component.' ); } } @@ -725,9 +739,9 @@ function_exists('posix_isatty'), if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $this->addRecommendation( - $this->getRealpathCacheSize() > 1000, - 'realpath_cache_size should be above 1024 in php.ini', - 'Set "realpath_cache_size" to e.g. "1024" in php.ini* to improve performance on windows.' + $this->getRealpathCacheSize() >= 5 * 1024 * 1024, + 'realpath_cache_size should be at least 5M in php.ini', + 'Setting "realpath_cache_size" to e.g. "5242880" or "5M" in php.ini* may improve performance on Windows significantly in some cases.' ); } @@ -778,4 +792,28 @@ protected function getRealpathCacheSize() return (int) $size; } } + + /** + * Defines PHP required version from Symfony version. + * + * @return string|false The PHP required version or false if it could not be guessed + */ + protected function getPhpRequiredVersion() + { + if (!file_exists($path = __DIR__.'/../composer.lock')) { + return false; + } + + $composerLock = json_decode(file_get_contents($path), true); + foreach ($composerLock['packages'] as $package) { + $name = $package['name']; + if ('symfony/symfony' !== $name && 'symfony/http-kernel' !== $name) { + continue; + } + + return (int) $package['version'][1] > 2 ? self::REQUIRED_PHP_VERSION : self::LEGACY_REQUIRED_PHP_VERSION; + } + + return false; + } } diff --git a/web/config.php b/web/config.php index 5e36d79..a031a3a 100644 --- a/web/config.php +++ b/web/config.php @@ -28,6 +28,8 @@ $majorProblems = $symfonyRequirements->getFailedRequirements(); $minorProblems = $symfonyRequirements->getFailedRecommendations(); +$hasMajorProblems = (bool) count($majorProblems); +$hasMinorProblems = (bool) count($minorProblems); ?> @@ -36,9 +38,216 @@ Symfony Configuration Checker - - -