Skip to content

Commit

Permalink
[WIP][TASK] Detect basepackages
Browse files Browse the repository at this point in the history
@todo add validation
@check endpoints
  • Loading branch information
benjaminkott committed Nov 25, 2024
1 parent 43bf37d commit 1c07262
Show file tree
Hide file tree
Showing 10 changed files with 371 additions and 23 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"symfony/dependency-injection": "^6.2",
"symfony/dotenv": "^6.2",
"symfony/expression-language": "^6.2",
"symfony/finder": "^6.2",
"symfony/flex": "^2.2",
"symfony/form": "^6.2",
"symfony/framework-bundle": "^6.2",
Expand Down
26 changes: 13 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ parameters:
count: 1
path: src/Service/ComposerPackagesService.php

-
message: '#^Method App\\Service\\SitepackageBaseService\:\:getBasepackageVersionChoices\(\) should return array\<string, float\> but returns array\<int\|string, float\>\.$#'
identifier: return.type
count: 1
path: src/Service/SitepackageBaseService.php

-
message: '#^Parameter \#1 \$releases of method App\\Twig\\Filter\\SortByVersion\:\:sort\(\) expects Doctrine\\Common\\Collections\\Collection\<int, App\\Entity\\Release\>, mixed given\.$#'
identifier: argument.type
Expand Down
1 change: 1 addition & 0 deletions resources/packages/bootstrap_package/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
label: Bootstrap Package
1 change: 1 addition & 0 deletions resources/packages/fluid_styled_content/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
label: Fluid Styled Content
67 changes: 67 additions & 0 deletions src/Command/BasepackagesCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?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\Command;

use App\Entity\Sitepackage\BasepackageVersion;
use App\Service\SitepackageBaseService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class BasepackagesCommand extends Command
{
protected static $defaultName = 'app:sitepackagegenerator:basepackage-list';

public function __construct(private readonly SitepackageBaseService $sitepackageBaseService)
{
parent::__construct();
}

protected function configure(): void
{
$this->setDescription('Display all available Basepackages.');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$packages = $this->sitepackageBaseService->getPackages();

$rows = [];
foreach ($packages as $package) {
$rows[] = [
$package->getIdentifier(),
$package->getLabel(),
implode(', ', array_map(static fn(BasepackageVersion $version): float => $version->getVersion(), $package->getVersions()->toArray())),
];
}

$table = new Table($output);
$table->setHeaders(['Identifier', 'Label', 'Versions']);
$table->setRows($rows);
$table->render();

return self::SUCCESS;
}
}
93 changes: 93 additions & 0 deletions src/Entity/Sitepackage/Basepackage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?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\Entity\Sitepackage;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;

class Basepackage
{
protected string $identifier;
protected string $label;

/**
* @var ArrayCollection<int, BasepackageVersion>
*/
protected ArrayCollection $versions;

public function __construct()
{
$this->versions = new ArrayCollection();
}

public function getIdentifier(): string
{
return $this->identifier;
}

public function setIdentifier(string $identifier): self
{
$this->identifier = $identifier;

return $this;
}

public function getLabel(): string
{
return $this->label;
}

public function setLabel(string $label): self
{
$this->label = $label;

return $this;
}

/**
* @return ArrayCollection<int, BasepackageVersion>
*/
public function getVersions(): ArrayCollection
{
return $this->versions->matching(new Criteria(null, ['version' => Criteria::DESC]));
}

public function addVersion(BasepackageVersion $version): self
{
if (!$this->versions->contains($version)) {
$this->versions[] = $version;
}

return $this;
}

public function removeVersion(BasepackageVersion $version): static
{
if ($this->versions->contains($version)) {
$this->versions->removeElement($version);
}

return $this;
}
}
41 changes: 41 additions & 0 deletions src/Entity/Sitepackage/BasepackageVersion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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\Entity\Sitepackage;

class BasepackageVersion
{
protected float $version;

public function getVersion(): float
{
return $this->version;
}

public function setVersion(float $version): self
{
$this->version = $version;

return $this;
}
}
27 changes: 17 additions & 10 deletions src/Form/SitepackageType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
namespace App\Form;

use App\Entity\Sitepackage;
use App\Service\SitepackageBaseService;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
Expand All @@ -33,29 +35,34 @@

class SitepackageType extends AbstractType
{
private SitepackageBaseService $sitepackageBaseService;

public function __construct(SitepackageBaseService $sitepackageBaseService)
{
$this->sitepackageBaseService = $sitepackageBaseService;
}

/**
* @param array<string, mixed> $options
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$sitepackageBaseService = $this->sitepackageBaseService;

$builder
->setAction($options['action'])
->add('basePackage', ChoiceType::class, [
'label' => 'Base Package',
'choices' => [
'Bootstrap Package' => 'bootstrap_package',
'Fluid Styled Content' => 'fluid_styled_content',
],
'choice_loader' => new CallbackChoiceLoader(static function () use ($sitepackageBaseService): array {
return $sitepackageBaseService->getBasepackageChoices();
}),
'expanded' => true,
])
->add('typo3Version', ChoiceType::class, [
'label' => 'TYPO3 Version',
'choices' => [
'13.4 (Beta)' => 13.4,
'12.4' => 12.4,
'11.5' => 11.5,
'10.4' => 10.4,
],
'choice_loader' => new CallbackChoiceLoader(static function () use ($sitepackageBaseService): array {
return $sitepackageBaseService->getBasepackageVersionChoices();
}),
'expanded' => true,
])
->add('title', TextType::class, [
Expand Down
Loading

0 comments on commit 1c07262

Please sign in to comment.