ConfigOptionsList.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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\Config\Setup;
  8. use Magento\Framework\App\DeploymentConfig;
  9. use Magento\Framework\Config\Data\ConfigData;
  10. use Magento\Framework\Config\Data\ConfigDataFactory;
  11. use Magento\Framework\Config\File\ConfigFilePool;
  12. use Magento\Framework\Setup\ConfigOptionsListInterface;
  13. use Magento\Framework\Setup\Option\SelectConfigOption;
  14. /**
  15. * Deployment configuration options required for the Config module.
  16. */
  17. class ConfigOptionsList implements ConfigOptionsListInterface
  18. {
  19. /**
  20. * Input key for the debug_logging option.
  21. */
  22. const INPUT_KEY_DEBUG_LOGGING = 'enable-debug-logging';
  23. /**
  24. * Path to the debug_logging value in the deployment config.
  25. */
  26. const CONFIG_PATH_DEBUG_LOGGING = 'dev/debug/debug_logging';
  27. /**
  28. * Input key for the syslog_logging option.
  29. */
  30. const INPUT_KEY_SYSLOG_LOGGING = 'enable-syslog-logging';
  31. /**
  32. * Path to the syslog_logging value in the deployment config.
  33. */
  34. const CONFIG_PATH_SYSLOG_LOGGING = 'dev/syslog/syslog_logging';
  35. /**
  36. * @var ConfigDataFactory
  37. */
  38. private $configDataFactory;
  39. /**
  40. * @param ConfigDataFactory $configDataFactory
  41. */
  42. public function __construct(ConfigDataFactory $configDataFactory)
  43. {
  44. $this->configDataFactory = $configDataFactory;
  45. }
  46. /**
  47. * @inheritdoc
  48. */
  49. public function getOptions()
  50. {
  51. return [
  52. new SelectConfigOption(
  53. self::INPUT_KEY_DEBUG_LOGGING,
  54. SelectConfigOption::FRONTEND_WIZARD_RADIO,
  55. [true, false, 1, 0],
  56. self::CONFIG_PATH_DEBUG_LOGGING,
  57. 'Enable debug logging'
  58. ),
  59. new SelectConfigOption(
  60. self::INPUT_KEY_SYSLOG_LOGGING,
  61. SelectConfigOption::FRONTEND_WIZARD_RADIO,
  62. [true, false, 1, 0],
  63. self::CONFIG_PATH_SYSLOG_LOGGING,
  64. 'Enable syslog logging'
  65. ),
  66. ];
  67. }
  68. /**
  69. * @inheritdoc
  70. */
  71. public function createConfig(array $options, DeploymentConfig $deploymentConfig)
  72. {
  73. $deploymentOption = [
  74. self::INPUT_KEY_DEBUG_LOGGING => self::CONFIG_PATH_DEBUG_LOGGING,
  75. self::INPUT_KEY_SYSLOG_LOGGING => self::CONFIG_PATH_SYSLOG_LOGGING,
  76. ];
  77. $config = [];
  78. foreach ($deploymentOption as $inputKey => $configPath) {
  79. $configValue = $this->processBooleanConfigValue(
  80. $inputKey,
  81. $configPath,
  82. $options
  83. );
  84. if ($configValue) {
  85. $config[] = $configValue;
  86. }
  87. }
  88. return $config;
  89. }
  90. /**
  91. * Provide config value from input.
  92. *
  93. * @param string $inputKey
  94. * @param string $configPath
  95. * @param array $options
  96. * @return ConfigData|null
  97. */
  98. private function processBooleanConfigValue(string $inputKey, string $configPath, array &$options): ?ConfigData
  99. {
  100. $configData = null;
  101. if (isset($options[$inputKey])) {
  102. $configData = $this->configDataFactory->create(ConfigFilePool::APP_ENV);
  103. if ($options[$inputKey] === 'true'
  104. || $options[$inputKey] === '1') {
  105. $value = 1;
  106. } else {
  107. $value = 0;
  108. }
  109. $configData->set($configPath, $value);
  110. }
  111. return $configData;
  112. }
  113. /**
  114. * @inheritdoc
  115. */
  116. public function validate(array $options, DeploymentConfig $deploymentConfig)
  117. {
  118. return [];
  119. }
  120. }