composer 1.5 KB

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