InitialConfigSource.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Store\App\Config\Source;
  7. use Magento\Framework\App\Config\ConfigSourceInterface;
  8. use Magento\Framework\App\DeploymentConfig;
  9. use Magento\Framework\App\DeploymentConfig\Reader;
  10. /**
  11. * Config source. Retrieve all configuration data from files for specified config type
  12. */
  13. class InitialConfigSource implements ConfigSourceInterface
  14. {
  15. /**
  16. * The file reader
  17. *
  18. * @var Reader
  19. */
  20. private $reader;
  21. /**
  22. * The deployment config reader
  23. *
  24. * @var DeploymentConfig
  25. */
  26. private $deploymentConfig;
  27. /**
  28. * The config type
  29. *
  30. * @var string
  31. */
  32. private $configType;
  33. /**
  34. * @param Reader $reader The file reader
  35. * @param DeploymentConfig $deploymentConfig The deployment config reader
  36. * @param string $configType The config type
  37. */
  38. public function __construct(
  39. Reader $reader,
  40. DeploymentConfig $deploymentConfig,
  41. $configType
  42. ) {
  43. $this->reader = $reader;
  44. $this->deploymentConfig = $deploymentConfig;
  45. $this->configType = $configType;
  46. }
  47. /**
  48. * Return whole config data from config file for specified config type.
  49. * Ignore $path argument due to config source must return all config data
  50. *
  51. * @param string $path
  52. * @return array
  53. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  54. */
  55. public function get($path = '')
  56. {
  57. /**
  58. * Magento store configuration should not be read from file source if database is available
  59. *
  60. * @see \Magento\Store\Model\Config\Importer To import store configs
  61. */
  62. if ($this->deploymentConfig->isAvailable()) {
  63. return [];
  64. }
  65. return $this->reader->load()[$this->configType] ?? [];
  66. }
  67. }