-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Add BasePackageVersionSupport validation
- Loading branch information
1 parent
c839517
commit 0116c83
Showing
5 changed files
with
118 additions
and
5 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
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
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,35 @@ | ||
<?php | ||
|
||
/* | ||
* 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\Validator; | ||
|
||
use Symfony\Component\Validator\Constraint; | ||
|
||
#[\Attribute(\Attribute::TARGET_CLASS)] | ||
class BasePackageVersionSupport extends Constraint | ||
{ | ||
public string $message = 'The Base Package "{{ basePackage }}" is not compatible with TYPO3 Version "{{ typo3Version }}".'; | ||
|
||
public function getTargets(): string | ||
{ | ||
return self::CLASS_CONSTRAINT; | ||
} | ||
} |
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,59 @@ | ||
<?php | ||
|
||
/* | ||
* 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\Validator; | ||
|
||
use App\Entity\SitePackage; | ||
use App\Service\SitePackageBaseService; | ||
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\ConstraintValidator; | ||
|
||
class BasePackageVersionSupportValidator extends ConstraintValidator | ||
{ | ||
private SitePackageBaseService $sitePackageBaseService; | ||
|
||
public function __construct(SitePackageBaseService $sitePackageBaseService) | ||
{ | ||
$this->sitePackageBaseService = $sitePackageBaseService; | ||
} | ||
|
||
public function validate(mixed $object, Constraint $constraint) | ||
{ | ||
if (!$constraint instanceof BasePackageVersionSupport) { | ||
throw new \LogicException('Invalid constraint type.'); | ||
} | ||
|
||
if (!$object instanceof SitePackage) { | ||
throw new \LogicException('Object must be of type ' . SitePackage::class); | ||
} | ||
|
||
$basePackage = $object->getBasePackage(); | ||
$typo3Version = $object->getTypo3Version(); | ||
|
||
$package = $this->sitePackageBaseService->getPackage($basePackage); | ||
if ($package === null || !$package->hasVersionSupport($typo3Version)) { | ||
$this->context->buildViolation($constraint->message) | ||
->setParameter('{{ basePackage }}', $basePackage) | ||
->setParameter('{{ typo3Version }}', (string)$typo3Version) | ||
->addViolation(); | ||
} | ||
} | ||
} |