|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace App\Controller; |
| 13 | + |
| 14 | +use App\Service\Changelog\ChangelogProvider; |
| 15 | +use App\Service\Packagist\PackagistDataProvider; |
| 16 | +use App\Service\UxPackageRepository; |
| 17 | +use App\Twig\Components\ChangelogItem; |
| 18 | +use DateTimeImmutable; |
| 19 | +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
| 20 | +use Symfony\Component\HttpFoundation\Response; |
| 21 | +use Symfony\Component\Routing\Attribute\Route; |
| 22 | + |
| 23 | +#[Route('/{package}', name: 'app_package')] |
| 24 | +class UxPackageController extends AbstractController |
| 25 | +{ |
| 26 | + public function __construct( |
| 27 | + private readonly UxPackageRepository $packageRepository, |
| 28 | + private readonly ChangelogProvider $changeLogProvider, |
| 29 | + private readonly PackagistDataProvider $packagistData, |
| 30 | + ) |
| 31 | + { |
| 32 | + } |
| 33 | + |
| 34 | + #[Route('/changelog', name: 'app_package_changelog')] |
| 35 | + public function changelog(string $package): Response |
| 36 | + { |
| 37 | + $uxPackage = $this->packageRepository->find($package) ?? throw $this->createNotFoundException(sprintf('Package "%s" not found', $package)); |
| 38 | + |
| 39 | + $packageLog = $this->changeLogProvider->getPackageChangelog('ux-'.$uxPackage->getName()); |
| 40 | + $packageData = $this->packagistData->getPackageData($uxPackage->getComposerName()); |
| 41 | + |
| 42 | + $firstLine = array_shift($packageLog); |
| 43 | + |
| 44 | + $changelog = []; |
| 45 | + foreach ($packageLog as $a) { |
| 46 | + |
| 47 | + $lines = explode("\n", $a); |
| 48 | + $version = array_shift($lines); |
| 49 | + |
| 50 | + $versionData = $packageData['versions']['v'.$version] ?? []; |
| 51 | + if ([] === $versionData) { |
| 52 | + continue; |
| 53 | + } |
| 54 | + |
| 55 | + $changelog[] = [ |
| 56 | + 'body' => implode("\n", $lines), |
| 57 | + 'version' => $version, |
| 58 | + 'name' => 'v'.$version, |
| 59 | + 'date' => $versionData['time'] ?? null, |
| 60 | + ]; |
| 61 | + } |
| 62 | + |
| 63 | + return $this->render('ux_packages/package_changelog.html.twig', [ |
| 64 | + 'package' => $uxPackage, |
| 65 | + 'changelog' => $changelog, |
| 66 | + ]); |
| 67 | + } |
| 68 | + |
| 69 | + #[Route('/requirements', name: 'app_package_requirements')] |
| 70 | + public function requirements(string $package): Response |
| 71 | + { |
| 72 | + $uxPackage = $this->packageRepository->find($package) ?? throw $this->createNotFoundException(sprintf('Package "%s" not found', $package)); |
| 73 | + |
| 74 | + $packageData = $this->packagistData->getPackageData($uxPackage->getComposerName()); |
| 75 | + |
| 76 | + $packageVersions = $packageData['versions'] ?? []; |
| 77 | + $currentVersion = array_shift($packageVersions); |
| 78 | + |
| 79 | + return $this->render('ux_packages/package_requirements.html.twig', [ |
| 80 | + 'package' => $uxPackage, |
| 81 | + 'requirements' => [ |
| 82 | + 'requires' => $currentVersion['require'] ?? [], |
| 83 | + 'devRequires' => $currentVersion['require-dev'] ?? [], |
| 84 | + ], |
| 85 | + ]); |
| 86 | + } |
| 87 | +} |
0 commit comments