composer-check.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env php
  2. <?php
  3. namespace Fgm\ComposerCheck;
  4. /**
  5. * Guess the path where the Composer autoloader is available.
  6. *
  7. * TODO find a better logic.
  8. *
  9. * @return string
  10. * The path to the
  11. */
  12. function setupAutoload($debug = FALSE) {
  13. $runningFrom = [
  14. // Straight git clone, then composer install.
  15. "git clone" => __DIR__ . '/../vendor',
  16. // Composer install as drush plugin with default config/bin.
  17. "composer default" => __DIR__ . '/../../../../vendor',
  18. ];
  19. foreach ($runningFrom as $kind => $location) {
  20. $path = "${location}/autoload.php";
  21. if (is_file($path) && is_readable($path)) {
  22. $autoloader = include_once $path;
  23. if ($autoloader instanceof \Composer\Autoload\ClassLoader) {
  24. if ($debug) {
  25. echo "Install appears to be: $kind\n";
  26. }
  27. break;
  28. }
  29. }
  30. }
  31. return realpath(dirname($location));
  32. }
  33. // TODO use options.
  34. $all = FALSE;
  35. $debug = TRUE;
  36. $useYaml = TRUE;
  37. $path = setupAutoload($debug);
  38. if (empty($path)) {
  39. die("Autoloader not found.");
  40. }
  41. $factory = new LoaderFactory($path, $all);
  42. $requirementsLoader = $factory->createLoader('requirements');
  43. $requirementsLoader->load();
  44. $lockLoader = $factory->createLoader('lock');
  45. $lockLoader->load();
  46. $merger = new MergeBox($requirementsLoader, $lockLoader, $all);
  47. $merger->merge();
  48. $reporter = $useYaml ? new YamlReporter() : new JsonReporter();
  49. echo $reporter->report($merger);