GitRepository.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. use Composer\Package\Link;
  15. use Composer\Package\LinkConstraint\VersionConstraint;
  16. use Composer\Package\Loader\ArrayLoader;
  17. use Composer\Json\JsonFile;
  18. /**
  19. * FIXME This is majorly broken and incomplete, it was an experiment
  20. *
  21. * @author Jordi Boggiano <j.boggiano@seld.be>
  22. */
  23. class GitRepository extends ArrayRepository
  24. {
  25. protected $url;
  26. public function __construct(array $url)
  27. {
  28. if (!filter_var($config['url'], FILTER_VALIDATE_URL)) {
  29. throw new \UnexpectedValueException('Invalid url given for PEAR repository: '.$url);
  30. }
  31. $this->url = $url;
  32. }
  33. protected function initialize()
  34. {
  35. parent::initialize();
  36. if (preg_match('#^(?:https?|git(?:\+ssh)?|ssh)://#', $this->url)) {
  37. // check if the repo is on github.com, read the composer.json file & branch/tags out of it
  38. // otherwise, maybe we have to clone the repo to figure out what's in it
  39. throw new \Exception('Not implemented yet');
  40. } elseif (file_exists($this->url)) {
  41. if (!file_exists($this->url.'/composer.json')) {
  42. throw new \InvalidArgumentException('The repository at url '.$this->url.' does not contain a composer.json file.');
  43. }
  44. $json = new JsonFile($this->url.'/composer.json');
  45. $config = $json->read();
  46. if (!$config) {
  47. throw new \UnexpectedValueException('Config file could not be parsed: '.$this->url.'/composer.json. Probably a JSON syntax error.');
  48. }
  49. } else {
  50. throw new \InvalidArgumentException('Could not find repository at url '.$this->url);
  51. }
  52. $loader = new ArrayLoader($this->repositoryManager);
  53. $this->addPackage($loader->load($config));
  54. }
  55. }