PlatformRepository.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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\BasePackage;
  14. /**
  15. * @author Jordi Boggiano <j.boggiano@seld.be>
  16. */
  17. class PlatformRepository extends ArrayRepository
  18. {
  19. protected $packages;
  20. protected function initialize()
  21. {
  22. parent::initialize();
  23. try {
  24. $version = BasePackage::parseVersion(PHP_VERSION);
  25. } catch (\UnexpectedValueException $e) {
  26. $version = BasePackage::parseVersion(preg_replace('#^(.+?)(-.+)?#', '$1', PHP_VERSION));
  27. }
  28. // TODO mark as type platform and create a special installer that skips it + one that throws an exception
  29. $php = new MemoryPackage('php', $version['version'], $version['type']);
  30. $this->addPackage($php);
  31. foreach (get_loaded_extensions() as $ext) {
  32. if (in_array($ext, array('standard', 'Core'))) {
  33. continue;
  34. }
  35. $reflExt = new \ReflectionExtension($ext);
  36. try {
  37. $version = BasePackage::parseVersion($reflExt->getVersion());
  38. } catch (\UnexpectedValueException $e) {
  39. $version = array('version' => '0', 'type' => 'stable');
  40. }
  41. $ext = new MemoryPackage('ext/'.strtolower($ext), $version['version'], $version['type']);
  42. $this->addPackage($ext);
  43. }
  44. }
  45. }