Repository navigation
Expand file tree
/
Copy pathMultiLineStringValidator.php
More file actions
56 lines (47 loc) · 1.91 KB
/
Copy pathMultiLineStringValidator.php
File metadata and controls
56 lines (47 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* This file is part of the spatial project.
*
* PHP 8.4 | 8.5
*
* Copyright Alexandre Tranchant <alexandre.tranchant@gmail.com> 2024-2026
* Copyright Longitude One 2024-2026
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace LongitudeOne\SpatialValidator\Validator\Constraints;
use LongitudeOne\Core\Enum\GeometryTypeEnum;
use LongitudeOne\SpatialTypes\Interfaces\MultiLineStringInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
/** Validate every member through the shared recursive component contract. */
final class MultiLineStringValidator extends ConstraintValidator
{
/**
* @param mixed $value Spatial object to validate
* @param Constraint $constraint Applied constraint
*/
public function validate(mixed $value, Constraint $constraint): void
{
if (!$constraint instanceof MultiLineString) {
throw new UnexpectedTypeException($constraint, MultiLineString::class);
}
// Allow optional spatial values; use NotNull separately when a value is required.
if (null === $value) {
return;
}
if (!$value instanceof MultiLineStringInterface) {
throw new UnexpectedValueException($value, MultiLineStringInterface::class);
}
if (GeometryTypeEnum::MULTILINESTRING !== $value->getType()) {
throw new UnexpectedValueException($value, GeometryTypeEnum::MULTILINESTRING->value);
}
$this->context->getValidator()->inContext($this->context)
->validate($value, new Components(groups: $constraint->groups), $this->context->getGroup())
;
}
}