Эх сурвалжийг харах

Include support key in package API

Jordi Boggiano 5 жил өмнө
parent
commit
d18795f4c6

+ 1 - 1
src/Packagist/WebBundle/Controller/PackageController.php

@@ -405,7 +405,7 @@ class PackageController extends Controller
         }
 
         if ('json' === $req->getRequestFormat()) {
-            $data = $package->toArray($this->getDoctrine()->getRepository(Version::class));
+            $data = $package->toArray($this->getDoctrine()->getRepository(Version::class), true);
             $data['dependents'] = $repo->getDependantCount($package->getName());
             $data['suggesters'] = $repo->getSuggestCount($package->getName());
 

+ 2 - 2
src/Packagist/WebBundle/Entity/Package.php

@@ -193,7 +193,7 @@ class Package
         $this->createdAt = new \DateTime;
     }
 
-    public function toArray(VersionRepository $versionRepo)
+    public function toArray(VersionRepository $versionRepo, bool $serializeForApi = false)
     {
         $versions = array();
         $partialVersions = $this->getVersions()->toArray();
@@ -202,7 +202,7 @@ class Package
             $slice = array_splice($partialVersions, 0, 100);
             $fullVersions = $versionRepo->refreshVersions($slice);
             $versionData = $versionRepo->getVersionData(array_map(function ($v) { return $v->getId(); }, $fullVersions));
-            $versions = array_merge($versions, $versionRepo->detachToArray($fullVersions, $versionData));
+            $versions = array_merge($versions, $versionRepo->detachToArray($fullVersions, $versionData, $serializeForApi));
         }
 
         $maintainers = array();

+ 4 - 1
src/Packagist/WebBundle/Entity/Version.php

@@ -218,7 +218,7 @@ class Version
         $this->updatedAt = new \DateTime;
     }
 
-    public function toArray(array $versionData)
+    public function toArray(array $versionData, bool $serializeForApi = false)
     {
         if (isset($versionData[$this->id]['tags'])) {
             $tags = $versionData[$this->id]['tags'];
@@ -262,6 +262,9 @@ class Version
             'type' => $this->getType(),
         );
 
+        if ($serializeForApi && $this->getSupport()) {
+            $data['support'] = $this->getSupport();
+        }
         if ($this->getReleasedAt()) {
             $data['time'] = $this->getReleasedAt()->format('Y-m-d\TH:i:sP');
         }

+ 2 - 2
src/Packagist/WebBundle/Entity/VersionRepository.php

@@ -82,12 +82,12 @@ class VersionRepository extends EntityRepository
     /**
      * @param Version[] $versions
      */
-    public function detachToArray(array $versions, array $versionData): array
+    public function detachToArray(array $versions, array $versionData, bool $serializeForApi = false): array
     {
         $res = [];
         $em = $this->getEntityManager();
         foreach ($versions as $version) {
-            $res[$version->getVersion()] = $version->toArray($versionData);
+            $res[$version->getVersion()] = $version->toArray($versionData, $serializeForApi);
             $em->detach($version);
         }