← All changes
|
includes/sdk/google/ramsey/uuid/src/FeatureSet.php
+108
-151
1.2.7
→
1.4.1
View file →
| @@ -9,152 +9,95 @@ | ||
| 9 | 9 | * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> |
| 10 | 10 | * @license http://opensource.org/licenses/MIT MIT |
| 11 | 11 | */ |
| 12 | 12 | declare (strict_types=1); |
| 13 | -namespace Dudlewebs\WPMCS\Ramsey\Uuid; | |
| 13 | +namespace Dudlewebs\WPMCS\GCP\Ramsey\Uuid; | |
| 14 | 14 | |
| 15 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Builder\BuilderCollection; | |
| 16 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Builder\FallbackBuilder; | |
| 17 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Builder\UuidBuilderInterface; | |
| 18 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Codec\CodecInterface; | |
| 19 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Codec\GuidStringCodec; | |
| 20 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Codec\StringCodec; | |
| 21 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Converter\Number\GenericNumberConverter; | |
| 22 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Converter\NumberConverterInterface; | |
| 23 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Converter\Time\GenericTimeConverter; | |
| 24 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Converter\Time\PhpTimeConverter; | |
| 25 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Converter\TimeConverterInterface; | |
| 26 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Generator\DceSecurityGenerator; | |
| 27 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Generator\DceSecurityGeneratorInterface; | |
| 28 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Generator\NameGeneratorFactory; | |
| 29 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Generator\NameGeneratorInterface; | |
| 30 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Generator\PeclUuidNameGenerator; | |
| 31 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Generator\PeclUuidRandomGenerator; | |
| 32 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Generator\PeclUuidTimeGenerator; | |
| 33 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Generator\RandomGeneratorFactory; | |
| 34 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Generator\RandomGeneratorInterface; | |
| 35 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Generator\TimeGeneratorFactory; | |
| 36 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Generator\TimeGeneratorInterface; | |
| 37 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Guid\GuidBuilder; | |
| 38 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Math\BrickMathCalculator; | |
| 39 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Math\CalculatorInterface; | |
| 40 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Nonstandard\UuidBuilder as NonstandardUuidBuilder; | |
| 41 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Provider\Dce\SystemDceSecurityProvider; | |
| 42 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Provider\DceSecurityProviderInterface; | |
| 43 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Provider\Node\FallbackNodeProvider; | |
| 44 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Provider\Node\NodeProviderCollection; | |
| 45 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Provider\Node\RandomNodeProvider; | |
| 46 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Provider\Node\SystemNodeProvider; | |
| 47 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Provider\NodeProviderInterface; | |
| 48 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Provider\Time\SystemTimeProvider; | |
| 49 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Provider\TimeProviderInterface; | |
| 50 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Rfc4122\UuidBuilder as Rfc4122UuidBuilder; | |
| 51 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Validator\GenericValidator; | |
| 52 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Validator\ValidatorInterface; | |
| 15 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Builder\FallbackBuilder; | |
| 16 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Builder\UuidBuilderInterface; | |
| 17 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Codec\CodecInterface; | |
| 18 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Codec\GuidStringCodec; | |
| 19 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Codec\StringCodec; | |
| 20 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Converter\Number\GenericNumberConverter; | |
| 21 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Converter\NumberConverterInterface; | |
| 22 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Converter\Time\GenericTimeConverter; | |
| 23 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Converter\Time\PhpTimeConverter; | |
| 24 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Converter\TimeConverterInterface; | |
| 25 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Generator\DceSecurityGenerator; | |
| 26 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Generator\DceSecurityGeneratorInterface; | |
| 27 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Generator\NameGeneratorFactory; | |
| 28 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Generator\NameGeneratorInterface; | |
| 29 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Generator\PeclUuidNameGenerator; | |
| 30 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Generator\PeclUuidRandomGenerator; | |
| 31 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Generator\PeclUuidTimeGenerator; | |
| 32 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Generator\RandomGeneratorFactory; | |
| 33 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Generator\RandomGeneratorInterface; | |
| 34 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Generator\TimeGeneratorFactory; | |
| 35 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Generator\TimeGeneratorInterface; | |
| 36 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Generator\UnixTimeGenerator; | |
| 37 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Guid\GuidBuilder; | |
| 38 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Math\BrickMathCalculator; | |
| 39 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Math\CalculatorInterface; | |
| 40 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Nonstandard\UuidBuilder as NonstandardUuidBuilder; | |
| 41 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Provider\Dce\SystemDceSecurityProvider; | |
| 42 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Provider\DceSecurityProviderInterface; | |
| 43 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Provider\Node\FallbackNodeProvider; | |
| 44 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Provider\Node\RandomNodeProvider; | |
| 45 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Provider\Node\SystemNodeProvider; | |
| 46 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Provider\NodeProviderInterface; | |
| 47 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Provider\Time\SystemTimeProvider; | |
| 48 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Provider\TimeProviderInterface; | |
| 49 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Rfc4122\UuidBuilder as Rfc4122UuidBuilder; | |
| 50 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Validator\GenericValidator; | |
| 51 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Validator\ValidatorInterface; | |
| 53 | 52 | use const PHP_INT_SIZE; |
| 54 | 53 | /** |
| 55 | 54 | * FeatureSet detects and exposes available features in the current environment |
| 56 | 55 | * |
| 57 | - * A feature set is used by UuidFactory to determine the available features and | |
| 58 | - * capabilities of the environment. | |
| 56 | + * A feature set is used by UuidFactory to determine the available features and capabilities of the environment. | |
| 59 | 57 | */ |
| 60 | 58 | class FeatureSet |
| 61 | 59 | { |
| 60 | + private ?TimeProviderInterface $timeProvider = null; | |
| 61 | + private CalculatorInterface $calculator; | |
| 62 | + private CodecInterface $codec; | |
| 63 | + private DceSecurityGeneratorInterface $dceSecurityGenerator; | |
| 64 | + private NameGeneratorInterface $nameGenerator; | |
| 65 | + private NodeProviderInterface $nodeProvider; | |
| 66 | + private NumberConverterInterface $numberConverter; | |
| 67 | + private RandomGeneratorInterface $randomGenerator; | |
| 68 | + private TimeConverterInterface $timeConverter; | |
| 69 | + private TimeGeneratorInterface $timeGenerator; | |
| 70 | + private TimeGeneratorInterface $unixTimeGenerator; | |
| 71 | + private UuidBuilderInterface $builder; | |
| 72 | + private ValidatorInterface $validator; | |
| 62 | 73 | /** |
| 63 | - * @var bool | |
| 64 | - */ | |
| 65 | - private $disableBigNumber = \false; | |
| 66 | - /** | |
| 67 | - * @var bool | |
| 68 | - */ | |
| 69 | - private $disable64Bit = \false; | |
| 70 | - /** | |
| 71 | - * @var bool | |
| 72 | - */ | |
| 73 | - private $ignoreSystemNode = \false; | |
| 74 | - /** | |
| 75 | - * @var bool | |
| 76 | - */ | |
| 77 | - private $enablePecl = \false; | |
| 78 | - /** | |
| 79 | - * @var UuidBuilderInterface | |
| 80 | - */ | |
| 81 | - private $builder; | |
| 82 | - /** | |
| 83 | - * @var CodecInterface | |
| 84 | - */ | |
| 85 | - private $codec; | |
| 86 | - /** | |
| 87 | - * @var DceSecurityGeneratorInterface | |
| 88 | - */ | |
| 89 | - private $dceSecurityGenerator; | |
| 90 | - /** | |
| 91 | - * @var NameGeneratorInterface | |
| 92 | - */ | |
| 93 | - private $nameGenerator; | |
| 94 | - /** | |
| 95 | - * @var NodeProviderInterface | |
| 96 | - */ | |
| 97 | - private $nodeProvider; | |
| 98 | - /** | |
| 99 | - * @var NumberConverterInterface | |
| 100 | - */ | |
| 101 | - private $numberConverter; | |
| 102 | - /** | |
| 103 | - * @var TimeConverterInterface | |
| 104 | - */ | |
| 105 | - private $timeConverter; | |
| 106 | - /** | |
| 107 | - * @var RandomGeneratorInterface | |
| 108 | - */ | |
| 109 | - private $randomGenerator; | |
| 110 | - /** | |
| 111 | - * @var TimeGeneratorInterface | |
| 112 | - */ | |
| 113 | - private $timeGenerator; | |
| 114 | - /** | |
| 115 | - * @var TimeProviderInterface | |
| 116 | - */ | |
| 117 | - private $timeProvider; | |
| 118 | - /** | |
| 119 | - * @var ValidatorInterface | |
| 120 | - */ | |
| 121 | - private $validator; | |
| 122 | - /** | |
| 123 | - * @var CalculatorInterface | |
| 124 | - */ | |
| 125 | - private $calculator; | |
| 126 | - /** | |
| 127 | 74 | * @param bool $useGuids True build UUIDs using the GuidStringCodec |
| 128 | - * @param bool $force32Bit True to force the use of 32-bit functionality | |
| 129 | - * (primarily for testing purposes) | |
| 130 | - * @param bool $forceNoBigNumber True to disable the use of moontoast/math | |
| 131 | - * (primarily for testing purposes) | |
| 132 | - * @param bool $ignoreSystemNode True to disable attempts to check for the | |
| 133 | - * system node ID (primarily for testing purposes) | |
| 134 | - * @param bool $enablePecl True to enable the use of the PeclUuidTimeGenerator | |
| 135 | - * to generate version 1 UUIDs | |
| 75 | + * @param bool $force32Bit True to force the use of 32-bit functionality (primarily for testing purposes) | |
| 76 | + * @param bool $forceNoBigNumber (obsolete) | |
| 77 | + * @param bool $ignoreSystemNode True to disable attempts to check for the system node ID (primarily for testing purposes) | |
| 78 | + * @param bool $enablePecl True to enable the use of the PeclUuidTimeGenerator to generate version 1 UUIDs | |
| 79 | + * | |
| 80 | + * @phpstan-ignore constructor.unusedParameter ($forceNoBigNumber is deprecated) | |
| 136 | 81 | */ |
| 137 | - public function __construct(bool $useGuids = \false, bool $force32Bit = \false, bool $forceNoBigNumber = \false, bool $ignoreSystemNode = \false, bool $enablePecl = \false) | |
| 82 | + public function __construct(bool $useGuids = \false, private bool $force32Bit = \false, bool $forceNoBigNumber = \false, private bool $ignoreSystemNode = \false, private bool $enablePecl = \false) | |
| 138 | 83 | { |
| 139 | - $this->disableBigNumber = $forceNoBigNumber; | |
| 140 | - $this->disable64Bit = $force32Bit; | |
| 141 | - $this->ignoreSystemNode = $ignoreSystemNode; | |
| 142 | - $this->enablePecl = $enablePecl; | |
| 84 | + $this->randomGenerator = $this->buildRandomGenerator(); | |
| 143 | 85 | $this->setCalculator(new BrickMathCalculator()); |
| 144 | 86 | $this->builder = $this->buildUuidBuilder($useGuids); |
| 145 | 87 | $this->codec = $this->buildCodec($useGuids); |
| 146 | 88 | $this->nodeProvider = $this->buildNodeProvider(); |
| 147 | 89 | $this->nameGenerator = $this->buildNameGenerator(); |
| 148 | - $this->randomGenerator = $this->buildRandomGenerator(); | |
| 149 | 90 | $this->setTimeProvider(new SystemTimeProvider()); |
| 150 | 91 | $this->setDceSecurityProvider(new SystemDceSecurityProvider()); |
| 151 | 92 | $this->validator = new GenericValidator(); |
| 93 | + \assert($this->timeProvider !== null); | |
| 94 | + $this->unixTimeGenerator = $this->buildUnixTimeGenerator(); | |
| 152 | 95 | } |
| 153 | 96 | /** |
| 154 | 97 | * Returns the builder configured for this environment |
| 155 | 98 | */ |
| 156 | - public function getBuilder(): UuidBuilderInterface | |
| 99 | + public function getBuilder() : UuidBuilderInterface | |
| 157 | 100 | { |
| 158 | 101 | return $this->builder; |
| 159 | 102 | } |
| 160 | 103 | /** |
| @@ -159,9 +102,9 @@ | ||
| 159 | 102 | } |
| 160 | 103 | /** |
| 161 | 104 | * Returns the calculator configured for this environment |
| 162 | 105 | */ |
| 163 | - public function getCalculator(): CalculatorInterface | |
| 106 | + public function getCalculator() : CalculatorInterface | |
| 164 | 107 | { |
| 165 | 108 | return $this->calculator; |
| 166 | 109 | } |
| 167 | 110 | /** |
| @@ -166,9 +109,9 @@ | ||
| 166 | 109 | } |
| 167 | 110 | /** |
| 168 | 111 | * Returns the codec configured for this environment |
| 169 | 112 | */ |
| 170 | - public function getCodec(): CodecInterface | |
| 113 | + public function getCodec() : CodecInterface | |
| 171 | 114 | { |
| 172 | 115 | return $this->codec; |
| 173 | 116 | } |
| 174 | 117 | /** |
| @@ -173,9 +116,9 @@ | ||
| 173 | 116 | } |
| 174 | 117 | /** |
| 175 | 118 | * Returns the DCE Security generator configured for this environment |
| 176 | 119 | */ |
| 177 | - public function getDceSecurityGenerator(): DceSecurityGeneratorInterface | |
| 120 | + public function getDceSecurityGenerator() : DceSecurityGeneratorInterface | |
| 178 | 121 | { |
| 179 | 122 | return $this->dceSecurityGenerator; |
| 180 | 123 | } |
| 181 | 124 | /** |
| @@ -180,9 +123,9 @@ | ||
| 180 | 123 | } |
| 181 | 124 | /** |
| 182 | 125 | * Returns the name generator configured for this environment |
| 183 | 126 | */ |
| 184 | - public function getNameGenerator(): NameGeneratorInterface | |
| 127 | + public function getNameGenerator() : NameGeneratorInterface | |
| 185 | 128 | { |
| 186 | 129 | return $this->nameGenerator; |
| 187 | 130 | } |
| 188 | 131 | /** |
| @@ -187,9 +130,9 @@ | ||
| 187 | 130 | } |
| 188 | 131 | /** |
| 189 | 132 | * Returns the node provider configured for this environment |
| 190 | 133 | */ |
| 191 | - public function getNodeProvider(): NodeProviderInterface | |
| 134 | + public function getNodeProvider() : NodeProviderInterface | |
| 192 | 135 | { |
| 193 | 136 | return $this->nodeProvider; |
| 194 | 137 | } |
| 195 | 138 | /** |
| @@ -194,9 +137,9 @@ | ||
| 194 | 137 | } |
| 195 | 138 | /** |
| 196 | 139 | * Returns the number converter configured for this environment |
| 197 | 140 | */ |
| 198 | - public function getNumberConverter(): NumberConverterInterface | |
| 141 | + public function getNumberConverter() : NumberConverterInterface | |
| 199 | 142 | { |
| 200 | 143 | return $this->numberConverter; |
| 201 | 144 | } |
| 202 | 145 | /** |
| @@ -201,9 +144,9 @@ | ||
| 201 | 144 | } |
| 202 | 145 | /** |
| 203 | 146 | * Returns the random generator configured for this environment |
| 204 | 147 | */ |
| 205 | - public function getRandomGenerator(): RandomGeneratorInterface | |
| 148 | + public function getRandomGenerator() : RandomGeneratorInterface | |
| 206 | 149 | { |
| 207 | 150 | return $this->randomGenerator; |
| 208 | 151 | } |
| 209 | 152 | /** |
| @@ -208,9 +151,9 @@ | ||
| 208 | 151 | } |
| 209 | 152 | /** |
| 210 | 153 | * Returns the time converter configured for this environment |
| 211 | 154 | */ |
| 212 | - public function getTimeConverter(): TimeConverterInterface | |
| 155 | + public function getTimeConverter() : TimeConverterInterface | |
| 213 | 156 | { |
| 214 | 157 | return $this->timeConverter; |
| 215 | 158 | } |
| 216 | 159 | /** |
| @@ -215,16 +158,23 @@ | ||
| 215 | 158 | } |
| 216 | 159 | /** |
| 217 | 160 | * Returns the time generator configured for this environment |
| 218 | 161 | */ |
| 219 | - public function getTimeGenerator(): TimeGeneratorInterface | |
| 162 | + public function getTimeGenerator() : TimeGeneratorInterface | |
| 220 | 163 | { |
| 221 | 164 | return $this->timeGenerator; |
| 222 | 165 | } |
| 223 | 166 | /** |
| 167 | + * Returns the Unix Epoch time generator configured for this environment | |
| 168 | + */ | |
| 169 | + public function getUnixTimeGenerator() : TimeGeneratorInterface | |
| 170 | + { | |
| 171 | + return $this->unixTimeGenerator; | |
| 172 | + } | |
| 173 | + /** | |
| 224 | 174 | * Returns the validator configured for this environment |
| 225 | 175 | */ |
| 226 | - public function getValidator(): ValidatorInterface | |
| 176 | + public function getValidator() : ValidatorInterface | |
| 227 | 177 | { |
| 228 | 178 | return $this->validator; |
| 229 | 179 | } |
| 230 | 180 | /** |
| @@ -229,14 +179,13 @@ | ||
| 229 | 179 | } |
| 230 | 180 | /** |
| 231 | 181 | * Sets the calculator to use in this environment |
| 232 | 182 | */ |
| 233 | - public function setCalculator(CalculatorInterface $calculator): void | |
| 183 | + public function setCalculator(CalculatorInterface $calculator) : void | |
| 234 | 184 | { |
| 235 | 185 | $this->calculator = $calculator; |
| 236 | 186 | $this->numberConverter = $this->buildNumberConverter($calculator); |
| 237 | 187 | $this->timeConverter = $this->buildTimeConverter($calculator); |
| 238 | - /** @psalm-suppress RedundantPropertyInitializationCheck */ | |
| 239 | 188 | if (isset($this->timeProvider)) { |
| 240 | 189 | $this->timeGenerator = $this->buildTimeGenerator($this->timeProvider); |
| 241 | 190 | } |
| 242 | 191 | } |
| @@ -242,9 +191,9 @@ | ||
| 242 | 191 | } |
| 243 | 192 | /** |
| 244 | 193 | * Sets the DCE Security provider to use in this environment |
| 245 | 194 | */ |
| 246 | - public function setDceSecurityProvider(DceSecurityProviderInterface $dceSecurityProvider): void | |
| 195 | + public function setDceSecurityProvider(DceSecurityProviderInterface $dceSecurityProvider) : void | |
| 247 | 196 | { |
| 248 | 197 | $this->dceSecurityGenerator = $this->buildDceSecurityGenerator($dceSecurityProvider); |
| 249 | 198 | } |
| 250 | 199 | /** |
| @@ -249,17 +198,19 @@ | ||
| 249 | 198 | } |
| 250 | 199 | /** |
| 251 | 200 | * Sets the node provider to use in this environment |
| 252 | 201 | */ |
| 253 | - public function setNodeProvider(NodeProviderInterface $nodeProvider): void | |
| 202 | + public function setNodeProvider(NodeProviderInterface $nodeProvider) : void | |
| 254 | 203 | { |
| 255 | 204 | $this->nodeProvider = $nodeProvider; |
| 256 | - $this->timeGenerator = $this->buildTimeGenerator($this->timeProvider); | |
| 205 | + if (isset($this->timeProvider)) { | |
| 206 | + $this->timeGenerator = $this->buildTimeGenerator($this->timeProvider); | |
| 207 | + } | |
| 257 | 208 | } |
| 258 | 209 | /** |
| 259 | 210 | * Sets the time provider to use in this environment |
| 260 | 211 | */ |
| 261 | - public function setTimeProvider(TimeProviderInterface $timeProvider): void | |
| 212 | + public function setTimeProvider(TimeProviderInterface $timeProvider) : void | |
| 262 | 213 | { |
| 263 | 214 | $this->timeProvider = $timeProvider; |
| 264 | 215 | $this->timeGenerator = $this->buildTimeGenerator($timeProvider); |
| 265 | 216 | } |
| @@ -265,9 +216,9 @@ | ||
| 265 | 216 | } |
| 266 | 217 | /** |
| 267 | 218 | * Set the validator to use in this environment |
| 268 | 219 | */ |
| 269 | - public function setValidator(ValidatorInterface $validator): void | |
| 220 | + public function setValidator(ValidatorInterface $validator) : void | |
| 270 | 221 | { |
| 271 | 222 | $this->validator = $validator; |
| 272 | 223 | } |
| 273 | 224 | /** |
| @@ -274,9 +225,9 @@ | ||
| 274 | 225 | * Returns a codec configured for this environment |
| 275 | 226 | * |
| 276 | 227 | * @param bool $useGuids Whether to build UUIDs using the GuidStringCodec |
| 277 | 228 | */ |
| 278 | - private function buildCodec(bool $useGuids = \false): CodecInterface | |
| 229 | + private function buildCodec(bool $useGuids = \false) : CodecInterface | |
| 279 | 230 | { |
| 280 | 231 | if ($useGuids) { |
| 281 | 232 | return new GuidStringCodec($this->builder); |
| 282 | 233 | } |
| @@ -284,9 +235,9 @@ | ||
| 284 | 235 | } |
| 285 | 236 | /** |
| 286 | 237 | * Returns a DCE Security generator configured for this environment |
| 287 | 238 | */ |
| 288 | - private function buildDceSecurityGenerator(DceSecurityProviderInterface $dceSecurityProvider): DceSecurityGeneratorInterface | |
| 239 | + private function buildDceSecurityGenerator(DceSecurityProviderInterface $dceSecurityProvider) : DceSecurityGeneratorInterface | |
| 289 | 240 | { |
| 290 | 241 | return new DceSecurityGenerator($this->numberConverter, $this->timeGenerator, $dceSecurityProvider); |
| 291 | 242 | } |
| 292 | 243 | /** |
| @@ -291,19 +242,19 @@ | ||
| 291 | 242 | } |
| 292 | 243 | /** |
| 293 | 244 | * Returns a node provider configured for this environment |
| 294 | 245 | */ |
| 295 | - private function buildNodeProvider(): NodeProviderInterface | |
| 246 | + private function buildNodeProvider() : NodeProviderInterface | |
| 296 | 247 | { |
| 297 | 248 | if ($this->ignoreSystemNode) { |
| 298 | 249 | return new RandomNodeProvider(); |
| 299 | 250 | } |
| 300 | - return new FallbackNodeProvider(new NodeProviderCollection([new SystemNodeProvider(), new RandomNodeProvider()])); | |
| 251 | + return new FallbackNodeProvider([new SystemNodeProvider(), new RandomNodeProvider()]); | |
| 301 | 252 | } |
| 302 | 253 | /** |
| 303 | 254 | * Returns a number converter configured for this environment |
| 304 | 255 | */ |
| 305 | - private function buildNumberConverter(CalculatorInterface $calculator): NumberConverterInterface | |
| 256 | + private function buildNumberConverter(CalculatorInterface $calculator) : NumberConverterInterface | |
| 306 | 257 | { |
| 307 | 258 | return new GenericNumberConverter($calculator); |
| 308 | 259 | } |
| 309 | 260 | /** |
| @@ -308,9 +259,9 @@ | ||
| 308 | 259 | } |
| 309 | 260 | /** |
| 310 | 261 | * Returns a random generator configured for this environment |
| 311 | 262 | */ |
| 312 | - private function buildRandomGenerator(): RandomGeneratorInterface | |
| 263 | + private function buildRandomGenerator() : RandomGeneratorInterface | |
| 313 | 264 | { |
| 314 | 265 | if ($this->enablePecl) { |
| 315 | 266 | return new PeclUuidRandomGenerator(); |
| 316 | 267 | } |
| @@ -321,9 +272,9 @@ | ||
| 321 | 272 | * |
| 322 | 273 | * @param TimeProviderInterface $timeProvider The time provider to use with |
| 323 | 274 | * the time generator |
| 324 | 275 | */ |
| 325 | - private function buildTimeGenerator(TimeProviderInterface $timeProvider): TimeGeneratorInterface | |
| 276 | + private function buildTimeGenerator(TimeProviderInterface $timeProvider) : TimeGeneratorInterface | |
| 326 | 277 | { |
| 327 | 278 | if ($this->enablePecl) { |
| 328 | 279 | return new PeclUuidTimeGenerator(); |
| 329 | 280 | } |
| @@ -329,11 +280,18 @@ | ||
| 329 | 280 | } |
| 330 | 281 | return (new TimeGeneratorFactory($this->nodeProvider, $this->timeConverter, $timeProvider))->getGenerator(); |
| 331 | 282 | } |
| 332 | 283 | /** |
| 284 | + * Returns a Unix Epoch time generator configured for this environment | |
| 285 | + */ | |
| 286 | + private function buildUnixTimeGenerator() : TimeGeneratorInterface | |
| 287 | + { | |
| 288 | + return new UnixTimeGenerator($this->randomGenerator); | |
| 289 | + } | |
| 290 | + /** | |
| 333 | 291 | * Returns a name generator configured for this environment |
| 334 | 292 | */ |
| 335 | - private function buildNameGenerator(): NameGeneratorInterface | |
| 293 | + private function buildNameGenerator() : NameGeneratorInterface | |
| 336 | 294 | { |
| 337 | 295 | if ($this->enablePecl) { |
| 338 | 296 | return new PeclUuidNameGenerator(); |
| 339 | 297 | } |
| @@ -341,9 +299,9 @@ | ||
| 341 | 299 | } |
| 342 | 300 | /** |
| 343 | 301 | * Returns a time converter configured for this environment |
| 344 | 302 | */ |
| 345 | - private function buildTimeConverter(CalculatorInterface $calculator): TimeConverterInterface | |
| 303 | + private function buildTimeConverter(CalculatorInterface $calculator) : TimeConverterInterface | |
| 346 | 304 | { |
| 347 | 305 | $genericConverter = new GenericTimeConverter($calculator); |
| 348 | 306 | if ($this->is64BitSystem()) { |
| 349 | 307 | return new PhpTimeConverter($calculator, $genericConverter); |
| @@ -354,20 +312,19 @@ | ||
| 354 | 312 | * Returns a UUID builder configured for this environment |
| 355 | 313 | * |
| 356 | 314 | * @param bool $useGuids Whether to build UUIDs using the GuidStringCodec |
| 357 | 315 | */ |
| 358 | - private function buildUuidBuilder(bool $useGuids = \false): UuidBuilderInterface | |
| 316 | + private function buildUuidBuilder(bool $useGuids = \false) : UuidBuilderInterface | |
| 359 | 317 | { |
| 360 | 318 | if ($useGuids) { |
| 361 | 319 | return new GuidBuilder($this->numberConverter, $this->timeConverter); |
| 362 | 320 | } |
| 363 | - /** @psalm-suppress ImpureArgument */ | |
| 364 | - return new FallbackBuilder(new BuilderCollection([new Rfc4122UuidBuilder($this->numberConverter, $this->timeConverter), new NonstandardUuidBuilder($this->numberConverter, $this->timeConverter)])); | |
| 321 | + return new FallbackBuilder([new Rfc4122UuidBuilder($this->numberConverter, $this->timeConverter), new NonstandardUuidBuilder($this->numberConverter, $this->timeConverter)]); | |
| 365 | 322 | } |
| 366 | 323 | /** |
| 367 | 324 | * Returns true if the PHP build is 64-bit |
| 368 | 325 | */ |
| 369 | - private function is64BitSystem(): bool | |
| 326 | + private function is64BitSystem() : bool | |
| 370 | 327 | { |
| 371 | - return PHP_INT_SIZE === 8 && !$this->disable64Bit; | |
| 328 | + return PHP_INT_SIZE === 8 && !$this->force32Bit; | |
| 372 | 329 | } |
| 373 | 330 | } |