wiki/content/20201112132007-automatic_validation_based_on_doctrine_mapping.md

805 B

date id title
2020-11-12 c7132269-2084-4d87-9888-0f860db29aaf Automatic Validation Based on Doctrine Mapping

Description

From Symfony 4.3, Symfony introduces automatic validation based on Doctrine mapping.

Examples

use Doctrine\ORM\Mapping as ORM;

/** @ORM\Entity */
class SomeEntity
{
    // ...

    /** @ORM\Column(length=4) */
    public $pinCode;
}
$entity = new SomeEntity();
$entity->pinCode = '1234567890';
$violationList = $validator->validate($entity);
$violationList = $validator->validate($entity);

var_dump((string) $violationList);
// Object(App\Entity\SomeEntity).columnLength:\n
//     This value is too long. It should have 4 characters or less.
//     (code d94b19cc-114f-4f44-9cc4-4138e80a87b9)\n