IndexStructureProxy.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CatalogSearch\Model\Indexer;
  7. use Magento\Framework\Indexer\IndexStructureInterface;
  8. /**
  9. * Catalog search index structure proxy.
  10. */
  11. class IndexStructureProxy implements IndexStructureInterface
  12. {
  13. /**
  14. * @var IndexStructureInterface
  15. */
  16. private $indexStructureEntity;
  17. /**
  18. * @var IndexStructureFactory
  19. */
  20. private $indexStructureFactory;
  21. /**
  22. * @param IndexStructureFactory $indexStructureFactory
  23. */
  24. public function __construct(
  25. IndexStructureFactory $indexStructureFactory
  26. ) {
  27. $this->indexStructureFactory = $indexStructureFactory;
  28. }
  29. /**
  30. * @inheritdoc
  31. */
  32. public function delete(
  33. $index,
  34. array $dimensions = []
  35. ) {
  36. return $this->getEntity()->delete($index, $dimensions);
  37. }
  38. /**
  39. * @inheritdoc
  40. */
  41. public function create(
  42. $index,
  43. array $fields,
  44. array $dimensions = []
  45. ) {
  46. return $this->getEntity()->create($index, $fields, $dimensions);
  47. }
  48. /**
  49. * Get instance of current index structure
  50. *
  51. * @return IndexStructureInterface
  52. */
  53. private function getEntity()
  54. {
  55. if (empty($this->indexStructureEntity)) {
  56. $this->indexStructureEntity = $this->indexStructureFactory->create();
  57. }
  58. return $this->indexStructureEntity;
  59. }
  60. }