php-cs-fixer 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
  13. error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED);
  14. }
  15. if (defined('HHVM_VERSION_ID')) {
  16. fwrite(STDERR, "HHVM is not supported.\n");
  17. if (getenv('PHP_CS_FIXER_IGNORE_ENV')) {
  18. fwrite(STDERR, "Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Execution may be unstable.\n");
  19. } else {
  20. exit(1);
  21. }
  22. } elseif (!defined('PHP_VERSION_ID') || \PHP_VERSION_ID < 50600 || \PHP_VERSION_ID >= 70500) {
  23. fwrite(STDERR, "PHP needs to be a minimum version of PHP 5.6.0 and maximum version of PHP 7.4.*.\n");
  24. if (getenv('PHP_CS_FIXER_IGNORE_ENV')) {
  25. fwrite(STDERR, "Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Execution may be unstable.\n");
  26. } else {
  27. fwrite(STDERR, "To ignore this requirement please set `PHP_CS_FIXER_IGNORE_ENV`.\n");
  28. fwrite(STDERR, "If you use PHP version higher than supported, you may experience code modified in a wrong way.\n");
  29. fwrite(STDERR, "Please report such cases at https://github.com/FriendsOfPHP/PHP-CS-Fixer .\n");
  30. exit(1);
  31. }
  32. }
  33. foreach (['json', 'tokenizer'] as $extension) {
  34. if (!extension_loaded($extension)) {
  35. fwrite(STDERR, sprintf("PHP extension ext-%s is missing from your system. Install or enable it.\n", $extension));
  36. if (getenv('PHP_CS_FIXER_IGNORE_ENV')) {
  37. fwrite(STDERR, "Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Execution may be unstable.\n");
  38. } else {
  39. exit(1);
  40. }
  41. }
  42. }
  43. unset($extension);
  44. set_error_handler(static function ($severity, $message, $file, $line) {
  45. if ($severity & error_reporting()) {
  46. throw new ErrorException($message, 0, $severity, $file, $line);
  47. }
  48. });
  49. $require = true;
  50. if (class_exists('Phar')) {
  51. // Maybe this file is used as phar-stub? Let's try!
  52. try {
  53. Phar::mapPhar('php-cs-fixer.phar');
  54. require_once 'phar://php-cs-fixer.phar/vendor/autoload.php';
  55. $require = false;
  56. } catch (PharException $e) {
  57. }
  58. }
  59. if ($require) {
  60. // OK, it's not, let give Composer autoloader a try!
  61. $possibleFiles = [__DIR__.'/../../autoload.php', __DIR__.'/../autoload.php', __DIR__.'/vendor/autoload.php'];
  62. $file = null;
  63. foreach ($possibleFiles as $possibleFile) {
  64. if (file_exists($possibleFile)) {
  65. $file = $possibleFile;
  66. break;
  67. }
  68. }
  69. if (null === $file) {
  70. throw new RuntimeException('Unable to locate autoload.php file.');
  71. }
  72. require_once $file;
  73. unset($possibleFiles, $possibleFile, $file);
  74. }
  75. unset($require);
  76. use Composer\XdebugHandler\XdebugHandler;
  77. use PhpCsFixer\Console\Application;
  78. // Restart if xdebug is loaded, unless the environment variable PHP_CS_FIXER_ALLOW_XDEBUG is set.
  79. $xdebug = new XdebugHandler('PHP_CS_FIXER', '--ansi');
  80. $xdebug->check();
  81. unset($xdebug);
  82. $application = new Application();
  83. $application->run();
  84. __HALT_COMPILER();