1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\ORM\Mapping; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\DBALException; |
8
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
9
|
|
|
use Doctrine\ORM\Sequencing; |
10
|
|
|
|
11
|
|
|
class ValueGeneratorMetadata |
12
|
|
|
{ |
13
|
|
|
/** @var Property */ |
14
|
|
|
protected $declaringProperty; |
15
|
|
|
|
16
|
|
|
/** @var string */ |
17
|
|
|
protected $type; |
18
|
|
|
|
19
|
|
|
/** @var mixed[] */ |
20
|
|
|
protected $definition; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param mixed[] $definition |
24
|
|
|
*/ |
25
|
318 |
|
public function __construct(string $type, array $definition = []) |
26
|
|
|
{ |
27
|
318 |
|
$this->type = $type; |
28
|
318 |
|
$this->definition = $definition; |
29
|
318 |
|
} |
30
|
|
|
|
31
|
|
|
public function getDeclaringProperty() : Property |
32
|
|
|
{ |
33
|
|
|
return $this->declaringProperty; |
34
|
|
|
} |
35
|
|
|
|
36
|
318 |
|
public function setDeclaringProperty(Property $declaringProperty) : void |
37
|
|
|
{ |
38
|
318 |
|
$this->declaringProperty = $declaringProperty; |
39
|
318 |
|
} |
40
|
|
|
|
41
|
1105 |
|
public function getType() : string |
42
|
|
|
{ |
43
|
1105 |
|
return $this->type; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return mixed[] |
48
|
|
|
*/ |
49
|
296 |
|
public function getDefinition() : array |
50
|
|
|
{ |
51
|
296 |
|
return $this->definition; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @throws DBALException |
56
|
|
|
*/ |
57
|
293 |
|
public function getSequencingGenerator(AbstractPlatform $platform) : Sequencing\Generator |
58
|
|
|
{ |
59
|
293 |
|
$class = $this->declaringProperty->getDeclaringClass(); |
60
|
|
|
|
61
|
293 |
|
switch ($this->type) { |
62
|
|
|
case GeneratorType::IDENTITY: |
63
|
286 |
|
$sequenceName = null; |
64
|
|
|
|
65
|
|
|
// Platforms that do not have native IDENTITY support need a sequence to emulate this behaviour. |
66
|
286 |
|
if ($platform->usesSequenceEmulatedIdentityColumns()) { |
67
|
|
|
$sequencePrefix = $platform->getSequencePrefix($class->getTableName(), $class->getSchemaName()); |
|
|
|
|
68
|
|
|
$idSequenceName = $platform->getIdentitySequenceName($sequencePrefix, $this->declaringProperty->getColumnName()); |
|
|
|
|
69
|
|
|
$sequenceName = $platform->quoteIdentifier($platform->fixSchemaElementName($idSequenceName)); |
70
|
|
|
} |
71
|
|
|
|
72
|
286 |
|
return $this->declaringProperty->getTypeName() === 'bigint' |
|
|
|
|
73
|
1 |
|
? new Sequencing\BigIntegerIdentityGenerator($sequenceName) |
|
|
|
|
74
|
286 |
|
: new Sequencing\IdentityGenerator($sequenceName); |
|
|
|
|
75
|
|
|
case GeneratorType::SEQUENCE: |
76
|
6 |
|
return new Sequencing\SequenceGenerator( |
77
|
6 |
|
$platform->quoteIdentifier($this->definition['sequenceName']), |
78
|
6 |
|
$this->definition['allocationSize'] |
79
|
|
|
); |
80
|
|
|
case GeneratorType::CUSTOM: |
81
|
1 |
|
$class = $this->definition['class']; |
82
|
|
|
|
83
|
1 |
|
return new $class(); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|