I'd like to create unique IDs, something like dujUSJue9389sjgjik
.
I've used the Doctrine's UUID
strategy to create them, but the result is something like d9c363ae-a1b7-11e6-a66d-9e9923e30d94
: I don't like the use of dashes and also I'd like to have shorter IDs.
They have to identify some entities to build an URL like http://example.com/entity/hduicw43tv43bic
.
Using PHP's uniqid()
doesn't guarantee the uniqueness of the generated value. I think a conflict is very rare, but, anyway, not excluded at all, so I'm not considering it "secure" (a conflict may cause an exception and the rows creation may cause a lot of headache to fix).
So, using Doctrine and Symfony, I'm looking for a way to generate a value like ajybUYBD74883bj8d74NJ
and check for its uniqueness. If it is already present, a new value has to be generated. Once the entity has a unique value, it can be persisted. The generation should happen when the entity is created.
Any ideas on how to implement this?