PlatformRepository.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Repository;
  12. use Composer\Package\MemoryPackage;
  13. use Composer\Package\Version\VersionParser;
  14. /**
  15. * @author Jordi Boggiano <j.boggiano@seld.be>
  16. */
  17. class PlatformRepository extends ArrayRepository
  18. {
  19. protected function initialize()
  20. {
  21. parent::initialize();
  22. $versionParser = new VersionParser();
  23. try {
  24. $prettyVersion = PHP_VERSION;
  25. $version = $versionParser->normalize($prettyVersion);
  26. } catch (\UnexpectedValueException $e) {
  27. $prettyVersion = preg_replace('#^(.+?)(-.+)?$#', '$1', PHP_VERSION);
  28. $version = $versionParser->normalize($prettyVersion);
  29. }
  30. $php = new MemoryPackage('php', $version, $prettyVersion);
  31. parent::addPackage($php);
  32. foreach (get_loaded_extensions() as $ext) {
  33. if (in_array($ext, array('standard', 'Core'))) {
  34. continue;
  35. }
  36. $reflExt = new \ReflectionExtension($ext);
  37. try {
  38. $prettyVersion = $reflExt->getVersion();
  39. $version = $versionParser->normalize($prettyVersion);
  40. } catch (\UnexpectedValueException $e) {
  41. $prettyVersion = '0';
  42. $version = $versionParser->normalize($prettyVersion);
  43. }
  44. $ext = new MemoryPackage('ext-'.strtolower($ext), $version, $prettyVersion);
  45. parent::addPackage($ext);
  46. }
  47. }
  48. }