ValidateDataIntegrity.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Model\ResourceModel\Db;
  7. use Magento\Framework\EntityManager\MetadataPool;
  8. use Magento\Framework\EntityManager\HydratorPool;
  9. /**
  10. * Class ValidateDataIntegrity
  11. */
  12. class ValidateDataIntegrity
  13. {
  14. /**
  15. * @var MetadataPool
  16. */
  17. private $metadataPool;
  18. /**
  19. * @var HydratorPool
  20. */
  21. private $hydratorPool;
  22. /**
  23. * @var ObjectRelationProcessor
  24. */
  25. private $objectRelationProcessor;
  26. /**
  27. * ValidateDataIntegrity constructor.
  28. *
  29. * @param MetadataPool $metadataPool
  30. * @param HydratorPool $hydratorPool
  31. * @param ObjectRelationProcessor $objectRelationProcessor
  32. */
  33. public function __construct(
  34. MetadataPool $metadataPool,
  35. HydratorPool $hydratorPool,
  36. ObjectRelationProcessor $objectRelationProcessor
  37. ) {
  38. $this->metadataPool = $metadataPool;
  39. $this->hydratorPool = $hydratorPool;
  40. $this->objectRelationProcessor = $objectRelationProcessor;
  41. }
  42. /**
  43. * @param string $entityType
  44. * @param object $entity
  45. * @throws \Exception
  46. * @return void
  47. */
  48. public function execute($entityType, $entity)
  49. {
  50. $metadata = $this->metadataPool->getMetadata($entityType);
  51. $hydrator = $this->hydratorPool->getHydrator($entityType);
  52. $this->objectRelationProcessor->validateDataIntegrity(
  53. $metadata->getEntityTable(),
  54. $hydrator->extract($entity)
  55. );
  56. }
  57. }