Skip to content

Commit

Permalink
New base-package structure and detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbertsoft committed May 15, 2023
1 parent aada7cd commit 58f3f8c
Show file tree
Hide file tree
Showing 19 changed files with 715 additions and 374 deletions.
38 changes: 36 additions & 2 deletions src/Controller/Tools/SitepackageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function index(): Response
}

#[Route(path: '/new', name: 'tools_sitepackage_new')]
#[Route(path: '/new/{vendor}/{project}', name: 'tools_sitepackage_new_filtered')]
#[Route(path: '/new/{vendor}/{project}', name: 'tools_sitepackage_new')]
public function new(string $vendor = '', string $project = ''): Response
{
$this->setSitepackageConfig(new SitepackageDto(), false);
Expand Down Expand Up @@ -95,6 +95,40 @@ public function new(string $vendor = '', string $project = ''): Response
);
}

#[Route(path: '/detail/{vendor}/{project}', name: 'tools_sitepackage_detail')]
#[Route(path: '/detail/{vendor}/{project}/{typo3Version}', name: 'tools_sitepackage_detail')]
public function detail(string $vendor, string $project, string $typo3Version = ''): Response
{
$this->setSitepackageConfig(new SitepackageDto(), false);

$basePackageName = sprintf('%s/%s', $vendor, $project);

try {
$basePackage = $this->basePackageService->checkAndInstallMissingBasePackage($basePackageName);

if ($typo3Version === '') {
$typo3Version = $basePackage->getTypo3Versions()[0];
}

$basePackageTemplate = $basePackage->getTemplates()[$typo3Version];
} catch (Throwable $throwable) {
$this->addFlash(
'fatal',
$throwable->getMessage()
);
return $this->redirectToRoute('tools_sitepackage_new');
}

return $this->render(
'tools/sitepackage/detail.html.twig',
[
'basePackage' => $basePackage,
'basePackageTemplate' => $basePackageTemplate,
'typo3Version' => $typo3Version,
]
);
}

#[Route(path: '/validate/{vendor}/{project}', name: 'tools_sitepackage_validate')]
public function validate(string $vendor, string $project): RedirectResponse
{
Expand All @@ -108,7 +142,7 @@ public function validate(string $vendor, string $project): RedirectResponse

try {
$basePackage = $this->basePackageService->checkAndInstallMissingBasePackage($configuration->basePackage);
$configuration->typo3Version = VersionUtility::versionToInt($basePackage->typo3Versions[0]);
$configuration->typo3Version = VersionUtility::versionToInt($basePackage->getTypo3Versions()[0]);
} catch (Throwable $throwable) {
$this->addFlash(
'fatal',
Expand Down
122 changes: 0 additions & 122 deletions src/Form/Dto/BasePackageDto.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Form/SitepackageType.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add('typo3Version', Typo3VersionType::class, [
'label' => 'TYPO3 Version',
'choice_filter' => static function (int $version) use ($basePackage): bool {
foreach ($basePackage->typo3Versions as $typo3Version) {
foreach ($basePackage->getTypo3Versions() as $typo3Version) {
if ($version < VersionUtility::versionToInt($typo3Version)) {
continue;
}

if ($version % 1_000_000 !== VersionUtility::versionToInt($typo3Version) % 1_000_000) {
if ($version / 1_000_000 !== VersionUtility::versionToInt($typo3Version) / 1_000_000) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Type/BasePackageType.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function configureOptions(OptionsResolver $resolver): void
$choices = [];

foreach ($this->basePackageService->getInstalledBasePackages() as $basePackage) {
$choices[sprintf('%s (%s)', $basePackage->title, $basePackage->packageName)] = $basePackage->packageName;
$choices[sprintf('%s (%s)', $basePackage->getTitle(), $basePackage->getComposerPackageName())] = $basePackage->getComposerPackageName();
}

$resolver->setDefaults([
Expand Down
138 changes: 138 additions & 0 deletions src/Package/BasePackage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package t3o/get.typo3.org.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

namespace App\Package;

use App\Entity\BasePackage as BasePackageEntity;
use App\Package\Manifest\BasePackageManifest;
use Composer\Package\PackageInterface as ComposerPackage;

use function explode;

class BasePackage
{
/**
* @var BasePackageTemplate[]
*/
private array $templates = [];

public readonly BasePackageManifest $manifest;

public static function fromPackage(
string $composerPackageInstallPath,
ComposerPackage $composerPackage,
?BasePackageEntity $entity = null
): self {
$basePackage = new self(
$composerPackageInstallPath,
$composerPackage->getName(),
($entity !== null) ? $entity->isActive() : true,
$entity !== null && $entity->isOfficial(),
($entity === null)
);

return $basePackage;
}

public function __construct(
private readonly string $composerPackageInstallPath,
private readonly string $composerPackageName,
public readonly bool $active,
public readonly bool $official,
public readonly bool $thirdParty,
) {
$this->manifest = new BasePackageManifest($this->composerPackageInstallPath);
}

public function getAssetsDir(): string
{
return str_replace('/', '-', strtolower($this->composerPackageName));
}

public function getAssetPreviewImage(): string
{
return \sprintf('%s/images/%s', $this->getAssetsDir(), $this->manifest->getPreviewImage());
}

public function getInstallPath(): string
{
return $this->composerPackageInstallPath;
}

public function getPublicInstallPath(): string
{
return \sprintf('%s/public', $this->composerPackageInstallPath);
}

public function getComposerPackageName(): string
{
return $this->composerPackageName;
}

public function getComposerVendorName(): string
{
return explode('/', strtolower($this->composerPackageName))[0];
}

public function getComposerProjectName(): string
{
return explode('/', strtolower($this->composerPackageName))[1];
}

public function getTitle(): string
{
return $this->manifest->getTitle();
}

public function getDescription(): string
{
return $this->manifest->getDescription();
}

/**
* @return string[]
*/
public function getTypo3Versions(): array
{
return $this->manifest->getTypo3Versions();
}

public function getPreviewImage(): string
{
return $this->manifest->getPreviewImage();
}

/**
* @return BasePackageTemplate[]
*/
public function getTemplates(): array
{
if ($this->templates === []) {
foreach ($this->getTypo3Versions() as $typo3Version) {
$this->templates[$typo3Version] = new BasePackageTemplate($this->composerPackageInstallPath, $this, $typo3Version);
}
}

return $this->templates;
}
}
Loading

0 comments on commit 58f3f8c

Please sign in to comment.