composer 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env php
  2. <?php
  3. if (PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg') {
  4. echo 'Warning: Composer should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL;
  5. }
  6. setlocale(LC_ALL, 'C');
  7. require __DIR__.'/../src/bootstrap.php';
  8. use Composer\Console\Application;
  9. use Composer\XdebugHandler\XdebugHandler;
  10. error_reporting(-1);
  11. // Restart without xdebug
  12. $xdebug = new XdebugHandler('Composer', '--ansi');
  13. $xdebug->check();
  14. unset($xdebug);
  15. if (function_exists('ini_set')) {
  16. @ini_set('display_errors', 1);
  17. $memoryInBytes = function ($value) {
  18. $unit = strtolower(substr($value, -1, 1));
  19. $value = (int) $value;
  20. switch($unit) {
  21. case 'g':
  22. $value *= 1024;
  23. // no break (cumulative multiplier)
  24. case 'm':
  25. $value *= 1024;
  26. // no break (cumulative multiplier)
  27. case 'k':
  28. $value *= 1024;
  29. }
  30. return $value;
  31. };
  32. $memoryLimit = trim(ini_get('memory_limit'));
  33. // Increase memory_limit if it is lower than 1.5GB
  34. if ($memoryLimit != -1 && $memoryInBytes($memoryLimit) < 1024 * 1024 * 1536) {
  35. @ini_set('memory_limit', '1536M');
  36. }
  37. // Set user defined memory limit
  38. if ($memoryLimit = getenv('COMPOSER_MEMORY_LIMIT')) {
  39. @ini_set('memory_limit', $memoryLimit);
  40. }
  41. unset($memoryInBytes, $memoryLimit);
  42. }
  43. putenv('COMPOSER_BINARY='.realpath($_SERVER['argv'][0]));
  44. // run the command application
  45. $application = new Application();
  46. $application->run();