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\Regex;
/**
* @author Warnar Boekkooi <[email protected]>
*/
class PatternRule implements ConstraintMapperInterface
{
const RULE_NAME = 'pattern';
* @var bool
private $enabled;
public function __construct($enabled)
$this->enabled = $enabled;
}
* {@inheritdoc}
public function resolve(Constraint $constraint, FormInterface $form, RuleCollection $collection)
if (!$this->supports($constraint, $form)) {
throw new LogicException();
/** @var \Symfony\Component\Validator\Constraints\Regex $constraint */
$collection->set(
self::RULE_NAME,
new ConstraintRule(
$constraint->getHtmlPattern(),
new RuleMessage($constraint->message),
$constraint->groups
)
);
public function supports(Constraint $constraint, FormInterface $form)
return $this->enabled && get_class($constraint) === Regex::class;