From b53a3086b6fb3ece2b6f7243e6d8a0a92614f5e0 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 21 Apr 2011 10:24:19 +0200 Subject: [PATCH] Minor refactorings and changes --- src/Composer/Command/InstallCommand.php | 7 +++- src/Composer/Composer.php | 6 ++- src/Composer/Package/BasePackage.php | 21 +++++++++++ .../Repository/ComposerRepository.php | 17 +-------- .../Repository/PlatformRepository.php | 37 +++++++++++++++++++ 5 files changed, 71 insertions(+), 17 deletions(-) create mode 100644 src/Composer/Repository/PlatformRepository.php diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index d2faabe35..4a7a23cbe 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -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(); diff --git a/src/Composer/Composer.php b/src/Composer/Composer.php index d74ebe6c4..39d995db2 100644 --- a/src/Composer/Composer.php +++ b/src/Composer/Composer.php @@ -13,6 +13,7 @@ namespace Composer; use Composer\Repository\ComposerRepository; +use Composer\Repository\PlatformRepository; /** * @author Jordi Boggiano @@ -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; } } } \ No newline at end of file diff --git a/src/Composer/Package/BasePackage.php b/src/Composer/Package/BasePackage.php index 70c5dc6bd..ea58b5f2a 100644 --- a/src/Composer/Package/BasePackage.php +++ b/src/Composer/Package/BasePackage.php @@ -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'), + ); + } + } diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 0dd38d2ce..21aedeed0 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -13,6 +13,7 @@ namespace Composer\Repository; use Composer\Package\MemoryPackage; +use Composer\Package\BasePackage; /** * @author Jordi Boggiano @@ -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'), - ); - } } \ No newline at end of file diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php new file mode 100644 index 000000000..361809e5a --- /dev/null +++ b/src/Composer/Repository/PlatformRepository.php @@ -0,0 +1,37 @@ + + * Jordi Boggiano + * + * 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 + */ +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 + } +} \ No newline at end of file