annotate app/check.php @ 0:493bcb69166c

added public content
author Daniel Wolff
date Tue, 09 Feb 2016 20:54:02 +0100
parents
children
rev   line source
Daniel@0 1 <?php
Daniel@0 2
Daniel@0 3 require_once dirname(__FILE__).'/SymfonyRequirements.php';
Daniel@0 4
Daniel@0 5 $lineSize = 70;
Daniel@0 6 $symfonyRequirements = new SymfonyRequirements();
Daniel@0 7 $iniPath = $symfonyRequirements->getPhpIniConfigPath();
Daniel@0 8
Daniel@0 9 echo_title('Symfony2 Requirements Checker');
Daniel@0 10
Daniel@0 11 echo '> PHP is using the following php.ini file:'.PHP_EOL;
Daniel@0 12 if ($iniPath) {
Daniel@0 13 echo_style('green', ' '.$iniPath);
Daniel@0 14 } else {
Daniel@0 15 echo_style('warning', ' WARNING: No configuration file (php.ini) used by PHP!');
Daniel@0 16 }
Daniel@0 17
Daniel@0 18 echo PHP_EOL.PHP_EOL;
Daniel@0 19
Daniel@0 20 echo '> Checking Symfony requirements:'.PHP_EOL.' ';
Daniel@0 21
Daniel@0 22 $messages = array();
Daniel@0 23 foreach ($symfonyRequirements->getRequirements() as $req) {
Daniel@0 24 /** @var $req Requirement */
Daniel@0 25 if ($helpText = get_error_message($req, $lineSize)) {
Daniel@0 26 echo_style('red', 'E');
Daniel@0 27 $messages['error'][] = $helpText;
Daniel@0 28 } else {
Daniel@0 29 echo_style('green', '.');
Daniel@0 30 }
Daniel@0 31 }
Daniel@0 32
Daniel@0 33 $checkPassed = empty($messages['error']);
Daniel@0 34
Daniel@0 35 foreach ($symfonyRequirements->getRecommendations() as $req) {
Daniel@0 36 if ($helpText = get_error_message($req, $lineSize)) {
Daniel@0 37 echo_style('yellow', 'W');
Daniel@0 38 $messages['warning'][] = $helpText;
Daniel@0 39 } else {
Daniel@0 40 echo_style('green', '.');
Daniel@0 41 }
Daniel@0 42 }
Daniel@0 43
Daniel@0 44 if ($checkPassed) {
Daniel@0 45 echo_block('success', 'OK', 'Your system is ready to run Symfony2 projects', true);
Daniel@0 46 } else {
Daniel@0 47 echo_block('error', 'ERROR', 'Your system is not ready to run Symfony2 projects', true);
Daniel@0 48
Daniel@0 49 echo_title('Fix the following mandatory requirements', 'red');
Daniel@0 50
Daniel@0 51 foreach ($messages['error'] as $helpText) {
Daniel@0 52 echo ' * '.$helpText.PHP_EOL;
Daniel@0 53 }
Daniel@0 54 }
Daniel@0 55
Daniel@0 56 if (!empty($messages['warning'])) {
Daniel@0 57 echo_title('Optional recommendations to improve your setup', 'yellow');
Daniel@0 58
Daniel@0 59 foreach ($messages['warning'] as $helpText) {
Daniel@0 60 echo ' * '.$helpText.PHP_EOL;
Daniel@0 61 }
Daniel@0 62 }
Daniel@0 63
Daniel@0 64 echo PHP_EOL;
Daniel@0 65 echo_style('title', 'Note');
Daniel@0 66 echo ' The command console could use a different php.ini file'.PHP_EOL;
Daniel@0 67 echo_style('title', '~~~~');
Daniel@0 68 echo ' than the one used with your web server. To be on the'.PHP_EOL;
Daniel@0 69 echo ' safe side, please check the requirements from your web'.PHP_EOL;
Daniel@0 70 echo ' server using the ';
Daniel@0 71 echo_style('yellow', 'web/config.php');
Daniel@0 72 echo ' script.'.PHP_EOL;
Daniel@0 73 echo PHP_EOL;
Daniel@0 74
Daniel@0 75 exit($checkPassed ? 0 : 1);
Daniel@0 76
Daniel@0 77 function get_error_message(Requirement $requirement, $lineSize)
Daniel@0 78 {
Daniel@0 79 if ($requirement->isFulfilled()) {
Daniel@0 80 return;
Daniel@0 81 }
Daniel@0 82
Daniel@0 83 $errorMessage = wordwrap($requirement->getTestMessage(), $lineSize - 3, PHP_EOL.' ').PHP_EOL;
Daniel@0 84 $errorMessage .= ' > '.wordwrap($requirement->getHelpText(), $lineSize - 5, PHP_EOL.' > ').PHP_EOL;
Daniel@0 85
Daniel@0 86 return $errorMessage;
Daniel@0 87 }
Daniel@0 88
Daniel@0 89 function echo_title($title, $style = null)
Daniel@0 90 {
Daniel@0 91 $style = $style ?: 'title';
Daniel@0 92
Daniel@0 93 echo PHP_EOL;
Daniel@0 94 echo_style($style, $title.PHP_EOL);
Daniel@0 95 echo_style($style, str_repeat('~', strlen($title)).PHP_EOL);
Daniel@0 96 echo PHP_EOL;
Daniel@0 97 }
Daniel@0 98
Daniel@0 99 function echo_style($style, $message)
Daniel@0 100 {
Daniel@0 101 // ANSI color codes
Daniel@0 102 $styles = array(
Daniel@0 103 'reset' => "\033[0m",
Daniel@0 104 'red' => "\033[31m",
Daniel@0 105 'green' => "\033[32m",
Daniel@0 106 'yellow' => "\033[33m",
Daniel@0 107 'error' => "\033[37;41m",
Daniel@0 108 'success' => "\033[37;42m",
Daniel@0 109 'title' => "\033[34m",
Daniel@0 110 );
Daniel@0 111 $supports = has_color_support();
Daniel@0 112
Daniel@0 113 echo($supports ? $styles[$style] : '').$message.($supports ? $styles['reset'] : '');
Daniel@0 114 }
Daniel@0 115
Daniel@0 116 function echo_block($style, $title, $message)
Daniel@0 117 {
Daniel@0 118 $message = ' '.trim($message).' ';
Daniel@0 119 $width = strlen($message);
Daniel@0 120
Daniel@0 121 echo PHP_EOL.PHP_EOL;
Daniel@0 122
Daniel@0 123 echo_style($style, str_repeat(' ', $width).PHP_EOL);
Daniel@0 124 echo_style($style, str_pad(' ['.$title.']', $width, ' ', STR_PAD_RIGHT).PHP_EOL);
Daniel@0 125 echo_style($style, str_pad($message, $width, ' ', STR_PAD_RIGHT).PHP_EOL);
Daniel@0 126 echo_style($style, str_repeat(' ', $width).PHP_EOL);
Daniel@0 127 }
Daniel@0 128
Daniel@0 129 function has_color_support()
Daniel@0 130 {
Daniel@0 131 static $support;
Daniel@0 132
Daniel@0 133 if (null === $support) {
Daniel@0 134 if (DIRECTORY_SEPARATOR == '\\') {
Daniel@0 135 $support = false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI');
Daniel@0 136 } else {
Daniel@0 137 $support = function_exists('posix_isatty') && @posix_isatty(STDOUT);
Daniel@0 138 }
Daniel@0 139 }
Daniel@0 140
Daniel@0 141 return $support;
Daniel@0 142 }