InitialSnapshotConfigSource.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Config\App\Config\Source;
  7. use Magento\Framework\App\Config\ConfigSourceInterface;
  8. use Magento\Framework\DataObjectFactory;
  9. use Magento\Framework\FlagManager;
  10. /**
  11. * The source with previously imported configuration.
  12. * @api
  13. * @since 101.0.0
  14. */
  15. class InitialSnapshotConfigSource implements ConfigSourceInterface
  16. {
  17. /**
  18. * The factory of Flag instances.
  19. *
  20. * @var FlagManager
  21. */
  22. private $flagManager;
  23. /**
  24. * The factory of DataObject instances.
  25. *
  26. * @var DataObjectFactory
  27. */
  28. private $dataObjectFactory;
  29. /**
  30. * @param FlagManager $flagManager The factory of Flag instances
  31. * @param DataObjectFactory $dataObjectFactory The factory of DataObject instances
  32. */
  33. public function __construct(FlagManager $flagManager, DataObjectFactory $dataObjectFactory)
  34. {
  35. $this->flagManager = $flagManager;
  36. $this->dataObjectFactory = $dataObjectFactory;
  37. }
  38. /**
  39. * Retrieves previously imported configuration.
  40. * Snapshots are stored in flags.
  41. *
  42. * {@inheritdoc}
  43. * @since 101.0.0
  44. */
  45. public function get($path = '')
  46. {
  47. $flagData = (array)($this->flagManager->getFlagData('system_config_snapshot') ?: []);
  48. $data = $this->dataObjectFactory->create(
  49. ['data' => $flagData]
  50. );
  51. return $data->getData($path) ?: [];
  52. }
  53. }