for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Boekkooi\Bundle\JqueryValidationBundle\Form\Rule\Mapping;
use Boekkooi\Bundle\JqueryValidationBundle\Exception\LogicException;
use Boekkooi\Bundle\JqueryValidationBundle\Form\Rule\ConstraintRule;
use Boekkooi\Bundle\JqueryValidationBundle\Form\Rule\ConstraintMapperInterface;
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleCollection;
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleMessage;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\NotNull;
/**
* @author Warnar Boekkooi <[email protected]>
*/
class RequiredRule implements ConstraintMapperInterface
{
const RULE_NAME = 'required';
* {@inheritdoc}
public function resolve(Constraint $constraint, FormInterface $form, RuleCollection $collection)
if (!$this->supports($constraint, $form)) {
throw new LogicException();
}
/** @var \Symfony\Component\Validator\Constraints\NotBlank | \Symfony\Component\Validator\Constraints\NotNull $constraint */
$collection->set(
self::RULE_NAME,
new ConstraintRule(
true,
new RuleMessage($constraint->message),
$constraint->groups
)
);
public function supports(Constraint $constraint, FormInterface $form)
return in_array(
get_class($constraint),
array(
NotBlank::class,
NotNull::class,
),
true