1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Created by PhpStorm. |
6
|
|
|
* User: benedikt |
7
|
|
|
* Date: 10/6/16 |
8
|
|
|
* Time: 11:18 AM |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Tfboe\FmLib\Entity\Helpers; |
12
|
|
|
|
13
|
|
|
use Doctrine\ORM\EntityManager; |
14
|
|
|
use Doctrine\ORM\Id\AbstractIdGenerator; |
15
|
|
|
use Doctrine\ORM\Mapping\Entity; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class IdGenerator. Generator for unique ids. |
19
|
|
|
* @package Tfboe\FmLib\Entity |
20
|
|
|
*/ |
21
|
|
|
class IdGenerator extends AbstractIdGenerator |
22
|
|
|
{ |
23
|
|
|
//<editor-fold desc="Public Methods"> |
24
|
|
|
/** |
25
|
|
|
* creates a new id |
26
|
|
|
* @param string $creatorFunction the id creator function name to use (if existent) |
27
|
|
|
* @return string the new id |
28
|
|
|
*/ |
29
|
|
|
public static function createIdFrom($creatorFunction = 'com_create_guid') |
30
|
|
|
{ |
31
|
|
|
if (function_exists($creatorFunction) === true) { |
32
|
|
|
return strtolower(trim($creatorFunction(), '{}')); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return strtolower(sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', |
36
|
|
|
mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), |
37
|
|
|
mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535))); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Generates an identifier for an entity. |
42
|
|
|
* |
43
|
|
|
* @param EntityManager $entityManager |
44
|
|
|
* @param Entity $entity |
45
|
|
|
* @return string |
46
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
47
|
|
|
*/ |
48
|
|
|
public function generate(EntityManager $entityManager, $entity): string |
49
|
|
|
{ |
50
|
|
|
return self::createIdFrom(); |
51
|
|
|
} |
52
|
|
|
//</editor-fold desc="Public Methods"> |
53
|
|
|
|
54
|
|
|
} |