composer 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '4.0', '>=')) {
  16. echo 'HHVM 4.0 has dropped support for Composer, please use PHP instead. Aborting.'.PHP_EOL;
  17. exit(1);
  18. }
  19. if (function_exists('ini_set')) {
  20. @ini_set('display_errors', 1);
  21. $memoryInBytes = function ($value) {
  22. $unit = strtolower(substr($value, -1, 1));
  23. $value = (int) $value;
  24. switch($unit) {
  25. case 'g':
  26. $value *= 1024;
  27. // no break (cumulative multiplier)
  28. case 'm':
  29. $value *= 1024;
  30. // no break (cumulative multiplier)
  31. case 'k':
  32. $value *= 1024;
  33. }
  34. return $value;
  35. };
  36. $memoryLimit = trim(ini_get('memory_limit'));
  37. // Increase memory_limit if it is lower than 1.5GB
  38. if ($memoryLimit != -1 && $memoryInBytes($memoryLimit) < 1024 * 1024 * 1536) {
  39. @ini_set('memory_limit', '1536M');
  40. }
  41. // Set user defined memory limit
  42. if ($memoryLimit = getenv('COMPOSER_MEMORY_LIMIT')) {
  43. @ini_set('memory_limit', $memoryLimit);
  44. }
  45. unset($memoryInBytes, $memoryLimit);
  46. }
  47. putenv('COMPOSER_BINARY='.realpath($_SERVER['argv'][0]));
  48. // run the command application
  49. $application = new Application();
  50. $application->run();