PHP code example of jcaillot / mongoid-validator

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

    

jcaillot / mongoid-validator example snippets


use Symfony\Component\Validator\Constraints as Assert;
use Chaman\Validator\Constraints as CustomAssert;

class Demo
{

/**
 * @var string
 *
 * @Assert\NotBlank
 * @CustomAssert\MongoId
 */
private string $mongoId;




use Symfony\Component\Validator\Validation;
use Chaman\Validator\Constraints\MongoId;

...
$validator = Validation::createValidator();
$constraint = new MongoId();
$id = '612e33884726a713fd31009b';


$violations = $validator->validate($id, $constraint);
if (!count($violations)) {
    ...
}