PluginProbe
Media Cloud Sync / 1.2.9
Media Cloud Sync v1.2.9
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 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / google / ramsey / uuid / src / Provider / Node / StaticNodeProvider.php

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

59 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 <ben@benramsey.com>
10 * @license http://opensource.org/licenses/MIT MIT
11 */
12 declare (strict_types=1);
13 namespace Dudlewebs\WPMCS\Ramsey\Uuid\Provider\Node;
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;
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 http://tools.ietf.org/html/rfc4122#section-4.5 RFC 4122, ยง 4.5: Node IDs that Do Not Identify the Host
27 */
28 class StaticNodeProvider implements NodeProviderInterface
29 {
30 /**
31 * @var Hexadecimal
32 */
33 private $node;
34 /**
35 * @param Hexadecimal $node The static node value to use
36 */
37 public function __construct(Hexadecimal $node)
38 {
39 if (strlen($node->toString()) > 12) {
40 throw new InvalidArgumentException('Static node value cannot be greater than 12 hexadecimal characters');
41 }
42 $this->node = $this->setMulticastBit($node);
43 }
44 public function getNode(): Hexadecimal
45 {
46 return $this->node;
47 }
48 /**
49 * Set the multicast bit for the static node value
50 */
51 private function setMulticastBit(Hexadecimal $node): Hexadecimal
52 {
53 $nodeHex = str_pad($node->toString(), 12, '0', STR_PAD_LEFT);
54 $firstOctet = substr($nodeHex, 0, 2);
55 $firstOctet = str_pad(dechex(hexdec($firstOctet) | 0x1), 2, '0', STR_PAD_LEFT);
56 return new Hexadecimal($firstOctet . substr($nodeHex, 2));
57 }
58 }
59