Create service to generate a unique id. #638
This commit is contained in:
parent
ee07c9cc84
commit
d6cf2de4ab
1 changed files with 22 additions and 0 deletions
22
src/Service/UniqueIdGenerator.php
Normal file
22
src/Service/UniqueIdGenerator.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
|
class UniqueIdGenerator
|
||||||
|
{
|
||||||
|
protected $em;
|
||||||
|
|
||||||
|
public function __construct(EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
$this->em = $em;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generateUniqueId($str_length)
|
||||||
|
{
|
||||||
|
// TODO: retry until we get a unique id
|
||||||
|
|
||||||
|
return substr(md5(time()), 0, $str_length);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue