DataCollector.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Deploy\Model\DeploymentConfig;
  7. use Magento\Framework\App\DeploymentConfig;
  8. /**
  9. * Config data collector of specific sections in configuration files which are defined in di.xml
  10. *
  11. * E.g., definition of sections which are needed to import:
  12. * ```xml
  13. * <type name="Magento\Deploy\Model\DeploymentConfig\ImporterPool">
  14. * <arguments>
  15. * <argument name="importers" xsi:type="array">
  16. * <item name="scopes" xsi:type="string">Magento\SomeModule\Model\SomeImporter</item>
  17. * </argument>
  18. * </arguments>
  19. * </type>
  20. * ```
  21. * Example, how sections are stored with their config data in configuration files:
  22. * ```php
  23. * [
  24. * 'scopes' => [...],
  25. * 'system' => [...],
  26. * 'themes' => [...],
  27. * ...
  28. * ]
  29. * ```
  30. *
  31. * In here we define section "scopes" and its importer Magento\SomeModule\Model\SomeImporter.
  32. * The data of this section will be collected then will be used in importing process from the shared configuration
  33. * files to appropriate application sources.
  34. *
  35. * @see \Magento\Deploy\Console\Command\App\ConfigImport\Processor::execute()
  36. */
  37. class DataCollector
  38. {
  39. /**
  40. * Pool of all deployment configuration importers.
  41. *
  42. * @var ImporterPool
  43. */
  44. private $configImporterPool;
  45. /**
  46. * Application deployment configuration.
  47. *
  48. * @var DeploymentConfig
  49. */
  50. private $deploymentConfig;
  51. /**
  52. * @param ImporterPool $configImporterPool the pool of all deployment configuration importers
  53. * @param DeploymentConfig $deploymentConfig the application deployment configuration
  54. */
  55. public function __construct(ImporterPool $configImporterPool, DeploymentConfig $deploymentConfig)
  56. {
  57. $this->configImporterPool = $configImporterPool;
  58. $this->deploymentConfig = $deploymentConfig;
  59. }
  60. /**
  61. * Retrieves configuration data of specific section from deployment configuration files.
  62. * Or retrieves configuration data of specific sections by its name.
  63. *
  64. * E.g.
  65. * ```php
  66. * [
  67. * 'scopes' => [...],
  68. * 'system' => [...],
  69. * 'themes' => [...],
  70. * ...
  71. * ]
  72. * ```
  73. *
  74. * This method retrieves the same structure for the specific section with only its data.
  75. * ```php
  76. * [
  77. * 'scopes' => [...]
  78. * ]
  79. *
  80. * In this example key of the array is the section name, value of the array is configuration data of the section.
  81. *
  82. * @param string $sectionName the section name for retrieving its configuration data
  83. * @return array
  84. */
  85. public function getConfig($sectionName = null)
  86. {
  87. $result = [];
  88. if ($sectionName) {
  89. $sections = [$sectionName];
  90. } else {
  91. $sections = $this->configImporterPool->getSections();
  92. }
  93. foreach ($sections as $section) {
  94. $result[$section] = $this->deploymentConfig->getConfigData($section);
  95. }
  96. return $result;
  97. }
  98. }