@@ -137,7 +137,7 @@ public function getDateTime(): \DateTimeImmutable
137
137
}
138
138
139
139
if (4 > \strlen ($ time )) {
140
- $ time = str_pad ( $ time , 4 , ' 0 ' , \ STR_PAD_LEFT ) ;
140
+ $ time = ' 000 ' . $ time ;
141
141
}
142
142
143
143
return \DateTimeImmutable::createFromFormat ('U.u ' , substr_replace ($ time , '. ' , -3 , 0 ));
@@ -149,7 +149,7 @@ public static function generate(\DateTimeInterface $time = null): string
149
149
return self ::doGenerate ();
150
150
}
151
151
152
- if (0 > $ time = substr ( $ time ->format ('Uu ' ), 0 , - 3 )) {
152
+ if (0 > $ time = $ time ->format ('Uv ' )) {
153
153
throw new \InvalidArgumentException ('The timestamp must be positive. ' );
154
154
}
155
155
@@ -163,7 +163,7 @@ private static function doGenerate(string $mtime = null): string
163
163
$ time = substr ($ time , 11 ).substr ($ time , 2 , 3 );
164
164
}
165
165
166
- if ($ time !== self ::$ time ) {
166
+ if ($ time > self :: $ time || ( null !== $ mtime && $ time !== self ::$ time) ) {
167
167
$ r = unpack ('nr1/nr2/nr3/nr4/nr ' , random_bytes (10 ));
168
168
$ r ['r1 ' ] |= ($ r ['r ' ] <<= 4 ) & 0xF0000 ;
169
169
$ r ['r2 ' ] |= ($ r ['r ' ] <<= 4 ) & 0xF0000 ;
@@ -186,6 +186,7 @@ private static function doGenerate(string $mtime = null): string
186
186
}
187
187
188
188
++self ::$ rand [$ i ];
189
+ $ time = self ::$ time ;
189
190
}
190
191
191
192
if (\PHP_INT_SIZE >= 8 ) {
0 commit comments