Daniel@0: getPhpIniConfigPath(); Daniel@0: Daniel@0: echo_title('Symfony2 Requirements Checker'); Daniel@0: Daniel@0: echo '> PHP is using the following php.ini file:'.PHP_EOL; Daniel@0: if ($iniPath) { Daniel@0: echo_style('green', ' '.$iniPath); Daniel@0: } else { Daniel@0: echo_style('warning', ' WARNING: No configuration file (php.ini) used by PHP!'); Daniel@0: } Daniel@0: Daniel@0: echo PHP_EOL.PHP_EOL; Daniel@0: Daniel@0: echo '> Checking Symfony requirements:'.PHP_EOL.' '; Daniel@0: Daniel@0: $messages = array(); Daniel@0: foreach ($symfonyRequirements->getRequirements() as $req) { Daniel@0: /** @var $req Requirement */ Daniel@0: if ($helpText = get_error_message($req, $lineSize)) { Daniel@0: echo_style('red', 'E'); Daniel@0: $messages['error'][] = $helpText; Daniel@0: } else { Daniel@0: echo_style('green', '.'); Daniel@0: } Daniel@0: } Daniel@0: Daniel@0: $checkPassed = empty($messages['error']); Daniel@0: Daniel@0: foreach ($symfonyRequirements->getRecommendations() as $req) { Daniel@0: if ($helpText = get_error_message($req, $lineSize)) { Daniel@0: echo_style('yellow', 'W'); Daniel@0: $messages['warning'][] = $helpText; Daniel@0: } else { Daniel@0: echo_style('green', '.'); Daniel@0: } Daniel@0: } Daniel@0: Daniel@0: if ($checkPassed) { Daniel@0: echo_block('success', 'OK', 'Your system is ready to run Symfony2 projects', true); Daniel@0: } else { Daniel@0: echo_block('error', 'ERROR', 'Your system is not ready to run Symfony2 projects', true); Daniel@0: Daniel@0: echo_title('Fix the following mandatory requirements', 'red'); Daniel@0: Daniel@0: foreach ($messages['error'] as $helpText) { Daniel@0: echo ' * '.$helpText.PHP_EOL; Daniel@0: } Daniel@0: } Daniel@0: Daniel@0: if (!empty($messages['warning'])) { Daniel@0: echo_title('Optional recommendations to improve your setup', 'yellow'); Daniel@0: Daniel@0: foreach ($messages['warning'] as $helpText) { Daniel@0: echo ' * '.$helpText.PHP_EOL; Daniel@0: } Daniel@0: } Daniel@0: Daniel@0: echo PHP_EOL; Daniel@0: echo_style('title', 'Note'); Daniel@0: echo ' The command console could use a different php.ini file'.PHP_EOL; Daniel@0: echo_style('title', '~~~~'); Daniel@0: echo ' than the one used with your web server. To be on the'.PHP_EOL; Daniel@0: echo ' safe side, please check the requirements from your web'.PHP_EOL; Daniel@0: echo ' server using the '; Daniel@0: echo_style('yellow', 'web/config.php'); Daniel@0: echo ' script.'.PHP_EOL; Daniel@0: echo PHP_EOL; Daniel@0: Daniel@0: exit($checkPassed ? 0 : 1); Daniel@0: Daniel@0: function get_error_message(Requirement $requirement, $lineSize) Daniel@0: { Daniel@0: if ($requirement->isFulfilled()) { Daniel@0: return; Daniel@0: } Daniel@0: Daniel@0: $errorMessage = wordwrap($requirement->getTestMessage(), $lineSize - 3, PHP_EOL.' ').PHP_EOL; Daniel@0: $errorMessage .= ' > '.wordwrap($requirement->getHelpText(), $lineSize - 5, PHP_EOL.' > ').PHP_EOL; Daniel@0: Daniel@0: return $errorMessage; Daniel@0: } Daniel@0: Daniel@0: function echo_title($title, $style = null) Daniel@0: { Daniel@0: $style = $style ?: 'title'; Daniel@0: Daniel@0: echo PHP_EOL; Daniel@0: echo_style($style, $title.PHP_EOL); Daniel@0: echo_style($style, str_repeat('~', strlen($title)).PHP_EOL); Daniel@0: echo PHP_EOL; Daniel@0: } Daniel@0: Daniel@0: function echo_style($style, $message) Daniel@0: { Daniel@0: // ANSI color codes Daniel@0: $styles = array( Daniel@0: 'reset' => "\033[0m", Daniel@0: 'red' => "\033[31m", Daniel@0: 'green' => "\033[32m", Daniel@0: 'yellow' => "\033[33m", Daniel@0: 'error' => "\033[37;41m", Daniel@0: 'success' => "\033[37;42m", Daniel@0: 'title' => "\033[34m", Daniel@0: ); Daniel@0: $supports = has_color_support(); Daniel@0: Daniel@0: echo($supports ? $styles[$style] : '').$message.($supports ? $styles['reset'] : ''); Daniel@0: } Daniel@0: Daniel@0: function echo_block($style, $title, $message) Daniel@0: { Daniel@0: $message = ' '.trim($message).' '; Daniel@0: $width = strlen($message); Daniel@0: Daniel@0: echo PHP_EOL.PHP_EOL; Daniel@0: Daniel@0: echo_style($style, str_repeat(' ', $width).PHP_EOL); Daniel@0: echo_style($style, str_pad(' ['.$title.']', $width, ' ', STR_PAD_RIGHT).PHP_EOL); Daniel@0: echo_style($style, str_pad($message, $width, ' ', STR_PAD_RIGHT).PHP_EOL); Daniel@0: echo_style($style, str_repeat(' ', $width).PHP_EOL); Daniel@0: } Daniel@0: Daniel@0: function has_color_support() Daniel@0: { Daniel@0: static $support; Daniel@0: Daniel@0: if (null === $support) { Daniel@0: if (DIRECTORY_SEPARATOR == '\\') { Daniel@0: $support = false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI'); Daniel@0: } else { Daniel@0: $support = function_exists('posix_isatty') && @posix_isatty(STDOUT); Daniel@0: } Daniel@0: } Daniel@0: Daniel@0: return $support; Daniel@0: }