Strategy.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Indexer\Table;
  7. class Strategy implements StrategyInterface
  8. {
  9. /**
  10. * Application resource
  11. *
  12. * @var \Magento\Framework\App\ResourceConnection
  13. */
  14. protected $resource;
  15. /**
  16. * Constructor
  17. *
  18. * @param \Magento\Framework\App\ResourceConnection $resource
  19. */
  20. public function __construct(
  21. \Magento\Framework\App\ResourceConnection $resource
  22. ) {
  23. $this->resource = $resource;
  24. }
  25. /**
  26. * Use index table directly
  27. *
  28. * @var bool
  29. */
  30. protected $useIdxTable = false;
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function getUseIdxTable()
  35. {
  36. return $this->useIdxTable;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function setUseIdxTable($value = false)
  42. {
  43. $this->useIdxTable = (bool) $value;
  44. return $this;
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function getTableName($tablePrefix)
  50. {
  51. return $this->resource->getTableName($this->prepareTableName($tablePrefix));
  52. }
  53. /**
  54. * Prepare index table name
  55. *
  56. * @param string $tablePrefix
  57. *
  58. * @return string
  59. */
  60. public function prepareTableName($tablePrefix)
  61. {
  62. return $this->getUseIdxTable()
  63. ? $tablePrefix . self::IDX_SUFFIX
  64. : $tablePrefix . self::TMP_SUFFIX;
  65. }
  66. }