Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Latest commit

 

History

History
82 lines (71 loc) · 1.4 KB

CoordinateConstraint.md

File metadata and controls

82 lines (71 loc) · 1.4 KB

CoordinateConstraint

<?php

use Chubbyphp\Validation\Constraint\CoordinateConstraint;
use Chubbyphp\Validation\ValidatorContextInterface;

$constraint = new CoordinateConstraint();

/** @var ValidatorContextInterface $context */
$context = ...;

// Use NotNullConstraint to prevent null
$errors = $constraint->validate(
    'path.to.property',
    null,
    $context
);
// [];

// Use NotBlankConstraint to prevent ''
$errors = $constraint->validate(
    'path.to.property',
    '',
    $context
);
// [];

$errors = $constraint->validate(
    'path.to.property',
    '90.0, 180.0',
    $context
);
// [];

$errors = $constraint->validate(
    'path.to.property',
    '-90.0, -180.0',
    $context
);
// [];

$errors = $constraint->validate(
    'path.to.property',
    [],
    $context
);
// [
//     new Error(
//         'path.to.property',
//         'constraint.coordinate.invalidtype',
//         ['type' => 'array']
//     )
// ];

$errors = $constraint->validate(
    'path.to.property',
    '90',
    $context
);
// [
//     new Error(
//         'path.to.property',
//         'constraint.coordinate.invalidformat',
//         ['value' => '90']
//     )
// ];

$errors = $constraint->validate(
    'path.to.property',
    '90.1, 180.1',
    $context
);
// [
//     new Error(
//         'path.to.property',
//         'constraint.coordinate.invalidvalue',
//         ['value' => '90.1, 180.1']
//     )
// ];