1
0
Fork 0

Minor refactorings and changes

pull/1/head
Jordi Boggiano 2011-04-21 10:24:19 +02:00
parent ec94b76c7c
commit b53a3086b6
5 changed files with 71 additions and 17 deletions

View File

@ -25,11 +25,16 @@ class InstallCommand
$config = $this->loadConfig();
foreach ($config['repositories'] as $name => $spec) {
$composer->addRepository($name, $spec);
}
// TODO this should just do dependency solving based on all repositories
$packages = array();
foreach ($composer->getRepositories() as $repository) {
$packages = array_merge($packages, $repository->getPackages());
$packages[] = $repository->getPackages();
}
$packages = call_user_func_array('array_merge', $packages);
$lock = array();

View File

@ -13,6 +13,7 @@
namespace Composer;
use Composer\Repository\ComposerRepository;
use Composer\Repository\PlatformRepository;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
@ -26,6 +27,7 @@ class Composer
public function __construct()
{
$this->addRepository('Packagist', array('composer' => 'http://packagist.org'));
$this->addRepository('Platform', array('platform' => ''));
}
public function addDownloader($type, $downloader)
@ -81,9 +83,11 @@ class Composer
throw new \Exception($type.' repositories not supported yet');
break;
case 'platform':
return new PlatformRepository;
case 'composer':
return new ComposerRepository($url);
break;
}
}
}

View File

@ -121,4 +121,25 @@ abstract class BasePackage implements PackageInterface
{
return $this->getName().'-'.$this->getReleaseType().'-'.$this->getVersion();
}
/**
* Parses a version string and returns an array with the version and its type (dev, alpha, beta, RC, stable)
*
* @param string $version
* @return array
*/
public static function parseVersion($version)
{
if (!preg_match('#^v?(\d+)(\.\d+)?(\.\d+)?-?(?:(beta|RC\d+|alpha|dev)?\d*)$#i', $version, $matches)) {
throw new \UnexpectedValueException('Invalid version string '.$version);
}
return array(
'version' => $matches[1]
.(!empty($matches[2]) ? $matches[2] : '.0')
.(!empty($matches[3]) ? $matches[3] : '.0'),
'type' => strtolower(!empty($matches[4]) ? $matches[4] : 'stable'),
);
}
}

View File

@ -13,6 +13,7 @@
namespace Composer\Repository;
use Composer\Package\MemoryPackage;
use Composer\Package\BasePackage;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
@ -42,7 +43,7 @@ class ComposerRepository extends ArrayRepository
protected function createPackages($data)
{
foreach ($data['versions'] as $rev) {
$version = $this->parseVersion($rev['version']);
$version = BasePackage::parseVersion($rev['version']);
$package = new MemoryPackage($rev['name'], $version['version'], $version['type']);
$package->setSourceType($rev['source']['type']);
@ -72,18 +73,4 @@ class ComposerRepository extends ArrayRepository
$this->addPackage($package);
}
}
protected function parseVersion($version)
{
if (!preg_match('#^v?(\d+)(\.\d+)?(\.\d+)?-?(beta|RC\d+|alpha|dev)?$#i', $version, $matches)) {
throw new \UnexpectedValueException('Invalid version string '.$version);
}
return array(
'version' => $matches[1]
.(!empty($matches[2]) ? $matches[2] : '.0')
.(!empty($matches[3]) ? $matches[3] : '.0'),
'type' => strtolower(!empty($matches[4]) ? $matches[4] : 'stable'),
);
}
}

View File

@ -0,0 +1,37 @@
<?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;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class PlatformRepository extends ArrayRepository
{
protected $packages;
protected function initialize()
{
parent::initialize();
$version = BasePackage::parseVersion(PHP_VERSION);
// TODO mark as type platform and create a special installer that skips it + one that throws an exception
$php = new MemoryPackage('php', $version['version'], $version['type']);
$this->addPackage($php);
// TODO check for php extensions
}
}