PHP code example of kasperh90 / symfony-extra-constraints

1. Go to this page and download the library: Download kasperh90/symfony-extra-constraints 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/ */

    

kasperh90 / symfony-extra-constraints example snippets


use Kasperh90\SymfonyExtraConstraints\Validator\Constraints as ExtraAssert;

class Allocation
{
    #[ExtraAssert\Sum(exactly: 100)]
    public array $percentages;

    #[ExtraAssert\Sum(min: 10)]
    public array $scores;

    #[ExtraAssert\Sum(max: 500)]
    public array $expenses;
}

class Ratings
{
    #[ExtraAssert\Average(min: 3.5)]
    public array $userRatings;

    #[ExtraAssert\Average(max: 5)]
    public array $scores;

    #[ExtraAssert\Average(exactly: 4)]
    public array $normalizedRatings;
}