IdentityService.php 872 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\DataObject;
  7. use Ramsey\Uuid\Uuid;
  8. /**
  9. * Class IdentityService
  10. */
  11. class IdentityService implements IdentityGeneratorInterface
  12. {
  13. /**
  14. * @var \Ramsey\Uuid\UuidFactoryInterface
  15. */
  16. private $uuidFactory;
  17. /**
  18. * IdentityService constructor.
  19. */
  20. public function __construct()
  21. {
  22. $this->uuidFactory = new \Ramsey\Uuid\UuidFactory();
  23. }
  24. /**
  25. * @inheritDoc
  26. */
  27. public function generateId()
  28. {
  29. $uuid = $this->uuidFactory->uuid4();
  30. return $uuid->toString();
  31. }
  32. /**
  33. * @inheritDoc
  34. */
  35. public function generateIdForData($data)
  36. {
  37. $uuid = $this->uuidFactory->uuid3(Uuid::NAMESPACE_DNS, $data);
  38. return $uuid->toString();
  39. }
  40. }