Using UniqueEntity outside of Symfony stack

304 views Asked by At

I have an app built on top of Silex and I'm using Doctrine as my ORM.

I have a problem where I'm trying to get a clean error for when a user tries to reuse an email, I found the validator UniqueEntity but it seems to be designed for the full stack version of Symfony.

My question is, is this true? I'm going a limb and assuming it as I haven't found anyone who successfully used it outside of Symfony.

My second question is, if I'm not able to use UniqueEntity, whats my next best option? I'm using the Symfony Validator component and would like to use something that's plugged into that to keep it all in the same block of code.

1

There are 1 answers

1
Anton Pelykh On BEST ANSWER

You can use UniqueEntity with Silex.

Here's the service provider package with the Doctrine ManagerRegistry implementation - saxulum/saxulum-doctrine-orm-manager-registry-provider. Also you can find the instructions how to use it with the UniqueEntity validator in README.

But you may want to implement you own UniqueEntity validator.

For example, if you want to validate DTO object (or any non-entity object), because it's not supported by Symfony's UniqueEntity validator (see issue on GitHub).