diff --git a/src/Symfony/Component/Validator/CHANGELOG.md b/src/Symfony/Component/Validator/CHANGELOG.md index c95fc1b84ade7..0a4e6a924beff 100644 --- a/src/Symfony/Component/Validator/CHANGELOG.md +++ b/src/Symfony/Component/Validator/CHANGELOG.md @@ -126,7 +126,8 @@ CHANGELOG } } ``` - + * Add Latitude and Longitude Constraints + 7.3 --- diff --git a/src/Symfony/Component/Validator/Constraints/Latitude.php b/src/Symfony/Component/Validator/Constraints/Latitude.php new file mode 100644 index 0000000000000..9e92c5133ee1a --- /dev/null +++ b/src/Symfony/Component/Validator/Constraints/Latitude.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Constraints; + +use Symfony\Component\Validator\Constraint; + +#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] +final class Latitude extends Constraint +{ + public const INVALID_LATITUDE_ERROR = '2f01c7bf-43ec-487c-a173-bcc305d3bbd1'; + + protected const ERROR_NAMES = [ + self::INVALID_LATITUDE_ERROR => 'INVALID_LATITUDE_ERROR', + ]; + + public function __construct( + public string $mode = 'strict', + public string $message = 'This value must contain valid latitude coordinates.', + ?array $groups = null, + mixed $payload = null, + ) { + parent::__construct(null, $groups, $payload); + } +} diff --git a/src/Symfony/Component/Validator/Constraints/LatitudeValidator.php b/src/Symfony/Component/Validator/Constraints/LatitudeValidator.php new file mode 100644 index 0000000000000..9e37bd45a25aa --- /dev/null +++ b/src/Symfony/Component/Validator/Constraints/LatitudeValidator.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Constraints; + +use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; +use Symfony\Component\Validator\Exception\UnexpectedValueException; + +final class LatitudeValidator extends ConstraintValidator +{ + public function validate(mixed $value, Constraint $constraint): void + { + if (!$constraint instanceof Latitude) { + throw new UnexpectedTypeException($constraint, Latitude::class); + } + + if (null === $value || '' === $value) { + return; + } + + if (!\is_scalar($value) && !$value instanceof \Stringable) { + throw new UnexpectedValueException($value, 'string'); + } + + // Accept only strings or numbers + if (!\is_string($value) && !is_numeric($value)) { + $this->context->buildViolation($constraint->message) + ->setParameter('{{ value }}', $value) + ->addViolation(); + + return; + } + + if (!preg_match('/^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?)$/', (string) $value)) { + $this->context->buildViolation($constraint->message) + ->setParameter('{{ value }}', $value) + ->setCode(Latitude::INVALID_LATITUDE_ERROR) + ->addViolation(); + } + } +} diff --git a/src/Symfony/Component/Validator/Constraints/Longitude.php b/src/Symfony/Component/Validator/Constraints/Longitude.php new file mode 100644 index 0000000000000..d2e9f5a7377d5 --- /dev/null +++ b/src/Symfony/Component/Validator/Constraints/Longitude.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Constraints; + +use Symfony\Component\Validator\Constraint; + +#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] +final class Longitude extends Constraint +{ + public const INVALID_LONGITUDE_ERROR = '2984c3a9-702d-40bb-b53e-74d81de37ea2'; + + protected const ERROR_NAMES = [ + self::INVALID_LONGITUDE_ERROR => 'INVALID_LONGITUDE_ERROR', + ]; + + public function __construct( + public string $mode = 'strict', + public string $message = 'This value must contain valid longitude coordinates.', + ?array $groups = null, + mixed $payload = null, + ) { + parent::__construct(null, $groups, $payload); + } +} diff --git a/src/Symfony/Component/Validator/Constraints/LongitudeValidator.php b/src/Symfony/Component/Validator/Constraints/LongitudeValidator.php new file mode 100644 index 0000000000000..48080f4e60463 --- /dev/null +++ b/src/Symfony/Component/Validator/Constraints/LongitudeValidator.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Constraints; + +use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; +use Symfony\Component\Validator\Exception\UnexpectedValueException; + +final class LongitudeValidator extends ConstraintValidator +{ + public function validate(mixed $value, Constraint $constraint): void + { + if (!$constraint instanceof Longitude) { + throw new UnexpectedTypeException($constraint, Longitude::class); + } + + if (null === $value || '' === $value) { + return; + } + + if (!\is_scalar($value) && !$value instanceof \Stringable) { + throw new UnexpectedValueException($value, 'string'); + } + + // Accept only strings or numbers + if (!\is_string($value) && !is_numeric($value)) { + $this->context->buildViolation($constraint->message) + ->setParameter('{{ value }}', $value) + ->addViolation(); + + return; + } + + if (!preg_match('/^[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/', (string) $value)) { + $this->context->buildViolation($constraint->message) + ->setParameter('{{ value }}', '"'.$value.'"') + ->setCode(Longitude::INVALID_LONGITUDE_ERROR) + ->addViolation(); + } + } +} diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.af.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.af.xlf index 9f53b1afe35c3..c617e4e0bd4b9 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.af.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.af.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Hierdie waarde is nie 'n geldige Twig-sjabloon nie. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.ar.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.ar.xlf index 827eed1bcc86e..070d92df5469d 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.ar.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.ar.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. هذه القيمة ليست نموذج Twig صالح. + + This value must contain valid latitude coordinates. + هذه القيمة يجب أن تحتوي على إحداثيات خط عرض صالحة. + + + This value must contain valid longitude coordinates. + هذه القيمة يجب أن تحتوي على إحداثيات خط طول صالحة. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.az.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.az.xlf index 9332c9ec2fd93..96098af36d552 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.az.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.az.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Bu dəyər etibarlı Twig şablonu deyil. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.be.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.be.xlf index 7b24df5e5c189..649d99362a565 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.be.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.be.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Гэта значэнне не з'яўляецца сапраўдным шаблонам Twig. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.bg.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.bg.xlf index afd7590f51cb9..489523d44dacf 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.bg.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.bg.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Тази стойност не е валиден Twig шаблон. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.bs.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.bs.xlf index d6b7de5768ee5..d383b8638d556 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.bs.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.bs.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Ova vrijednost nije važeći Twig šablon. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.ca.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.ca.xlf index d656ef540f825..17a9f404d3ef0 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.ca.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.ca.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Aquest valor no és una plantilla Twig vàlida. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.cs.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.cs.xlf index d5f48f0ae7ff2..c7c3e82b86e03 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.cs.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.cs.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Tato hodnota není platná Twig šablona. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.cy.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.cy.xlf index 08a76667d5f4a..2dfba9c2ec0be 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.cy.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.cy.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Nid yw'r gwerth hwn yn dempled Twig dilys. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.da.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.da.xlf index bb05bba2e641c..356512bad2c2f 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.da.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.da.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Denne værdi er ikke en gyldig Twig-skabelon. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.de.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.de.xlf index f02c56c6c5ca9..7cfe94ba965a7 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.de.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.de.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Dieser Wert ist kein valides Twig-Template. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.el.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.el.xlf index 9aec12ff82ce7..9cae636776ab2 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.el.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.el.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Αυτή η τιμή δεν είναι έγκυρο πρότυπο Twig. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.en.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.en.xlf index f8c664f18c423..85f3d85b42b3f 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.en.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.en.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. This value is not a valid Twig template. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.es.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.es.xlf index a9ad8a76b11e9..b5f4a241a4019 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.es.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.es.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Este valor no es una plantilla Twig válida. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.et.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.et.xlf index 2375aa4ade30c..02ac77d8606f8 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.et.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.et.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. See väärtus ei ole kehtiv Twig'i mall. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.eu.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.eu.xlf index 830f8673dff94..27ea132812206 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.eu.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.eu.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Balio hau ez da Twig txantiloi baliozko bat. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.fa.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.fa.xlf index f47633fd4a624..4e63088f6ebb0 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.fa.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.fa.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. این مقدار یک قالب معتبر Twig نیست. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.fi.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.fi.xlf index c046963f7ec66..192d54ea82992 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.fi.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.fi.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Tämä arvo ei ole kelvollinen Twig-malli. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.fr.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.fr.xlf index 13033c01973c8..9036287adb52c 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.fr.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.fr.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Cette valeur n'est pas un modèle Twig valide. + + This value must contain valid latitude coordinates. + Cette valeur doit contenir des coordonnées de latitude valides. + + + This value must contain valid longitude coordinates. + Cette valeur doit contenir des coordonnées de longitude valides. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.gl.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.gl.xlf index 391d741e96564..d6676bb13666a 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.gl.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.gl.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Este valor non é un modelo Twig válido. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.he.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.he.xlf index 671a98881536e..fd4153a1d31c8 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.he.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.he.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. ערך זה אינו תבנית Twig חוקית. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.hr.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.hr.xlf index 0951d41926514..bb05d69f6edc3 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.hr.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.hr.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Ova vrijednost nije valjani Twig predložak. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.hu.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.hu.xlf index dffab0ccbf700..848c047a29c84 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.hu.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.hu.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Ez az érték nem érvényes Twig sablon. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.hy.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.hy.xlf index 856babbd5fe4e..eecf8e3beb7c9 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.hy.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.hy.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Այս արժեքը վավեր Twig ձևանմուշ չէ: + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.id.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.id.xlf index b9796f888f924..6548b36a1f5b1 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.id.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.id.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Nilai ini bukan templat Twig yang valid. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.it.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.it.xlf index 34ef61ed5f8a7..94a0b5d5f347a 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.it.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.it.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Questo valore non è un template Twig valido. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.ja.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.ja.xlf index 42e51903c974c..d6c1eabd10d20 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.ja.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.ja.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. 有効なTwigテンプレートではありません。 + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.lb.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.lb.xlf index d1b5cef57bd0e..d3b5fed0b4528 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.lb.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.lb.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Dëse Wäert ass kee valabelen Twig-Template. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.lt.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.lt.xlf index 46abd95036044..80affbbfc9b6a 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.lt.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.lt.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Ši reikšmė nėra tinkamas „Twig“ šablonas. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.lv.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.lv.xlf index 3e2d51a30dec1..ee79bebd50dab 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.lv.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.lv.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Šī vērtība nav derīgs Twig šablons. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.mk.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.mk.xlf index 99b1a191b6c0d..bb7deda6628e1 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.mk.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.mk.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Оваа вредност не е валиден Twig шаблон. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.mn.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.mn.xlf index 3344675d9ae6a..09d12590d878e 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.mn.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.mn.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Энэ утга нь Twig-ийн хүчинтэй загвар биш юм. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.my.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.my.xlf index 04c955f754509..e01e5b7bf76e4 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.my.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.my.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. ဤတန်ဖိုးသည် မှန်ကန်သော Twig တင်းပလိတ်မဟုတ်ပါ။ + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.nb.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.nb.xlf index 58696f671ca4a..db9ecc9655057 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.nb.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.nb.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Denne verdien er ikke en gyldig Twig-mal. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.nl.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.nl.xlf index 1781b1f29ec64..d019597589b4d 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.nl.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.nl.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Deze waarde is geen geldige Twig-template. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.nn.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.nn.xlf index 74d332c06efb2..8775a35c276a7 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.nn.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.nn.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Denne verdien er ikkje ein gyldig Twig-mal. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.no.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.no.xlf index 58696f671ca4a..db9ecc9655057 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.no.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.no.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Denne verdien er ikke en gyldig Twig-mal. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.pl.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.pl.xlf index 04fe2fc1f1926..9036074649ad0 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.pl.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.pl.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Ta wartość nie jest prawidłowym szablonem Twig. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.pt.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.pt.xlf index b6562dbfe712f..fdc456584f8cd 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.pt.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.pt.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Este valor não é um modelo Twig válido. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.pt_BR.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.pt_BR.xlf index 0acf6dbf23a6c..546545e144c29 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.pt_BR.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.pt_BR.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Este valor não é um modelo Twig válido. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.ro.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.ro.xlf index d6c3b4fb82984..860ec66346326 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.ro.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.ro.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Această valoare nu este un șablon Twig valid. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.ru.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.ru.xlf index 727ae0aefdf86..dc23b3083e142 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.ru.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.ru.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Это значение не является корректным шаблоном Twig. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.sk.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.sk.xlf index bba3c291a7fed..396a34bb3d1b6 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.sk.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.sk.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Táto hodnota nie je platná šablóna Twig. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.sl.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.sl.xlf index 28c370e096887..def21f22ac90f 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.sl.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.sl.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Ta vrednost ni veljavna predloga Twig. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.sq.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.sq.xlf index 7d044b8fc3ace..a20ae4f229b17 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.sq.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.sq.xlf @@ -479,6 +479,14 @@ This value is not a valid Twig template. Kjo vlerë nuk është një shabllon Twig i vlefshëm. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.sr_Cyrl.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.sr_Cyrl.xlf index 61040270ac884..4c717e447f2ee 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.sr_Cyrl.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.sr_Cyrl.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Ова вредност није важећи Twig шаблон. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.sr_Latn.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.sr_Latn.xlf index be7ede71376d7..88102e87c4140 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.sr_Latn.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.sr_Latn.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Ova vrednost nije važeći Twig šablon. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.sv.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.sv.xlf index 692ac7f52d243..b842e6378ffc5 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.sv.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.sv.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Det här värdet är inte en giltig Twig-mall. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.th.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.th.xlf index 75398a0b84206..f1d8575293a4c 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.th.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.th.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. ค่านี้ไม่ใช่เทมเพลต Twig ที่ถูกต้อง + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.tl.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.tl.xlf index 729ebc9da9185..c9f6824e225ea 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.tl.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.tl.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Ang halagang ito ay hindi isang balidong Twig template. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.tr.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.tr.xlf index 42c4bbd91ebab..88ef42325188b 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.tr.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.tr.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Bu değer geçerli bir Twig şablonu olarak kabul edilmiyor. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.uk.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.uk.xlf index 5f132bc77a6ec..e45da286553b0 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.uk.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.uk.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Це значення не є дійсним шаблоном Twig. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.ur.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.ur.xlf index f13aafb43264b..83cc9346d687f 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.ur.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.ur.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. یہ قدر ایک درست Twig سانچہ نہیں ہے۔ + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.uz.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.uz.xlf index fe0b49f715b12..598a681faa40c 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.uz.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.uz.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Bu qiymat yaroqli Twig shabloni emas. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.vi.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.vi.xlf index 9daa4fe8a29d5..85c4f72302b6d 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.vi.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.vi.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. Giá trị này không phải là một mẫu Twig hợp lệ. + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.zh_CN.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.zh_CN.xlf index c570d936ff17c..628e6fa6c33f5 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.zh_CN.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.zh_CN.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. 此值不是有效的 Twig 模板。 + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.zh_TW.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.zh_TW.xlf index a60283b280898..6a40cd9092dae 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.zh_TW.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.zh_TW.xlf @@ -470,6 +470,14 @@ This value is not a valid Twig template. 這個數值不是有效的 Twig 模板。 + + This value must contain valid latitude coordinates. + This value must contain valid latitude coordinates. + + + This value must contain valid longitude coordinates. + This value must contain valid longitude coordinates. + diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LatitudeTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LatitudeTest.php new file mode 100644 index 0000000000000..30884d998b64b --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LatitudeTest.php @@ -0,0 +1,46 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Tests\Constraints; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Validator\Constraints\Latitude; +use Symfony\Component\Validator\Mapping\ClassMetadata; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; + +class LatitudeTest extends TestCase +{ + public function testAttributes() + { + $metadata = new ClassMetadata(LatitudeDummy::class); + $loader = new AttributeLoader(); + self::assertTrue($loader->loadClassMetadata($metadata)); + + [$bConstraint] = $metadata->properties['b']->getConstraints(); + self::assertSame('myMessage', $bConstraint->message); + self::assertSame(['Default', 'LatitudeDummy'], $bConstraint->groups); + + [$cConstraint] = $metadata->properties['c']->getConstraints(); + self::assertSame(['my_group'], $cConstraint->groups); + } +} + +class LatitudeDummy +{ + #[Latitude] + private $a; + + #[Latitude(message: 'myMessage')] + private $b; + + #[Latitude(groups: ['my_group'])] + private $c; +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LatitudeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LatitudeValidatorTest.php new file mode 100644 index 0000000000000..12ccec3ee8736 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LatitudeValidatorTest.php @@ -0,0 +1,98 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Tests\Constraints; + +use Symfony\Component\Validator\Constraints\Latitude; +use Symfony\Component\Validator\Constraints\LatitudeValidator; +use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; + +class LatitudeValidatorTest extends ConstraintValidatorTestCase +{ + protected function createValidator(): LatitudeValidator + { + return new LatitudeValidator(); + } + + /** + * @dataProvider getValidValues + */ + public function testLatitudeIsValid($value) + { + $this->validator->validate($value, new Latitude()); + + $this->assertNoViolation(); + } + + /** + * @dataProvider getInvalidValues + */ + public function testInvalidValues($value) + { + $constraint = new Latitude(message: 'myMessageTest'); + + $this->validator->validate($value, $constraint); + + $this->buildViolation('myMessageTest') + ->setParameter('{{ value }}', $value) + ->setCode(Latitude::INVALID_LATITUDE_ERROR) + ->assertRaised(); + } + + public static function getValidValues() + { + return [ + [null], + [''], + ['0'], + [0], + ['90'], + [90], + ['-90'], + [-90], + ['89.9999'], + [-89.9999], + ['45.123456'], + [33.975738401584266], + ['+45.0'], + ['+0'], + ['+90.0'], + ['-0.0'], + ['0.0'], + ['45'], + ['-45'], + ['89'], + ['-89'], + ]; + } + + public static function getInvalidValues() + { + return [ + ['90.0001'], + ['-90.0001'], + ['91'], + [-91], + ['180'], + ['-180'], + ['200'], + [-200], + ['abc'], + ['--45'], + ['+'], + [' '], + ['+90.1'], + ['-91'], + ['1,23'], + ['89,999'], + ]; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LongitudeTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LongitudeTest.php new file mode 100644 index 0000000000000..54c9b5ebcee87 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LongitudeTest.php @@ -0,0 +1,46 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Tests\Constraints; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Validator\Constraints\Longitude; +use Symfony\Component\Validator\Mapping\ClassMetadata; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; + +class LongitudeTest extends TestCase +{ + public function testAttributes() + { + $metadata = new ClassMetadata(LongitudeDummy::class); + $loader = new AttributeLoader(); + self::assertTrue($loader->loadClassMetadata($metadata)); + + [$bConstraint] = $metadata->properties['b']->getConstraints(); + self::assertSame('myMessage', $bConstraint->message); + self::assertSame(['Default', 'LongitudeDummy'], $bConstraint->groups); + + [$cConstraint] = $metadata->properties['c']->getConstraints(); + self::assertSame(['my_group'], $cConstraint->groups); + } +} + +class LongitudeDummy +{ + #[Longitude] + private $a; + + #[Longitude(message: 'myMessage')] + private $b; + + #[Longitude(groups: ['my_group'])] + private $c; +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LongitudeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LongitudeValidatorTest.php new file mode 100644 index 0000000000000..056faaf2c29c5 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LongitudeValidatorTest.php @@ -0,0 +1,91 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Tests\Constraints; + +use Symfony\Component\Validator\Constraints\Longitude; +use Symfony\Component\Validator\Constraints\LongitudeValidator; +use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; + +class LongitudeValidatorTest extends ConstraintValidatorTestCase +{ + protected function createValidator(): LongitudeValidator + { + return new LongitudeValidator(); + } + + /** + * @dataProvider getValidValues + */ + public function testLongitudeIsValid($value) + { + $this->validator->validate($value, new Longitude()); + + $this->assertNoViolation(); + } + + /** + * @dataProvider getInvalidValues + */ + public function testInvalidValues($value) + { + $constraint = new Longitude(message: 'myMessageTest'); + + $this->validator->validate($value, $constraint); + + $this->buildViolation('myMessageTest') + ->setParameter('{{ value }}', '"'.$value.'"') + ->setCode(Longitude::INVALID_LONGITUDE_ERROR) + ->assertRaised(); + } + + public static function getValidValues() + { + return [ + [null], + [''], + ['0'], + [0], + ['180'], + [180], + ['-180'], + [-180], + ['179.9999'], + [-179.9999], + ['90'], + ['-90'], + ['45.123456'], + [-6.824053096868544], + ['+45.0'], + ['+0'], + ['+180.0'], + ['-0.0'], + ]; + } + + public static function getInvalidValues() + { + return [ + ['180.0001'], + ['-180.0001'], + ['200'], + [-200], + ['abc'], + ['--45'], + ['+'], + [' '], + ['+180.1'], + ['-181'], + ['1,23'], + ['179,999'], + ]; + } +}