symfony_requirements 3.9 KB

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