2023-02-22 15:03:01 +00:00
|
|
|
<?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(
|
|
|
|
[
|
2023-03-10 22:10:07 +00:00
|
|
|
'fields' => [
|
|
|
|
'name' => [
|
|
|
|
new Assert\NotNull(),
|
|
|
|
new Assert\Type('string'),
|
|
|
|
new Assert\Length(['min' => 1]),
|
|
|
|
],
|
2023-02-22 15:03:01 +00:00
|
|
|
|
2023-03-10 22:10:07 +00:00
|
|
|
'language' => [
|
|
|
|
new Assert\NotNull(),
|
|
|
|
new Assert\Type('string'),
|
2023-03-12 11:07:20 +00:00
|
|
|
new Assert\Choice(['node', 'php']),
|
2023-03-10 22:10:07 +00:00
|
|
|
],
|
2023-02-22 15:03:01 +00:00
|
|
|
|
2023-03-10 22:10:07 +00:00
|
|
|
'type' => [
|
|
|
|
new Assert\NotNull(),
|
|
|
|
new Assert\Type('string'),
|
|
|
|
new Assert\Choice(['drupal-project', 'php-library']),
|
|
|
|
],
|
2023-02-22 15:03:01 +00:00
|
|
|
|
2023-03-10 22:19:10 +00:00
|
|
|
'project_root' => [
|
|
|
|
new Assert\NotNull(),
|
|
|
|
new Assert\Type('string'),
|
|
|
|
],
|
|
|
|
|
2023-03-10 22:10:07 +00:00
|
|
|
'database' => new Assert\Optional(),
|
2023-02-22 15:03:01 +00:00
|
|
|
|
2023-03-10 22:10:07 +00:00
|
|
|
'drupal' => new Assert\Optional(),
|
2023-02-22 15:03:01 +00:00
|
|
|
|
2023-03-10 22:10:07 +00:00
|
|
|
'docker-compose' => new Assert\Optional(),
|
2023-02-22 15:03:01 +00:00
|
|
|
|
2023-03-10 22:10:07 +00:00
|
|
|
'dockerfile' => new Assert\Optional(),
|
2023-02-22 15:03:01 +00:00
|
|
|
|
2023-03-10 22:10:07 +00:00
|
|
|
// TODO: this should be a boolean if present.
|
|
|
|
'justfile' => new Assert\Optional(),
|
2023-02-22 15:03:01 +00:00
|
|
|
|
2023-03-10 22:10:07 +00:00
|
|
|
'php' => new Assert\Optional(),
|
2023-02-22 15:03:01 +00:00
|
|
|
|
2023-03-10 22:10:07 +00:00
|
|
|
'web' => new Assert\Optional(),
|
|
|
|
],
|
|
|
|
|
|
|
|
'allowExtraFields' => false,
|
|
|
|
'allowMissingFields' => true,
|
2023-02-22 15:03:01 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
|
2023-03-10 22:10:07 +00:00
|
|
|
return $validator->validate(
|
|
|
|
constraints: $constraint,
|
|
|
|
groups: $groups,
|
|
|
|
value: $configurationData,
|
|
|
|
);
|
2023-02-22 15:03:01 +00:00
|
|
|
}
|
|
|
|
}
|