composer 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. setlocale(LC_ALL, 'C');
  7. require __DIR__.'/../src/bootstrap.php';
  8. use Composer\Factory;
  9. use Composer\XdebugHandler;
  10. use Composer\Console\Application;
  11. error_reporting(-1);
  12. // Create output for XdebugHandler and Application
  13. $output = Factory::createOutput();
  14. $xdebug = new XdebugHandler($output);
  15. $xdebug->check();
  16. unset($xdebug);
  17. if (function_exists('ini_set')) {
  18. @ini_set('display_errors', 1);
  19. $memoryInBytes = function ($value) {
  20. $unit = strtolower(substr($value, -1, 1));
  21. $value = (int) $value;
  22. switch($unit) {
  23. case 'g':
  24. $value *= 1024;
  25. // no break (cumulative multiplier)
  26. case 'm':
  27. $value *= 1024;
  28. // no break (cumulative multiplier)
  29. case 'k':
  30. $value *= 1024;
  31. }
  32. return $value;
  33. };
  34. $memoryLimit = trim(ini_get('memory_limit'));
  35. // Increase memory_limit if it is lower than 1.5GB
  36. if ($memoryLimit != -1 && $memoryInBytes($memoryLimit) < 1024 * 1024 * 1536) {
  37. @ini_set('memory_limit', '1536M');
  38. }
  39. // Set user defined memory limit
  40. if ($memoryLimit = getenv('COMPOSER_MEMORY_LIMIT')) {
  41. @ini_set('memory_limit', $memoryLimit);
  42. }
  43. unset($memoryInBytes, $memoryLimit);
  44. }
  45. putenv('COMPOSER_BINARY='.realpath($_SERVER['argv'][0]));
  46. // run the command application
  47. $application = new Application();
  48. $application->run(null, $output);