MaxTrait.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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\Rfc4122;
  13. /**
  14. * Provides common functionality for max UUIDs
  15. *
  16. * The max UUID is special form of UUID that is specified to have all 128 bits
  17. * set to one. It is the inverse of the nil UUID.
  18. *
  19. * @link https://datatracker.ietf.org/doc/html/draft-ietf-uuidrev-rfc4122bis-00#section-5.10 Max UUID
  20. *
  21. * @psalm-immutable
  22. */
  23. trait MaxTrait
  24. {
  25. /**
  26. * Returns the bytes that comprise the fields
  27. */
  28. abstract public function getBytes(): string;
  29. /**
  30. * Returns true if the byte string represents a max UUID
  31. */
  32. public function isMax(): bool
  33. {
  34. return $this->getBytes() === "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
  35. }
  36. }