| 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; |
| 14 |
|
| 15 |
/** |
| 16 |
* Provides binary math utilities |
| 17 |
*/ |
| 18 |
class BinaryUtils |
| 19 |
{ |
| 20 |
/** |
| 21 |
* Applies the RFC 4122 variant field to the 16-bit clock sequence |
| 22 |
* |
| 23 |
* @link http://tools.ietf.org/html/rfc4122#section-4.1.1 RFC 4122, § 4.1.1: Variant |
| 24 |
* |
| 25 |
* @param int $clockSeq The 16-bit clock sequence value before the RFC 4122 |
| 26 |
* variant is applied |
| 27 |
* |
| 28 |
* @return int The 16-bit clock sequence multiplexed with the UUID variant |
| 29 |
* |
| 30 |
* @psalm-pure |
| 31 |
*/ |
| 32 |
public static function applyVariant(int $clockSeq): int |
| 33 |
{ |
| 34 |
$clockSeq = $clockSeq & 0x3fff; |
| 35 |
$clockSeq |= 0x8000; |
| 36 |
return $clockSeq; |
| 37 |
} |
| 38 |
/** |
| 39 |
* Applies the RFC 4122 version number to the 16-bit `time_hi_and_version` field |
| 40 |
* |
| 41 |
* @link http://tools.ietf.org/html/rfc4122#section-4.1.3 RFC 4122, § 4.1.3: Version |
| 42 |
* |
| 43 |
* @param int $timeHi The value of the 16-bit `time_hi_and_version` field |
| 44 |
* before the RFC 4122 version is applied |
| 45 |
* @param int $version The RFC 4122 version to apply to the `time_hi` field |
| 46 |
* |
| 47 |
* @return int The 16-bit time_hi field of the timestamp multiplexed with |
| 48 |
* the UUID version number |
| 49 |
* |
| 50 |
* @psalm-pure |
| 51 |
*/ |
| 52 |
public static function applyVersion(int $timeHi, int $version): int |
| 53 |
{ |
| 54 |
$timeHi = $timeHi & 0xfff; |
| 55 |
$timeHi |= $version << 12; |
| 56 |
return $timeHi; |
| 57 |
} |
| 58 |
} |
| 59 |
|