Guid.php 2.2 KB

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