16
16
*/
17
17
class SequenceGenerator extends AbstractIdGenerator implements Serializable
18
18
{
19
- /**
20
- * The allocation size of the sequence.
21
- *
22
- * @var int
23
- */
24
- private $ _allocationSize ;
25
-
26
- /**
27
- * The name of the sequence.
28
- *
29
- * @var string
30
- */
31
- private $ _sequenceName ;
32
-
33
- /** @var int */
34
- private $ _nextValue = 0 ;
35
-
36
- /** @var int|null */
37
- private $ _maxValue = null ;
19
+ private int $ nextValue = 0 ;
20
+ private ?int $ maxValue = null ;
38
21
39
22
/**
40
23
* Initializes a new sequence generator.
41
24
*
42
25
* @param string $sequenceName The name of the sequence.
43
26
* @param int $allocationSize The allocation size of the sequence.
44
27
*/
45
- public function __construct ($ sequenceName , $ allocationSize )
46
- {
47
- $ this -> _sequenceName = $ sequenceName ;
48
- $ this -> _allocationSize = $ allocationSize ;
28
+ public function __construct (
29
+ private string $ sequenceName ,
30
+ private int $ allocationSize
31
+ ) {
49
32
}
50
33
51
- /**
52
- * {@inheritDoc}
53
- */
54
- public function generateId (EntityManagerInterface $ em , $ entity )
34
+ public function generateId (EntityManagerInterface $ em , ?object $ entity ): int
55
35
{
56
- if ($ this ->_maxValue === null || $ this ->_nextValue === $ this ->_maxValue ) {
36
+ if ($ this ->maxValue === null || $ this ->nextValue === $ this ->maxValue ) {
57
37
// Allocate new values
58
38
$ connection = $ em ->getConnection ();
59
- $ sql = $ connection ->getDatabasePlatform ()->getSequenceNextValSQL ($ this ->_sequenceName );
39
+ $ sql = $ connection ->getDatabasePlatform ()->getSequenceNextValSQL ($ this ->sequenceName );
60
40
61
41
if ($ connection instanceof PrimaryReadReplicaConnection) {
62
42
$ connection ->ensureConnectedToPrimary ();
63
43
}
64
44
65
- $ this ->_nextValue = (int ) $ connection ->executeQuery ($ sql )->fetchOne ();
66
- $ this ->_maxValue = $ this ->_nextValue + $ this ->_allocationSize ;
45
+ $ this ->nextValue = (int ) $ connection ->executeQuery ($ sql )->fetchOne ();
46
+ $ this ->maxValue = $ this ->nextValue + $ this ->allocationSize ;
67
47
}
68
48
69
- return $ this ->_nextValue ++;
49
+ return $ this ->nextValue ++;
70
50
}
71
51
72
52
/**
73
53
* Gets the maximum value of the currently allocated bag of values.
74
- *
75
- * @return int|null
76
54
*/
77
- public function getCurrentMaxValue ()
55
+ public function getCurrentMaxValue (): ? int
78
56
{
79
- return $ this ->_maxValue ;
57
+ return $ this ->maxValue ;
80
58
}
81
59
82
60
/**
83
61
* Gets the next value that will be returned by generate().
84
- *
85
- * @return int
86
62
*/
87
- public function getNextValue ()
63
+ public function getNextValue (): int
88
64
{
89
- return $ this ->_nextValue ;
65
+ return $ this ->nextValue ;
90
66
}
91
67
92
- /**
93
- * @return string
94
- *
95
- * @final
96
- */
97
- public function serialize ()
68
+ final public function serialize (): string
98
69
{
99
70
return serialize ($ this ->__serialize ());
100
71
}
@@ -105,19 +76,12 @@ public function serialize()
105
76
public function __serialize (): array
106
77
{
107
78
return [
108
- 'allocationSize ' => $ this ->_allocationSize ,
109
- 'sequenceName ' => $ this ->_sequenceName ,
79
+ 'allocationSize ' => $ this ->allocationSize ,
80
+ 'sequenceName ' => $ this ->sequenceName ,
110
81
];
111
82
}
112
83
113
- /**
114
- * @param string $serialized
115
- *
116
- * @return void
117
- *
118
- * @final
119
- */
120
- public function unserialize ($ serialized )
84
+ final public function unserialize (string $ serialized ): void
121
85
{
122
86
$ this ->__unserialize (unserialize ($ serialized ));
123
87
}
@@ -127,7 +91,7 @@ public function unserialize($serialized)
127
91
*/
128
92
public function __unserialize (array $ data ): void
129
93
{
130
- $ this ->_sequenceName = $ data ['sequenceName ' ];
131
- $ this ->_allocationSize = $ data ['allocationSize ' ];
94
+ $ this ->sequenceName = $ data ['sequenceName ' ];
95
+ $ this ->allocationSize = $ data ['allocationSize ' ];
132
96
}
133
97
}
0 commit comments