PHP code example of omasn / reflection-validator

1. Go to this page and download the library: Download omasn/reflection-validator 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/ */

    

omasn / reflection-validator example snippets


class A {
    public int $number;
    /** @var B[] */
    public array $rows;
}
class B {
    public int $number;
    /** @var C[] */
    public array $rows;
}
class C {
    #[Assert\Positive]
    public int $number;
}

$reflValidator = Omasn\ReflectionValidator\ReflectionValidator::createSimple();

$violations = $reflValidator->validate(A::class, [
    'number' => 0,
    'rows' => [
        [
            'number' => 0,
            'rows' => [
                [
                    'number' => -1,
                ],
            ],
        ],
    ],
]);

self::assertEquals(1, $violations->count());