Guid.php
62 lines
| 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 | |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace Ramsey\Uuid\Guid; |
| 16 | |
| 17 | use Ramsey\Uuid\Codec\CodecInterface; |
| 18 | use Ramsey\Uuid\Converter\NumberConverterInterface; |
| 19 | use Ramsey\Uuid\Converter\TimeConverterInterface; |
| 20 | use Ramsey\Uuid\Uuid; |
| 21 | |
| 22 | /** |
| 23 | * Guid represents a UUID with "native" (little-endian) byte order |
| 24 | * |
| 25 | * From Wikipedia: |
| 26 | * |
| 27 | * > The first three fields are unsigned 32- and 16-bit integers and are subject |
| 28 | * > to swapping, while the last two fields consist of uninterpreted bytes, not |
| 29 | * > subject to swapping. This byte swapping applies even for versions 3, 4, and |
| 30 | * > 5, where the canonical fields do not correspond to the content of the UUID. |
| 31 | * |
| 32 | * The first three fields of a GUID are encoded in little-endian byte order, |
| 33 | * while the last three fields are in network (big-endian) byte order. This is |
| 34 | * according to the history of the Microsoft definition of a GUID. |
| 35 | * |
| 36 | * According to the .NET Guid.ToByteArray method documentation: |
| 37 | * |
| 38 | * > Note that the order of bytes in the returned byte array is different from |
| 39 | * > the string representation of a Guid value. The order of the beginning |
| 40 | * > four-byte group and the next two two-byte groups is reversed, whereas the |
| 41 | * > order of the last two-byte group and the closing six-byte group is the |
| 42 | * > same. |
| 43 | * |
| 44 | * @link https://en.wikipedia.org/wiki/Universally_unique_identifier#Variants UUID Variants on Wikipedia |
| 45 | * @link https://docs.microsoft.com/en-us/windows/win32/api/guiddef/ns-guiddef-guid Windows GUID structure |
| 46 | * @link https://docs.microsoft.com/en-us/dotnet/api/system.guid .NET Guid Struct |
| 47 | * @link https://docs.microsoft.com/en-us/dotnet/api/system.guid.tobytearray .NET Guid.ToByteArray Method |
| 48 | * |
| 49 | * @psalm-immutable |
| 50 | */ |
| 51 | final class Guid extends Uuid |
| 52 | { |
| 53 | public function __construct( |
| 54 | Fields $fields, |
| 55 | NumberConverterInterface $numberConverter, |
| 56 | CodecInterface $codec, |
| 57 | TimeConverterInterface $timeConverter |
| 58 | ) { |
| 59 | parent::__construct($fields, $numberConverter, $codec, $timeConverter); |
| 60 | } |
| 61 | } |
| 62 |