mirror of
https://github.com/opdavies/build-configs.git
synced 2025-09-06 11:25:33 +01:00
refactor: extract a configuration validator
This commit is contained in:
parent
46747d2bf8
commit
a70557d2d5
4 changed files with 77 additions and 43 deletions
58
src/Validator/ConfigurationValidator.php
Normal file
58
src/Validator/ConfigurationValidator.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OliverDaviesLtd\BuildConfigs\Validator;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
final class ConfigurationValidator implements ValidatorInterface
|
||||
{
|
||||
public function validate(array $configurationData): ConstraintViolationListInterface
|
||||
{
|
||||
$validator = Validation::createValidator();
|
||||
|
||||
$groups = new Assert\GroupSequence(['Default', 'custom']);
|
||||
|
||||
$constraint = new Assert\Collection(
|
||||
[
|
||||
'name' => [
|
||||
new Assert\NotNull(),
|
||||
new Assert\Type('string'),
|
||||
new Assert\Length(['min' => 1]),
|
||||
],
|
||||
|
||||
'language' => [
|
||||
new Assert\NotNull(),
|
||||
new Assert\Type('string'),
|
||||
new Assert\Choice(['php']),
|
||||
],
|
||||
|
||||
'type' => [
|
||||
new Assert\NotNull(),
|
||||
new Assert\Type('string'),
|
||||
new Assert\Choice(['drupal-project', 'php-library']),
|
||||
],
|
||||
|
||||
'database' => new Assert\Optional(),
|
||||
|
||||
'drupal' => new Assert\Optional(),
|
||||
|
||||
'docker-compose' => new Assert\Optional(),
|
||||
|
||||
'dockerfile' => new Assert\Optional(),
|
||||
|
||||
// TODO: this should be a boolean if present.
|
||||
'justfile' => new Assert\Optional(),
|
||||
|
||||
'php' => new Assert\Optional(),
|
||||
|
||||
'web' => new Assert\Optional(),
|
||||
],
|
||||
);
|
||||
|
||||
return $validator->validate($configurationData, $constraint, $groups);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue