Browse Source

Add WrapperRepository class

Jordi Boggiano 13 years ago
parent
commit
4fe80d7abb
1 changed files with 64 additions and 0 deletions
  1. 64 0
      src/Composer/Repository/WrapperRepository.php

+ 64 - 0
src/Composer/Repository/WrapperRepository.php

@@ -0,0 +1,64 @@
+<?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\PackageInterface;
+
+/**
+ * @author Jordi Boggiano <j.boggiano@seld.be>
+ */
+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();
+            }
+        }
+    }
+}