UpdateMain.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\EntityManager\Operation\Update;
  7. use Magento\Framework\EntityManager\TypeResolver;
  8. use Magento\Framework\EntityManager\HydratorPool;
  9. use Magento\Framework\EntityManager\Db\UpdateRow;
  10. /**
  11. * Class UpdateMain
  12. */
  13. class UpdateMain
  14. {
  15. /**
  16. * @var TypeResolver
  17. */
  18. private $typeResolver;
  19. /**
  20. * @var HydratorPool
  21. */
  22. private $hydratorPool;
  23. /**
  24. * @var UpdateRow
  25. */
  26. private $updateRow;
  27. /**
  28. * @param TypeResolver $typeResolver
  29. * @param HydratorPool $hydratorPool
  30. * @param UpdateRow $updateRow
  31. */
  32. public function __construct(
  33. TypeResolver $typeResolver,
  34. HydratorPool $hydratorPool,
  35. UpdateRow $updateRow
  36. ) {
  37. $this->typeResolver = $typeResolver;
  38. $this->hydratorPool = $hydratorPool;
  39. $this->updateRow = $updateRow;
  40. }
  41. /**
  42. * @param object $entity
  43. * @param array $arguments
  44. * @return object
  45. */
  46. public function execute($entity, $arguments = [])
  47. {
  48. $entityType = $this->typeResolver->resolve($entity);
  49. $hydrator = $this->hydratorPool->getHydrator($entityType);
  50. $arguments = array_merge($hydrator->extract($entity), $arguments);
  51. $entityData = $this->updateRow->execute($entityType, $arguments);
  52. $entity = $hydrator->hydrate($entity, $entityData);
  53. return $entity;
  54. }
  55. }