Loader.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * System configuration loader
  8. */
  9. namespace Magento\Config\Model\Config;
  10. /**
  11. * Class which can read config by paths
  12. *
  13. * @package Magento\Config\Model\Config
  14. * @api
  15. * @since 100.0.2
  16. */
  17. class Loader
  18. {
  19. /**
  20. * Config data factory
  21. *
  22. * @var \Magento\Framework\App\Config\ValueFactory
  23. */
  24. protected $_configValueFactory;
  25. /**
  26. * @param \Magento\Framework\App\Config\ValueFactory $configValueFactory
  27. */
  28. public function __construct(\Magento\Framework\App\Config\ValueFactory $configValueFactory)
  29. {
  30. $this->_configValueFactory = $configValueFactory;
  31. }
  32. /**
  33. * Get configuration value by path
  34. *
  35. * @param string $path
  36. * @param string $scope
  37. * @param string $scopeId
  38. * @param bool $full
  39. * @return array
  40. */
  41. public function getConfigByPath($path, $scope, $scopeId, $full = true)
  42. {
  43. $configDataCollection = $this->_configValueFactory->create();
  44. $configDataCollection = $configDataCollection->getCollection()->addScopeFilter($scope, $scopeId, $path);
  45. $config = [];
  46. $configDataCollection->load();
  47. foreach ($configDataCollection->getItems() as $data) {
  48. if ($full) {
  49. $config[$data->getPath()] = [
  50. 'path' => $data->getPath(),
  51. 'value' => $data->getValue(),
  52. 'config_id' => $data->getConfigId(),
  53. ];
  54. } else {
  55. $config[$data->getPath()] = $data->getValue();
  56. }
  57. }
  58. return $config;
  59. }
  60. }