Skip to content

Commit f2ff74c

Browse files
authored
Merge pull request #23 from assoconnect/validator_bundle
Implement validation bundle
2 parents e2299b0 + d200f8e commit f2ff74c

10 files changed

Lines changed: 144 additions & 15 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"require-dev": {
1717
"symfony/contracts": "^2.4",
1818
"symfony/translation": "^4.2|^5.0",
19-
"assoconnect/php-quality-config": "^1.0"
19+
"assoconnect/php-quality-config": "^1.0",
20+
"assoconnect/validator-bundle": "^2.19"
2021
},
2122
"require": {
2223
"ext-intl": "*",

config/services.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
services:
2+
_defaults:
3+
autowire: true # Automatically injects dependencies in your services.
4+
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
5+
public: false # Allows optimizing the container by removing unused services; this also means
6+
# fetching services directly from the container via $container->get() won't work.
7+
# The best practice is to be explicit about your dependencies anyway.
8+
9+
AssoConnect\PHPDate\LocalizedStringParser:
10+
class: AssoConnect\PHPDate\LocalizedStringParser
11+
12+
AssoConnect\PHPDateBundle\Normalizer\AbsoluteDateNormalizer:
13+
tags:
14+
- 'serializer.normalizer'
15+
16+
AssoConnect\PHPDateBundle\Twig\Extension\AbsoluteDateExtension:
17+
arguments:
18+
- '@translator'
19+
tags:
20+
- 'twig.extension'
21+
22+
AssoConnect\PHPDateBundle\Validator\:
23+
resource: "../src/Validator/*"

phpstan-baseline.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Method AssoConnect\\\\PHPDateBundle\\\\Translatable\\\\AbsoluteDateTranslatable\\:\\:trans\\(\\) should return string but returns string\\|true\\.$#"
5+
count: 1
6+
path: src/Translatable/AbsoluteDateTranslatable.php

phpstan.neon.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ parameters:
22
paths:
33
- src/
44
- tests/
5+
exceptions:
6+
uncheckedExceptionClasses:
7+
- 'Symfony\Component\Validator\Exception\ConstraintDefinitionException'
8+
- 'Symfony\Component\Validator\Exception\InvalidOptionsException'
9+
- 'Symfony\Component\Validator\Exception\MissingOptionsException'
510

611
includes:
712
- vendor/assoconnect/php-quality-config/phpstan.extension.neon
13+
- phpstan-baseline.neon

src/DependencyInjection/PHPDateExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function load(array $configs, ContainerBuilder $container): void
3434
// Loading config.yml file
3535
$loader = new YamlFileLoader(
3636
$container,
37-
new FileLocator(__DIR__ . '/../Resources/config')
37+
new FileLocator(__DIR__ . '/../../config')
3838
);
3939
$loader->load('services.yaml');
4040
}

src/Resources/config/services.yaml

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AssoConnect\PHPDateBundle\Validator\ConstraintsSetFactory\Field;
6+
7+
use AssoConnect\PHPDate\AbsoluteDate;
8+
use AssoConnect\PHPDateBundle\Doctrine\DBAL\Types\AbsoluteDateType;
9+
use AssoConnect\ValidatorBundle\Validator\ConstraintsSetProvider\Field\FieldConstraintsSetProviderInterface;
10+
use Symfony\Component\Validator\Constraints\Type;
11+
12+
class AbsoluteDateProvider implements FieldConstraintsSetProviderInterface
13+
{
14+
public function supports(string $type): bool
15+
{
16+
return AbsoluteDateType::NAME === $type;
17+
}
18+
19+
public function getConstraints(array $fieldMapping): array
20+
{
21+
return [
22+
new Type(AbsoluteDate::class),
23+
];
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AssoConnect\PHPDateBundle\Validator\ConstraintsSetFactory\Field;
6+
7+
use AssoConnect\PHPDateBundle\Doctrine\DBAL\Types\DateTimeZoneType;
8+
use AssoConnect\ValidatorBundle\Validator\ConstraintsSetProvider\Field\FieldConstraintsSetProviderInterface;
9+
use DateTimeZone;
10+
use Symfony\Component\Validator\Constraints\Type;
11+
12+
class DateTimeZoneProvider implements FieldConstraintsSetProviderInterface
13+
{
14+
public function supports(string $type): bool
15+
{
16+
return DateTimeZoneType::NAME === $type;
17+
}
18+
19+
public function getConstraints(array $fieldMapping): array
20+
{
21+
return [
22+
new Type(DateTimeZone::class),
23+
];
24+
}
25+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AssoConnect\PHPDateBundle\Tests\Validator\ConstraintsSetFactory\Field;
6+
7+
use AssoConnect\PHPDate\AbsoluteDate;
8+
use AssoConnect\PHPDateBundle\Doctrine\DBAL\Types\AbsoluteDateType;
9+
use AssoConnect\PHPDateBundle\Validator\ConstraintsSetFactory\Field\AbsoluteDateProvider;
10+
use AssoConnect\ValidatorBundle\Test\FieldConstraintsSetProviderTestCase;
11+
use AssoConnect\ValidatorBundle\Validator\ConstraintsSetProvider\Field\FieldConstraintsSetProviderInterface;
12+
use Symfony\Component\Validator\Constraints\Type;
13+
14+
class AbsoluteDateProviderTest extends FieldConstraintsSetProviderTestCase
15+
{
16+
protected function getFactory(): FieldConstraintsSetProviderInterface
17+
{
18+
return new AbsoluteDateProvider();
19+
}
20+
21+
public function getConstraintsForTypeProvider(): iterable
22+
{
23+
yield [
24+
['type' => AbsoluteDateType::NAME],
25+
[new Type(AbsoluteDate::class)],
26+
];
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AssoConnect\PHPDateBundle\Tests\Validator\ConstraintsSetFactory\Field;
6+
7+
use AssoConnect\PHPDateBundle\Doctrine\DBAL\Types\DateTimeZoneType;
8+
use AssoConnect\PHPDateBundle\Validator\ConstraintsSetFactory\Field\DateTimeZoneProvider;
9+
use AssoConnect\ValidatorBundle\Test\FieldConstraintsSetProviderTestCase;
10+
use AssoConnect\ValidatorBundle\Validator\ConstraintsSetProvider\Field\FieldConstraintsSetProviderInterface;
11+
use DateTimeZone;
12+
use Symfony\Component\Validator\Constraints\Type;
13+
14+
class DateTimeZoneProviderTest extends FieldConstraintsSetProviderTestCase
15+
{
16+
protected function getFactory(): FieldConstraintsSetProviderInterface
17+
{
18+
return new DateTimeZoneProvider();
19+
}
20+
21+
public function getConstraintsForTypeProvider(): iterable
22+
{
23+
yield [
24+
['type' => DateTimeZoneType::NAME],
25+
[new Type(DateTimeZone::class)],
26+
];
27+
}
28+
}

0 commit comments

Comments
 (0)