← All changes
|
includes/sdk/google/ramsey/uuid/src/Provider/Node/StaticNodeProvider.php
+9
-12
1.2.13
→
1.4.2
View file →
| @@ -9,13 +9,13 @@ | ||
| 9 | 9 | * @copyright Copyright (c) Ben Ramsey <[email protected]> |
| 10 | 10 | * @license http://opensource.org/licenses/MIT MIT |
| 11 | 11 | */ |
| 12 | 12 | declare (strict_types=1); |
| 13 | -namespace Dudlewebs\WPMCS\Ramsey\Uuid\Provider\Node; | |
| 13 | +namespace Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Provider\Node; | |
| 14 | 14 | |
| 15 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Exception\InvalidArgumentException; | |
| 16 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Provider\NodeProviderInterface; | |
| 17 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Type\Hexadecimal; | |
| 15 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Exception\InvalidArgumentException; | |
| 16 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Provider\NodeProviderInterface; | |
| 17 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Type\Hexadecimal; | |
| 18 | 18 | use function dechex; |
| 19 | 19 | use function hexdec; |
| 20 | 20 | use function str_pad; |
| 21 | 21 | use function substr; |
| @@ -22,27 +22,24 @@ | ||
| 22 | 22 | use const STR_PAD_LEFT; |
| 23 | 23 | /** |
| 24 | 24 | * StaticNodeProvider provides a static node value with the multicast bit set |
| 25 | 25 | * |
| 26 | - * @link http://tools.ietf.org/html/rfc4122#section-4.5 RFC 4122, ยง 4.5: Node IDs that Do Not Identify the Host | |
| 26 | + * @link https://www.rfc-editor.org/rfc/rfc9562#section-6.10 RFC 9562, 6.10. UUIDs That Do Not Identify the Host | |
| 27 | 27 | */ |
| 28 | 28 | class StaticNodeProvider implements NodeProviderInterface |
| 29 | 29 | { |
| 30 | + private Hexadecimal $node; | |
| 30 | 31 | /** |
| 31 | - * @var Hexadecimal | |
| 32 | - */ | |
| 33 | - private $node; | |
| 34 | - /** | |
| 35 | 32 | * @param Hexadecimal $node The static node value to use |
| 36 | 33 | */ |
| 37 | 34 | public function __construct(Hexadecimal $node) |
| 38 | 35 | { |
| 39 | - if (strlen($node->toString()) > 12) { | |
| 36 | + if (\strlen($node->toString()) > 12) { | |
| 40 | 37 | throw new InvalidArgumentException('Static node value cannot be greater than 12 hexadecimal characters'); |
| 41 | 38 | } |
| 42 | 39 | $this->node = $this->setMulticastBit($node); |
| 43 | 40 | } |
| 44 | - public function getNode(): Hexadecimal | |
| 41 | + public function getNode() : Hexadecimal | |
| 45 | 42 | { |
| 46 | 43 | return $this->node; |
| 47 | 44 | } |
| 48 | 45 | /** |
| @@ -47,9 +44,9 @@ | ||
| 47 | 44 | } |
| 48 | 45 | /** |
| 49 | 46 | * Set the multicast bit for the static node value |
| 50 | 47 | */ |
| 51 | - private function setMulticastBit(Hexadecimal $node): Hexadecimal | |
| 48 | + private function setMulticastBit(Hexadecimal $node) : Hexadecimal | |
| 52 | 49 | { |
| 53 | 50 | $nodeHex = str_pad($node->toString(), 12, '0', STR_PAD_LEFT); |
| 54 | 51 | $firstOctet = substr($nodeHex, 0, 2); |
| 55 | 52 | $firstOctet = str_pad(dechex(hexdec($firstOctet) | 0x1), 2, '0', STR_PAD_LEFT); |