1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- /*
- * This file is part of Composer.
- *
- * (c) Nils Adermann <naderman@naderman.de>
- * Jordi Boggiano <j.boggiano@seld.be>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Composer\Repository;
- use Composer\Package\MemoryPackage;
- use Composer\Package\BasePackage;
- use Composer\Package\Link;
- use Composer\Package\LinkConstraint\VersionConstraint;
- /**
- * @author Jordi Boggiano <j.boggiano@seld.be>
- */
- class ComposerRepository extends ArrayRepository
- {
- protected $packages;
- public function __construct($url)
- {
- $this->url = $url;
- }
- protected function initialize()
- {
- parent::initialize();
- $packages = @json_decode(file_get_contents($this->url.'/packages.json'), true);
- if (!$packages) {
- throw new \UnexpectedValueException('Could not parse package list from the '.$this->url.' repository');
- }
- foreach ($packages as $data) {
- $this->createPackages($data);
- }
- }
- protected function createPackages($data)
- {
- foreach ($data['versions'] as $rev) {
- $version = BasePackage::parseVersion($rev['version']);
- $package = new MemoryPackage($rev['name'], $version['version'], $version['type']);
- $package->setSourceType($rev['source']['type']);
- $package->setSourceUrl($rev['source']['url']);
- if (isset($rev['license'])) {
- $package->setLicense($rev['license']);
- }
- $links = array(
- 'require',
- 'conflict',
- 'provide',
- 'replace',
- 'recommend',
- 'suggest',
- );
- foreach ($links as $link) {
- if (isset($rev[$link])) {
- $method = 'set'.$link.'s';
- $package->{$method}($this->createLinks($rev['name'], $link.'s', $rev[$link]));
- }
- }
- $this->addPackage($package);
- }
- }
- protected function createLinks($name, $description, $linkSpecs)
- {
- $links = array();
- foreach ($linkSpecs as $dep => $ver) {
- preg_match('#^([>=<~]*)([\d.]+.*)$#', $ver, $match);
- if (!$match[1]) {
- $match[1] = '=';
- }
- $constraint = new VersionConstraint($match[1], $match[2]);
- $links[] = new Link($name, $dep, $constraint, $description);
- }
- return $links;
- }
- }
|