瀏覽代碼

Make ArrayRepository more extensible

Jordi Boggiano 14 年之前
父節點
當前提交
2475ce47e4
共有 1 個文件被更改,包括 12 次插入1 次删除
  1. 12 1
      src/Composer/Repository/ArrayRepository.php

+ 12 - 1
src/Composer/Repository/ArrayRepository.php

@@ -21,7 +21,7 @@ use Composer\Package\PackageInterface;
  */
 class ArrayRepository implements RepositoryInterface
 {
-    protected $packages = array();
+    protected $packages;
 
     /**
      * Adds a new package to the repository
@@ -41,6 +41,9 @@ class ArrayRepository implements RepositoryInterface
      */
     public function getPackages()
     {
+        if (null === $this->packages) {
+            $this->initialize();
+        }
         return $this->packages;
     }
 
@@ -53,4 +56,12 @@ class ArrayRepository implements RepositoryInterface
     {
         return count($this->packages);
     }
+
+    /**
+     * Initializes the packages array. Mostly meant as an extension point.
+     */
+    protected function initialize()
+    {
+        $this->packages = array();
+    }
 }