IndexNameResolver.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\InventoryMultiDimensionalIndexerApi\Model;
  8. use Magento\Framework\Search\Request\IndexScopeResolverInterface;
  9. /**
  10. * @inheritdoc
  11. */
  12. class IndexNameResolver implements IndexNameResolverInterface
  13. {
  14. /**
  15. * TODO: move to separate configurable interface (https://github.com/magento-engcom/msi/issues/213)
  16. * Suffix for replica index table
  17. *
  18. * @var string
  19. */
  20. private $additionalTableSuffix = '_replica';
  21. /**
  22. * @var IndexScopeResolverInterface
  23. */
  24. private $indexScopeResolver;
  25. /**
  26. * @param IndexScopeResolverInterface $indexScopeResolver
  27. */
  28. public function __construct(
  29. IndexScopeResolverInterface $indexScopeResolver
  30. ) {
  31. $this->indexScopeResolver = $indexScopeResolver;
  32. }
  33. /**
  34. * @inheritdoc
  35. */
  36. public function resolveName(IndexName $indexName): string
  37. {
  38. $tableName = $this->indexScopeResolver->resolve($indexName->getIndexId(), $indexName->getDimensions());
  39. if ($indexName->getAlias()->getValue() === Alias::ALIAS_REPLICA) {
  40. $tableName = $this->getAdditionalTableName($tableName);
  41. }
  42. return $tableName;
  43. }
  44. /**
  45. * TODO: move to separate configurable interface (https://github.com/magento-engcom/msi/issues/213)
  46. * @param string $tableName
  47. * @return string
  48. */
  49. public function getAdditionalTableName(string $tableName): string
  50. {
  51. return $tableName . $this->additionalTableSuffix;
  52. }
  53. }