PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
media-cloud-sync / includes / sdk / google / ramsey / uuid / src / Provider / Node / StaticNodeProvider.php

StaticNodeProvider.php in Media Cloud Sync 1.4.2, at includes/sdk/google/ramsey/uuid/src/Provider/Node/StaticNodeProvider.php

56 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * This file is part of the ramsey/uuid library
5 *
6 * For the full copyright and license information, please view the LICENSE
7 * file that was distributed with this source code.
8 *
9 * @copyright Copyright (c) Ben Ramsey <[email protected]>
10 * @license http://opensource.org/licenses/MIT MIT
11 */
12 declare (strict_types=1);
13 namespace Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Provider\Node;
14
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 use function dechex;
19 use function hexdec;
20 use function str_pad;
21 use function substr;
22 use const STR_PAD_LEFT;
23 /**
24 * StaticNodeProvider provides a static node value with the multicast bit set
25 *
26 * @link https://www.rfc-editor.org/rfc/rfc9562#section-6.10 RFC 9562, 6.10. UUIDs That Do Not Identify the Host
27 */
28 class StaticNodeProvider implements NodeProviderInterface
29 {
30 private Hexadecimal $node;
31 /**
32 * @param Hexadecimal $node The static node value to use
33 */
34 public function __construct(Hexadecimal $node)
35 {
36 if (\strlen($node->toString()) > 12) {
37 throw new InvalidArgumentException('Static node value cannot be greater than 12 hexadecimal characters');
38 }
39 $this->node = $this->setMulticastBit($node);
40 }
41 public function getNode() : Hexadecimal
42 {
43 return $this->node;
44 }
45 /**
46 * Set the multicast bit for the static node value
47 */
48 private function setMulticastBit(Hexadecimal $node) : Hexadecimal
49 {
50 $nodeHex = str_pad($node->toString(), 12, '0', STR_PAD_LEFT);
51 $firstOctet = substr($nodeHex, 0, 2);
52 $firstOctet = str_pad(dechex(hexdec($firstOctet) | 0x1), 2, '0', STR_PAD_LEFT);
53 return new Hexadecimal($firstOctet . substr($nodeHex, 2));
54 }
55 }
56