PHP code example of n7 / symfony-validators-bundle

1. Go to this page and download the library: Download n7/symfony-validators-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

n7 / symfony-validators-bundle example snippets


use N7\SymfonyValidatorsBundle\Validator\NestedObject;
use N7\SymfonyValidatorsBundle\Validator\NestedObjects;
use Symfony\Component\Validator\Constraints;

final class Book
{
    #[Constraints\NotBlank]
    #[Constraints\Type('integer')]
    private int $id;

    #[Constraints\NotBlank]
    #[Constraints\Type('string')]
    private string $title;
}

final class Reader
{
    #[Constraints\NotBlank]
    #[Constraints\Type('integer')]
    private int $id;

    #[Constraints\NotBlank]
    #[NestedObject(Book::class)]
    private Book $favoriteBook;

    /**
     * @var Book[]
     */
    #[Constraints\NotBlank]
    #[NestedObjects(Book::class)]
    private array $readedBooks;
}