ソースを参照

Display funding information for packages and expose funding info to Composer

Requires funding support to be merged into Composer and the
composer/composer dep to be updated.
Nils Adermann 5 年 前
コミット
49e04a9e90

+ 29 - 0
src/Packagist/WebBundle/Entity/Version.php

@@ -179,6 +179,11 @@ class Version
      */
     private $support;
 
+    /**
+     * @ORM\Column(type="text", nullable=true)
+     */
+    private $funding;
+
     /**
      * @ORM\Column(name="authors", type="json", nullable=true)
      */
@@ -265,6 +270,9 @@ class Version
         if ($serializeForApi && $this->getSupport()) {
             $data['support'] = $this->getSupport();
         }
+        if ($serializeForApi && $this->getFunding()) {
+            $data['funding'] = $this->getFunding();
+        }
         if ($this->getReleasedAt()) {
             $data['time'] = $this->getReleasedAt()->format('Y-m-d\TH:i:sP');
         }
@@ -321,6 +329,7 @@ class Version
             $array['support'] = $this->getSupport();
             ksort($array['support']);
         }
+        // TODO do we need to do something for funding here? sort by type/url?
 
         return $array;
     }
@@ -616,6 +625,26 @@ class Version
         return json_decode($this->support, true);
     }
 
+    /**
+     * Set Funding
+     *
+     * @param array $funding
+     */
+    public function setFunding($funding)
+    {
+        $this->funding = $funding ? json_encode($funding) : null;
+    }
+
+    /**
+     * Get funding
+     *
+     * @return array|null
+     */
+    public function getFunding()
+    {
+        return json_decode($this->funding, true);
+    }
+
     /**
      * Set createdAt
      *

+ 1 - 0
src/Packagist/WebBundle/Package/Updater.php

@@ -339,6 +339,7 @@ class Updater
         $version->setBinaries($data->getBinaries());
         $version->setIncludePaths($data->getIncludePaths());
         $version->setSupport($data->getSupport());
+        $version->setFunding($data->getFunding());
 
         if ($data->getKeywords()) {
             $keywords = array();

+ 10 - 0
src/Packagist/WebBundle/Resources/views/package/view_package.html.twig

@@ -174,6 +174,16 @@
                             {% endif %}
                         </div>
 
+                        <div class="facts col-xs-12 col-sm-6 col-md-12">
+                            {% if version and version.funding is defined and version.funding|length > 0 %}
+                                <p>
+                                    Fund package maintenance!
+                                    {% for fundingOption in version.funding %}
+                                        <br>&raquo; <a rel="nofollow noopener external noindex" href="{{ fundingOption.url }}">{{ fundingOption.type == 'custom' ? fundingOption.url : fundingOption.type }}</a>
+                                    {% endfor %}
+                            {% endif %}
+                        </div>
+
                         <div class="facts col-xs-12 col-sm-6 col-md-12">
                             <p>
                                 <span>