From e5907a3431ef6dbc1dcd5577f156aa0905e286a8 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 25 Sep 2011 23:42:40 +0200 Subject: [PATCH] Remove WrapperRepository in favor of PlatformRepository wrapping the local repo --- bin/composer | 6 +- .../Repository/PlatformRepository.php | 43 ++++++++++++- src/Composer/Repository/WrapperRepository.php | 64 ------------------- 3 files changed, 41 insertions(+), 72 deletions(-) delete mode 100644 src/Composer/Repository/WrapperRepository.php diff --git a/bin/composer b/bin/composer index 94c5c19b2..030566656 100755 --- a/bin/composer +++ b/bin/composer @@ -12,11 +12,7 @@ use Composer\Console\Application as ComposerApplication; // initialize repository manager $rm = new Repository\RepositoryManager(); -$localRepository = new Repository\WrapperRepository(array( - new Repository\ArrayRepository('.composer/installed.json'), - new Repository\PlatformRepository(), -)); -$rm->setLocalRepository($localRepository); +$rm->setLocalRepository(new Repository\PlatformRepository(new Repository\FilesystemRepository('.composer/installed.json'))); $rm->setRepository('Packagist', new Repository\ComposerRepository('http://packagist.org')); // initialize download manager diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index 5a94eee55..a93e32bf0 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -14,13 +14,21 @@ namespace Composer\Repository; use Composer\Package\MemoryPackage; use Composer\Package\BasePackage; +use Composer\Package\PackageInterface; use Composer\Package\Version\VersionParser; /** * @author Jordi Boggiano */ -class PlatformRepository extends ArrayRepository +class PlatformRepository extends ArrayRepository implements WritableRepositoryInterface { + private $localRepository; + + public function __construct(WritableRepositoryInterface $localRepository) + { + $this->localRepository = $localRepository; + } + protected function initialize() { parent::initialize(); @@ -34,7 +42,7 @@ class PlatformRepository extends ArrayRepository } $php = new MemoryPackage('php', $version['version'], $version['type']); - $this->addPackage($php); + parent::addPackage($php); foreach (get_loaded_extensions() as $ext) { if (in_array($ext, array('standard', 'Core'))) { @@ -49,7 +57,36 @@ class PlatformRepository extends ArrayRepository } $ext = new MemoryPackage('ext/'.strtolower($ext), $version['version'], $version['type']); - $this->addPackage($ext); + parent::addPackage($ext); } } + + public function getPackages() + { + return array_merge(parent::getPackages(), $this->localRepository->getPackages()); + } + + /** + * {@inheritDoc} + */ + public function addPackage(PackageInterface $package) + { + $this->localRepository->addPackage($package); + } + + /** + * {@inheritDoc} + */ + public function removePackage(PackageInterface $package) + { + $this->localRepository->removePackage($package); + } + + /** + * {@inheritDoc} + */ + public function write() + { + $this->localRepository->write(); + } } diff --git a/src/Composer/Repository/WrapperRepository.php b/src/Composer/Repository/WrapperRepository.php deleted file mode 100644 index f298cb50b..000000000 --- a/src/Composer/Repository/WrapperRepository.php +++ /dev/null @@ -1,64 +0,0 @@ - - * 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\PackageInterface; - -/** - * @author Jordi Boggiano - */ -class WrapperRepository extends ArrayRepository implements WritableRepositoryInterface -{ - private $repositories; - - public function __construct(array $repositories) - { - $this->repositories = $repositories; - } - - protected function initialize() - { - parent::initialize(); - - foreach ($this->repositories as $repo) { - foreach ($repo->getPackages() as $package) { - $this->packages[] = $package; - } - } - } - - /** - * {@inheritDoc} - */ - public function addPackage(PackageInterface $package) - { - throw new \LogicException('Can not add packages to a wrapper repository'); - } - - /** - * {@inheritDoc} - */ - public function removePackage(PackageInterface $package) - { - throw new \LogicException('Can not remove packages to a wrapper repository'); - } - - public function write() - { - foreach ($this->repositories as $repo) { - if ($repo instanceof WritableRepositoryInterface) { - $repo->write(); - } - } - } -}