From 8aef6ecc0fdf10dc3dd35f9579ab661a389b566e Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sun, 31 Aug 2014 14:07:29 +0200 Subject: [PATCH] Update symfony files. --- app/SymfonyRequirements.php | 8 +- app/check.php | 148 +++++++++++++++++++++++++++--------- 2 files changed, 121 insertions(+), 35 deletions(-) diff --git a/app/SymfonyRequirements.php b/app/SymfonyRequirements.php index ed00a6f..25bc938 100644 --- a/app/SymfonyRequirements.php +++ b/app/SymfonyRequirements.php @@ -602,6 +602,12 @@ class SymfonyRequirements extends RequirementCollection 'Install and enable the XML extension.' ); + $this->addRecommendation( + function_exists('filter_var'), + 'filter_var() should be available', + 'Install and enable the filter extension.' + ); + if (!defined('PHP_WINDOWS_VERSION_BUILD')) { $this->addRecommendation( function_exists('posix_isatty'), @@ -662,7 +668,7 @@ class SymfonyRequirements extends RequirementCollection $this->addRecommendation( $accelerator, 'a PHP accelerator should be installed', - 'Install and enable a PHP accelerator like APC (highly recommended).' + 'Install and/or enable a PHP accelerator (highly recommended).' ); if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { diff --git a/app/check.php b/app/check.php index 91b826b..bb0a20e 100644 --- a/app/check.php +++ b/app/check.php @@ -2,61 +2,141 @@ require_once dirname(__FILE__).'/SymfonyRequirements.php'; +$lineSize = 70; $symfonyRequirements = new SymfonyRequirements(); - $iniPath = $symfonyRequirements->getPhpIniConfigPath(); -echo "********************************\n"; -echo "* *\n"; -echo "* Symfony requirements check *\n"; -echo "* *\n"; -echo "********************************\n\n"; +echo_title('Symfony2 Requirements Checker'); -echo $iniPath ? sprintf("* Configuration file used by PHP: %s\n\n", $iniPath) : "* WARNING: No configuration file (php.ini) used by PHP!\n\n"; - -echo "** ATTENTION **\n"; -echo "* The PHP CLI can use a different php.ini file\n"; -echo "* than the one used with your web server.\n"; -if ('\\' == DIRECTORY_SEPARATOR) { - echo "* (especially on the Windows platform)\n"; +echo '> PHP is using the following php.ini file:'.PHP_EOL; +if ($iniPath) { + echo_style('green', ' '.$iniPath); +} else { + echo_style('warning', ' WARNING: No configuration file (php.ini) used by PHP!'); } -echo "* To be on the safe side, please also launch the requirements check\n"; -echo "* from your web server using the web/config.php script.\n"; -echo_title('Mandatory requirements'); +echo PHP_EOL.PHP_EOL; -$checkPassed = true; +echo '> Checking Symfony requirements:'.PHP_EOL.' '; + +$messages = array(); foreach ($symfonyRequirements->getRequirements() as $req) { /** @var $req Requirement */ - echo_requirement($req); - if (!$req->isFulfilled()) { - $checkPassed = false; + if ($helpText = get_error_message($req, $lineSize)) { + echo_style('red', 'E'); + $messages['error'][] = $helpText; + } else { + echo_style('green', '.'); } } -echo_title('Optional recommendations'); +$checkPassed = empty($messages['error']); foreach ($symfonyRequirements->getRecommendations() as $req) { - echo_requirement($req); + if ($helpText = get_error_message($req, $lineSize)) { + echo_style('yellow', 'W'); + $messages['warning'][] = $helpText; + } else { + echo_style('green', '.'); + } } +if ($checkPassed) { + echo_block('success', 'OK', 'Your system is ready to run Symfony2 projects', true); +} else { + echo_block('error', 'ERROR', 'Your system is not ready to run Symfony2 projects', true); + + echo_title('Fix the following mandatory requirements', 'red'); + + foreach ($messages['error'] as $helpText) { + echo ' * '.$helpText.PHP_EOL; + } +} + +if (!empty($messages['warning'])) { + echo_title('Optional recommendations to improve your setup', 'yellow'); + + foreach ($messages['warning'] as $helpText) { + echo ' * '.$helpText.PHP_EOL; + } +} + +echo PHP_EOL; +echo_style('title', 'Note'); +echo ' The command console could use a different php.ini file'.PHP_EOL; +echo_style('title', '~~~~'); +echo ' than the one used with your web server. To be on the'.PHP_EOL; +echo ' safe side, please check the requirements from your web'.PHP_EOL; +echo ' server using the '; +echo_style('yellow', 'web/config.php'); +echo ' script.'.PHP_EOL; +echo PHP_EOL; + exit($checkPassed ? 0 : 1); -/** - * Prints a Requirement instance - */ -function echo_requirement(Requirement $requirement) +function get_error_message(Requirement $requirement, $lineSize) { - $result = $requirement->isFulfilled() ? 'OK' : ($requirement->isOptional() ? 'WARNING' : 'ERROR'); - echo ' ' . str_pad($result, 9); - echo $requirement->getTestMessage() . "\n"; - - if (!$requirement->isFulfilled()) { - echo sprintf(" %s\n\n", $requirement->getHelpText()); + if ($requirement->isFulfilled()) { + return; } + + $errorMessage = wordwrap($requirement->getTestMessage(), $lineSize - 3, PHP_EOL.' ').PHP_EOL; + $errorMessage .= ' > '.wordwrap($requirement->getHelpText(), $lineSize - 5, PHP_EOL.' > ').PHP_EOL; + + return $errorMessage; } -function echo_title($title) +function echo_title($title, $style = null) { - echo "\n** $title **\n\n"; + $style = $style ?: 'title'; + + echo PHP_EOL; + echo_style($style, $title.PHP_EOL); + echo_style($style, str_repeat('~', strlen($title)).PHP_EOL); + echo PHP_EOL; +} + +function echo_style($style, $message) +{ + // ANSI color codes + $styles = array( + 'reset' => "\033[0m", + 'red' => "\033[31m", + 'green' => "\033[32m", + 'yellow' => "\033[33m", + 'error' => "\033[37;41m", + 'success' => "\033[37;42m", + 'title' => "\033[34m", + ); + $supports = has_color_support(); + + echo ($supports ? $styles[$style] : '').$message.($supports ? $styles['reset'] : ''); +} + +function echo_block($style, $title, $message) +{ + $message = ' '.trim($message).' '; + $width = strlen($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); +} + +function has_color_support() +{ + static $support; + + if (null === $support) { + if (DIRECTORY_SEPARATOR == '\\') { + $support = false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI'); + } else { + $support = function_exists('posix_isatty') && @posix_isatty(STDOUT); + } + } + + return $support; }