AbstractFlatState.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Catalog\Model\Indexer;
  7. use Magento\Store\Model\ScopeInterface;
  8. /**
  9. * @api
  10. * @since 100.0.2
  11. */
  12. abstract class AbstractFlatState
  13. {
  14. /**
  15. * Indexer ID in configuration
  16. */
  17. const INDEXER_ID = '';
  18. /**
  19. * Flat Is Enabled Config XML Path
  20. */
  21. const INDEXER_ENABLED_XML_PATH = '';
  22. /**
  23. * @var \Magento\Framework\App\Config\ScopeConfigInterface
  24. */
  25. protected $scopeConfig;
  26. /**
  27. * @var bool
  28. */
  29. protected $isAvailable;
  30. /**
  31. * @var \Magento\Framework\Indexer\IndexerRegistry
  32. */
  33. protected $indexerRegistry;
  34. /**
  35. * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  36. * @param \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
  37. * @param bool $isAvailable
  38. */
  39. public function __construct(
  40. \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
  41. \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry,
  42. $isAvailable = false
  43. ) {
  44. $this->scopeConfig = $scopeConfig;
  45. $this->indexerRegistry = $indexerRegistry;
  46. $this->isAvailable = $isAvailable;
  47. }
  48. /**
  49. * Check if Flat Index is enabled
  50. *
  51. * @return bool
  52. */
  53. public function isFlatEnabled()
  54. {
  55. return $this->scopeConfig->isSetFlag(static::INDEXER_ENABLED_XML_PATH, ScopeInterface::SCOPE_STORE);
  56. }
  57. /**
  58. * Check if Flat Index is available for use
  59. *
  60. * @return bool
  61. */
  62. public function isAvailable()
  63. {
  64. return $this->isAvailable && $this->isFlatEnabled()
  65. && $this->indexerRegistry->get(static::INDEXER_ID)->isValid();
  66. }
  67. }