ComposerJsonFinder.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Composer;
  7. use Magento\Framework\App\Filesystem\DirectoryList;
  8. /**
  9. * A class to find path to root Composer json file
  10. */
  11. class ComposerJsonFinder
  12. {
  13. /**
  14. * @var DirectoryList
  15. */
  16. private $directoryList;
  17. /**
  18. * Constructor
  19. *
  20. * @param DirectoryList $directoryList
  21. */
  22. public function __construct(DirectoryList $directoryList)
  23. {
  24. $this->directoryList = $directoryList;
  25. }
  26. /**
  27. * Find absolute path to root Composer json file
  28. *
  29. * @return string
  30. * @throws \Exception
  31. */
  32. public function findComposerJson()
  33. {
  34. $composerJson = $this->directoryList->getPath(DirectoryList::ROOT) . '/composer.json';
  35. $composerJson = realpath($composerJson);
  36. if ($composerJson === false) {
  37. throw new \Exception('Composer file not found');
  38. }
  39. return $composerJson;
  40. }
  41. }