Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Latest commit

 

History

History
81 lines (69 loc) · 1.26 KB

BlankConstraint.md

File metadata and controls

81 lines (69 loc) · 1.26 KB

BlankConstraint

<?php

use Chubbyphp\Validation\Constraint\BlankConstraint;
use Chubbyphp\Validation\ValidatorContextInterface;

$constraint = new BlankConstraint();

/** @var ValidatorContextInterface $context */
$context = ...;

// Use NotNullConstraint to prevent null
$errors = $constraint->validate(
    'path.to.property',
    null,
    $context
);
// [];

$errors = $constraint->validate(
    'path.to.property',
    '',
    $context
);
// [];

$errors = $constraint->validate(
    'path.to.property',
    [],
    $context
);
// [];

$errors = $constraint->validate(
    'path.to.property',
    new \stdClass,
    $context
);
// [];

$errors = $constraint->validate(
    'path.to.property',
    'value',
    $context
);
// [
//     new Error(
//         'path.to.property',
//         'constraint.blank.notblank'
//     )
// ];

$errors = $constraint->validate(
    'path.to.property',
    ['value'],
    $context
);
// [
//     new Error(
//         'path.to.property',
//         'constraint.blank.notblank'
//     )
// ];

$object = new \stdClass();
$object->key = 'value';

$errors = $constraint->validate(
    'path.to.property',
    $object,
    $context
);
// [
//     new Error(
//         'path.to.property',
//         'constraint.blank.notblank'
//     )
// ];