steevanb / symfony-validator-constraints
Add validator constraints
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 1 007
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^5.4 || ^7.0
- symfony/validator: ^2.3 || ^3.0
This package is auto-updated.
Last update: 2023-04-28 08:50:16 UTC
README
![symfony](https://img.shields.io/badge/symfony/validator-^2.3 || ^3.0-blue.svg) ![Lines](https://img.shields.io/badge/code lines-314-green.svg)
symfony-validator-constraints
Add constraints for symfony/validators.
UniqueObject
UniqueEntity assert new entity is not already in database.
But if you want to assert an object is unique in an array or \Traversable, without accessing database, you can use UniqueObject.
# Resources/config/validation/Bar.yml Foo\Bar: properties: baz: - steevanb\SymfonyValidatorConstraints\Constraints\UniqueObject: # uniq id to stop error validation when error found, # otherwise you will have an error by object in collection uniqid: bar_baz # properties and getters to generate an "objet identifier", # who has to be unique properties: [foo, bar] getters: [getFoo(), getBar()] groups: [add] message: translation.message
Example :
Foo\Bar: property: baz: - steevanb\SymfonyValidatorConstraints\Constraints\UniqueObject: uniqid: bar_baz properties: [foo] groups: [add]
$object1 = new Foo\Baz(); $object1->foo = 1; $object1->bar = 2; $object2 = new Foo\Baz(); $object2->foo = 1; $object2->bar = 2; $collection = new Foo\Bar(); $collection->add($object1); $collection->add($object2); // errors will contain 1 error, because $object1->foo and $object2->foo are identicals $errors = $validator->validate($collection, null, ['add']); // errors will not contain any error $object1->foo = 2; $errors = $validator->validate($collection, null, ['add']);