Version 1
[yaffs-website] / vendor / symfony / validator / Constraints / IsFalseValidator.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Validator\Constraints;
13
14 use Symfony\Component\Validator\Context\ExecutionContextInterface;
15 use Symfony\Component\Validator\Constraint;
16 use Symfony\Component\Validator\ConstraintValidator;
17 use Symfony\Component\Validator\Exception\UnexpectedTypeException;
18
19 /**
20  * @author Bernhard Schussek <bschussek@gmail.com>
21  */
22 class IsFalseValidator extends ConstraintValidator
23 {
24     /**
25      * {@inheritdoc}
26      */
27     public function validate($value, Constraint $constraint)
28     {
29         if (!$constraint instanceof IsFalse) {
30             throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\IsFalse');
31         }
32
33         if (null === $value || false === $value || 0 === $value || '0' === $value) {
34             return;
35         }
36
37         if ($this->context instanceof ExecutionContextInterface) {
38             $this->context->buildViolation($constraint->message)
39                 ->setParameter('{{ value }}', $this->formatValue($value))
40                 ->setCode(IsFalse::NOT_FALSE_ERROR)
41                 ->addViolation();
42         } else {
43             $this->buildViolation($constraint->message)
44                 ->setParameter('{{ value }}', $this->formatValue($value))
45                 ->setCode(IsFalse::NOT_FALSE_ERROR)
46                 ->addViolation();
47         }
48     }
49 }