-
-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extensions listing page, fixes #1440
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of Packagist. | ||
* | ||
* (c) Jordi Boggiano <[email protected]> | ||
* Nils Adermann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace App\Controller; | ||
|
||
use App\Entity\Package; | ||
use App\Model\DownloadManager; | ||
use App\Model\FavoriteManager; | ||
use Pagerfanta\Adapter\FixedAdapter; | ||
use Pagerfanta\Pagerfanta; | ||
use Predis\Client as RedisClient; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\EventListener\AbstractSessionListener; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
|
||
class ExtensionController extends Controller | ||
{ | ||
#[Route(path: '/extensions.{_format}', name: 'browse_extensions', defaults: ['_format' => 'html'])] | ||
public function extensionsAction(Request $req, RedisClient $redis, FavoriteManager $favMgr, DownloadManager $dlMgr): Response | ||
{ | ||
$packages = $this->getEM()->getRepository(Package::class) | ||
->createQueryBuilder('p') | ||
->where("(p.type = 'php-ext' OR p.type = 'php-ext-zend')") | ||
->andWhere('p.frozen IS NULL') | ||
->orderBy('p.name') | ||
->getQuery() | ||
->enableResultCache(900) | ||
->getResult(); | ||
|
||
$packages = new Pagerfanta(new FixedAdapter(count($packages), $packages)); | ||
|
||
$data = [ | ||
'packages' => $packages, | ||
]; | ||
$data['meta'] = $this->getPackagesMetadata($favMgr, $dlMgr, $data['packages']); | ||
|
||
if ($req->getRequestFormat() === 'json') { | ||
$result = [ | ||
'packages' => [], | ||
]; | ||
|
||
foreach ($packages as $package) { | ||
$url = $this->generateUrl('view_package', ['name' => $package->getName()], UrlGeneratorInterface::ABSOLUTE_URL); | ||
|
||
$result['packages'][] = [ | ||
'name' => $package->getName(), | ||
'description' => $package->getDescription() ?: '', | ||
'url' => $url, | ||
'downloads' => $data['meta']['downloads'][$package->getId()], | ||
'favers' => $data['meta']['favers'][$package->getId()], | ||
]; | ||
} | ||
|
||
$response = new JsonResponse($result); | ||
$response->setSharedMaxAge(900); | ||
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true'); | ||
|
||
return $response; | ||
} | ||
|
||
return $this->render('extensions/list.html.twig', $data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% embed "web/list.html.twig" %} | ||
{% block content_title %} | ||
<h2 class="title">PHP Extensions</h2> | ||
{% endblock %} | ||
{% endembed %} |