Przeglądaj źródła

Add parsing of keywords/authors/release date to the ArrayLoader

Jordi Boggiano 13 lat temu
rodzic
commit
a13c35537c

+ 17 - 3
src/Composer/Package/Loader/ArrayLoader.php

@@ -69,12 +69,26 @@ class ArrayLoader
             $package->setRepositories($config['repositories']);
         }
 
-        if (isset($config['extra'])) {
+        if (isset($config['extra']) && is_array($config['extra'])) {
             $package->setExtra($config['extra']);
         }
 
-        if (isset($config['license'])) {
-            $package->setLicense($config['license']);
+        if (!empty($config['keywords'])) {
+            $package->setKeywords(is_array($config['keywords']) ? $config['keywords'] : array($config['keywords']));
+
+        if (!empty($config['license'])) {
+            $package->setLicense(is_array($config['license']) ? $config['license'] : array($config['license']));
+        }
+
+        if (!empty($config['time'])) {
+            try {
+                $package->setReleaseDate(new \DateTime($config['time']));
+            } catch (\Exception $e) {
+            }
+        }
+
+        if (!empty($config['authors']) && is_array($config['authors'])) {
+            $package->setAuthors($config['authors']);
         }
 
         if (isset($config['installation-source'])) {

+ 57 - 0
src/Composer/Package/MemoryPackage.php

@@ -33,6 +33,9 @@ class MemoryPackage extends BasePackage
     protected $prettyVersion;
     protected $repositories;
     protected $license;
+    protected $releaseDate;
+    protected $keywords;
+    protected $authors;
     protected $extra = array();
 
     protected $requires = array();
@@ -394,6 +397,60 @@ class MemoryPackage extends BasePackage
         return $this->suggests;
     }
 
+    /**
+     * Set the releaseDate
+     *
+     * @param DateTime $releaseDate
+     */
+    public function setReleasedate(\DateTime $releaseDate)
+    {
+        $this->releaseDate = $releaseDate;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function getReleaseDate()
+    {
+        return $this->releaseDate;
+    }
+
+    /**
+     * Set the keywords
+     *
+     * @param array $keywords
+     */
+    public function setKeywords(array $keywords)
+    {
+        $this->keywords = $keywords;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function getKeywords()
+    {
+        return $this->keywords;
+    }
+
+    /**
+     * Set the authors
+     *
+     * @param array $authors
+     */
+    public function setAuthors(array $authors)
+    {
+        $this->authors = $authors;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function getAuthors()
+    {
+        return $this->authors;
+    }
+
     /**
      * Set the autoload mapping
      *

+ 24 - 1
src/Composer/Package/PackageInterface.php

@@ -259,7 +259,30 @@ interface PackageInterface
     function getRepository();
 
     /**
-     * Returns package unique name, constructed from name, version and release type.
+     * Returns the release date of the package
+     *
+     * @return DateTime
+     */
+    function getReleaseDate();
+
+    /**
+     * Returns an array of keywords relating to the package
+     *
+     * @return array
+     */
+    function getKeywords();
+
+    /**
+     * Returns an array of authors of the package
+     *
+     * Each item can contain name/homepage/email keys
+     *
+     * @return array
+     */
+    function getAuthors();
+
+    /**
+     * Returns package unique name, constructed from name and version.
      *
      * @return string
      */