Skip to content

Commit

Permalink
Add 'Vendor Package Listing' page
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioheleno committed May 4, 2022
1 parent 35eb5b2 commit f004318
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Application\Action\Package\ViewPackageAction;
use App\Application\Action\Package\ViewPackageBadgeAction;
use App\Application\Action\System\HealthAction;
use App\Application\Action\Vendor\ListPackagesAction as ListVendorPackagesAction;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\App;
Expand All @@ -33,6 +34,9 @@ function (ServerRequestInterface $request, ResponseInterface $response): Respons
function (Group $group) {
$group
->get('', RedirectListPackagesAction::class);
$group
->get('/{vendor}', ListVendorPackagesAction::class)
->setName('listVendorPackages');
$group
->get('/{vendor}/{project}/status.svg', RedirectPackageBadgeAction::class)
->setName('redirectPackageBadge');
Expand Down
30 changes: 30 additions & 0 deletions resources/views/vendor/list.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends "template.twig" %}

{% block title %}Keep your dependencies up-to-date - PHP.Package.Health{% endblock %}

{% block hero_type %}is-info{% endblock %}
{% block hero_title %}Keep your dependencies up-to-date{% endblock %}

{% block hero_subtitle %}Package.Health uses semantic versioning to detect outdated or insecure dependencies in your project's <code>composer.json</code>.{% endblock %}

{% block content %}
<h2 class="title is-3">Packages from {{ vendor }}</h2>
<table class="table is-fullwidth is-striped is-hoverable">
<thead>
<tr>
<th>Package</th>
<th></th>
<th class="has-text-right">Status</th>
</tr>
</thead>
<tbody>
{% for package in packages %}
<tr>
<td><a href="{{ url_for('redirectPackage', {vendor: package.vendor, project: package.project}) }}">{{ package.name }}</a></td>
<td class="has-text-grey">{{ package.description }}</td>
<td class="has-text-right"><img src="{{ url_for('redirectPackageBadge', {vendor: package.vendor, project: package.project}) }}" height="20" alt="Dependency Badge" decoding="async"></td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
66 changes: 66 additions & 0 deletions src/Application/Action/Vendor/ListPackagesAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
declare(strict_types = 1);

namespace App\Application\Action\Vendor;

use App\Application\Action\AbstractAction;
use App\Domain\Package\PackageRepositoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
use Slim\HttpCache\CacheProvider;
use Slim\Views\Twig;

final class ListPackagesAction extends AbstractAction {
protected PackageRepositoryInterface $packageRepository;

public function __construct(
LoggerInterface $logger,
CacheProvider $cacheProvider,
PackageRepositoryInterface $packageRepository
) {
parent::__construct($logger, $cacheProvider);
$this->packageRepository = $packageRepository;
}

protected function action(): ResponseInterface {
$vendor = $this->resolveStringArg('vendor');
$packages = $this->packageRepository->findMatching(['name' => "$vendor/%"]);
$twig = Twig::fromRequest($this->request);

$this->logger->debug('Vendor package list was viewed.');

// if (count($packages)) {
// $lastModifiedList = array_map(
// function (Package $package): int {
// $lastModified = $package->getUpdatedAt() ?? $package->getCreatedAt();

// return $lastModified->getTimestamp();
// },
// $packages
// );

// $lastModified = max($lastModifiedList);
// $this->response = $this->cacheProvider->withLastModified(
// $this->response,
// $lastModified
// );
// $this->response = $this->cacheProvider->withEtag(
// $this->response,
// hash('sha1', (string)$lastModified)
// );
// }

return $this->respondWithHtml(
$twig->fetch(
'vendor/list.twig',
[
'vendor' => $vendor,
'packages' => $packages,
'app' => [
'version' => $_ENV['VERSION']
]
]
)
);
}
}

0 comments on commit f004318

Please sign in to comment.