check.php 3.8 KB

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