php-cs-fixer 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. exit(1);
  28. }
  29. }
  30. foreach (['json', 'tokenizer'] as $extension) {
  31. if (!extension_loaded($extension)) {
  32. fwrite(STDERR, sprintf("PHP extension ext-%s is missing from your system. Install or enable it.\n", $extension));
  33. if (getenv('PHP_CS_FIXER_IGNORE_ENV')) {
  34. fwrite(STDERR, "Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Execution may be unstable.\n");
  35. } else {
  36. exit(1);
  37. }
  38. }
  39. }
  40. unset($extension);
  41. set_error_handler(static function ($severity, $message, $file, $line) {
  42. if ($severity & error_reporting()) {
  43. throw new ErrorException($message, 0, $severity, $file, $line);
  44. }
  45. });
  46. $require = true;
  47. if (class_exists('Phar')) {
  48. // Maybe this file is used as phar-stub? Let's try!
  49. try {
  50. Phar::mapPhar('php-cs-fixer.phar');
  51. require_once 'phar://php-cs-fixer.phar/vendor/autoload.php';
  52. $require = false;
  53. } catch (PharException $e) {
  54. }
  55. }
  56. if ($require) {
  57. // OK, it's not, let give Composer autoloader a try!
  58. $possibleFiles = [__DIR__.'/../../autoload.php', __DIR__.'/../autoload.php', __DIR__.'/vendor/autoload.php'];
  59. $file = null;
  60. foreach ($possibleFiles as $possibleFile) {
  61. if (file_exists($possibleFile)) {
  62. $file = $possibleFile;
  63. break;
  64. }
  65. }
  66. if (null === $file) {
  67. throw new RuntimeException('Unable to locate autoload.php file.');
  68. }
  69. require_once $file;
  70. unset($possibleFiles, $possibleFile, $file);
  71. }
  72. unset($require);
  73. use Composer\XdebugHandler\XdebugHandler;
  74. use PhpCsFixer\Console\Application;
  75. // Restart if xdebug is loaded, unless the environment variable PHP_CS_FIXER_ALLOW_XDEBUG is set.
  76. $xdebug = new XdebugHandler('PHP_CS_FIXER', '--ansi');
  77. $xdebug->check();
  78. unset($xdebug);
  79. $application = new Application();
  80. $application->run();
  81. __HALT_COMPILER();