Scope.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Config;
  7. class Scope implements \Magento\Framework\Config\ScopeInterface, \Magento\Framework\Config\ScopeListInterface
  8. {
  9. /**
  10. * Default application scope
  11. *
  12. * @var string
  13. */
  14. protected $_defaultScope;
  15. /**
  16. * Current config scope
  17. *
  18. * @var string
  19. */
  20. protected $_currentScope;
  21. /**
  22. * List of all available areas
  23. *
  24. * @var \Magento\Framework\App\AreaList
  25. */
  26. protected $_areaList;
  27. /**
  28. * Constructor
  29. *
  30. * @param \Magento\Framework\App\AreaList $areaList
  31. * @param string $defaultScope
  32. */
  33. public function __construct(\Magento\Framework\App\AreaList $areaList, $defaultScope = 'primary')
  34. {
  35. $this->_defaultScope = $this->_currentScope = $defaultScope;
  36. $this->_areaList = $areaList;
  37. }
  38. /**
  39. * Get current configuration scope identifier
  40. *
  41. * @return string
  42. */
  43. public function getCurrentScope()
  44. {
  45. return $this->_currentScope;
  46. }
  47. /**
  48. * Set current configuration scope
  49. *
  50. * @param string $scope
  51. * @return void
  52. */
  53. public function setCurrentScope($scope)
  54. {
  55. $this->_currentScope = $scope;
  56. }
  57. /**
  58. * Retrieve list of available config scopes
  59. *
  60. * @return string[]
  61. */
  62. public function getAllScopes()
  63. {
  64. $codes = $this->_areaList->getCodes();
  65. array_unshift($codes, $this->_defaultScope);
  66. return $codes;
  67. }
  68. }