diff --git a/README.md b/README.md index 211a77e..d5833af 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ There may be occassions where you want the bridge between Symfony and Parsley en ); ``` -There is also the ``RemoveParsleyConstraint()`` class that can be used to remove specific Parsley constrains. This is handy if you want to remove something that was auto-generated from a Symfony Constraint. +There is also the ``RemoveParsleyDirective()`` class that can be used to remove specific Parsley constrains. This is handy if you want to remove something that was auto-generated from a Symfony Constraint. ## Rolling your own diff --git a/composer.json b/composer.json index d0b1a4d..f8e4bee 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "c0ntax/parsley-bundle", - "version": "0.6.0", + "version": "0.6.1", "type": "symfony-bundle", "description": "A bridge between Symfony and Parsley.js", "license": "Apache-2.0", diff --git a/src/Form/Extension/ParsleyTypeExtension.php b/src/Form/Extension/ParsleyTypeExtension.php index 3544ff2..a9cdf8c 100644 --- a/src/Form/Extension/ParsleyTypeExtension.php +++ b/src/Form/Extension/ParsleyTypeExtension.php @@ -8,8 +8,10 @@ use C0ntax\ParsleyBundle\Contracts\ParsleyInterface; use C0ntax\ParsleyBundle\Contracts\RemoveInterface; use C0ntax\ParsleyBundle\Factory\ConstraintFactory; +use C0ntax\ParsleyBundle\Parsleys\AbstractRemove; use C0ntax\ParsleyBundle\Parsleys\Directive\Field\Trigger; use C0ntax\ParsleyBundle\Parsleys\RemoveParsleyConstraint; +use C0ntax\ParsleyBundle\Parsleys\RemoveParsleyDirective; use C0ntax\ParsleyBundle\Parsleys\RemoveSymfonyConstraint; use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\Form\Extension\Core\Type\FormType; @@ -71,7 +73,7 @@ public function buildView(FormView $view, FormInterface $form, array $options): $this->createParsleyConstraintsFromValidationConstraints($symfonyConstraints, $form), $this->getDirectivesFromParsleys($parsleys) ), - $this->getRemoveParsleyConstraintsFromParsleys($parsleys) + $this->getRemoveParsleyDirectivesFromParsleys($parsleys) ); $this->addParsleyToView($view, $parsleyConstraints); @@ -121,15 +123,15 @@ function (ParsleyInterface $parsley) { /** * @param ParsleyInterface[] $parsleys - * @return RemoveParsleyConstraint[] + * @return AbstractRemove[] */ - private function getRemoveParsleyConstraintsFromParsleys(array $parsleys): array + private function getRemoveParsleyDirectivesFromParsleys(array $parsleys): array { return array_values( array_filter( $parsleys, function (ParsleyInterface $parsley) { - return $parsley instanceof RemoveParsleyConstraint; + return $parsley instanceof RemoveParsleyDirective || $parsley instanceof RemoveParsleyConstraint; } ) ); diff --git a/src/Parsleys/RemoveParsleyConstraint.php b/src/Parsleys/RemoveParsleyConstraint.php index 79ea8f0..8ede64c 100644 --- a/src/Parsleys/RemoveParsleyConstraint.php +++ b/src/Parsleys/RemoveParsleyConstraint.php @@ -11,6 +11,7 @@ * Used to remove Parsley Directives after they've been put in * * @package C0ntax\ParsleyBundle\Parsleys + * @deprecated Use RemoveParsleyDirective instead */ class RemoveParsleyConstraint extends AbstractRemove { diff --git a/src/Parsleys/RemoveParsleyDirective.php b/src/Parsleys/RemoveParsleyDirective.php new file mode 100644 index 0000000..f39d7f2 --- /dev/null +++ b/src/Parsleys/RemoveParsleyDirective.php @@ -0,0 +1,27 @@ +children['check']->vars['attr'] ); - } protected function getParsleyTypeConfig() diff --git a/tests/Parsleys/RemoveParsleyDirectiveTest.php b/tests/Parsleys/RemoveParsleyDirectiveTest.php new file mode 100644 index 0000000..984ead5 --- /dev/null +++ b/tests/Parsleys/RemoveParsleyDirectiveTest.php @@ -0,0 +1,90 @@ + ConstraintErrorMessage::class, + ], + [ + 'className' => Generic::class, + ], + [ + 'className' => Trigger::class, + ], + [ + 'className' => ParsleyConstraint\Email::class, + ], + [ + 'className' => ParsleyConstraint\Length::class, + ], + [ + 'className' => ParsleyConstraint\Max::class, + ], + [ + 'className' => ParsleyConstraint\MaxLength::class, + ], + [ + 'className' => ParsleyConstraint\Min::class, + ], + [ + 'className' => ParsleyConstraint\MinLength::class, + ], + [ + 'className' => ParsleyConstraint\Pattern::class, + ], + [ + 'className' => ParsleyConstraint\Range::class, + ], + [ + 'className' => ParsleyConstraint\Required::class, + ], + ]; + } + + public function getInvalidClassNames() + { + return [ + [ + 'className' => SymfonyConstraint\Email::class, + ], + [ + 'className' => SymfonyConstraint\Length::class, + ], + [ + 'className' => SymfonyConstraint\Regex::class, + ], + ]; + } +}