소스 검색

Merge pull request #4951 from franzliedke/fl/path-repositories

RepositoryManager::prependRepository()
Rob 9 년 전
부모
커밋
fa572f3452
2개의 변경된 파일28개의 추가작업 그리고 0개의 파일을 삭제
  1. 12 0
      src/Composer/Repository/RepositoryManager.php
  2. 16 0
      tests/Composer/Test/Repository/RepositoryManagerTest.php

+ 12 - 0
src/Composer/Repository/RepositoryManager.php

@@ -89,6 +89,18 @@ class RepositoryManager
         $this->repositories[] = $repository;
     }
 
+    /**
+     * Adds a repository to the beginning of the chain
+     *
+     * This is useful when injecting additional repositories that should trump Packagist, e.g. from a plugin.
+     *
+     * @param RepositoryInterface $repository repository instance
+     */
+    public function prependRepository(RepositoryInterface $repository)
+    {
+        array_unshift($this->repositories, $repository);
+    }
+
     /**
      * Returns a new repository for a specific installation type.
      *

+ 16 - 0
tests/Composer/Test/Repository/RepositoryManagerTest.php

@@ -32,6 +32,22 @@ class RepositoryManagerTest extends TestCase
         }
     }
 
+    public function testPrepend()
+    {
+        $rm = new RepositoryManager(
+            $this->getMock('Composer\IO\IOInterface'),
+            $this->getMock('Composer\Config'),
+            $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock()
+        );
+
+        $repository1 = $this->getMock('Composer\Repository\RepositoryInterface');
+        $repository2 = $this->getMock('Composer\Repository\RepositoryInterface');
+        $rm->addRepository($repository1);
+        $rm->prependRepository($repository2);
+
+        $this->assertEquals(array($repository2, $repository1), $rm->getRepositories());
+    }
+
     /**
      * @dataProvider creationCases
      */