Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GroupRepository.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Store\Model;
7 
11 
18 {
22  protected $groupFactory;
23 
27  protected $entities = [];
28 
32  protected $allLoaded = false;
33 
38 
42  private $appConfig;
43 
48  public function __construct(
49  GroupFactory $groupFactory,
51  ) {
52  $this->groupFactory = $groupFactory;
53  $this->groupCollectionFactory = $groupCollectionFactory;
54  }
55 
59  public function get($id)
60  {
61  if (isset($this->entities[$id])) {
62  return $this->entities[$id];
63  }
64 
65  $group = $this->groupFactory->create([
66  'data' => $this->getAppConfig()->get('scopes', "groups/$id", [])
67  ]);
68 
69  if (null === $group->getId()) {
70  throw new NoSuchEntityException();
71  }
72  $this->entities[$id] = $group;
73  return $group;
74  }
75 
79  public function getList()
80  {
81  if (!$this->allLoaded) {
82  $groups = $this->getAppConfig()->get('scopes', 'groups', []);
83  foreach ($groups as $data) {
84  $group = $this->groupFactory->create([
85  'data' => $data
86  ]);
87  $this->entities[$group->getId()] = $group;
88  }
89  $this->allLoaded = true;
90  }
91 
92  return $this->entities;
93  }
94 
98  public function clean()
99  {
100  $this->entities = [];
101  $this->allLoaded = false;
102  }
103 
110  private function getAppConfig()
111  {
112  if (!$this->appConfig) {
113  $this->appConfig = ObjectManager::getInstance()->get(Config::class);
114  }
115  return $this->appConfig;
116  }
117 }
$id
Definition: fieldset.phtml:14
$group
Definition: sections.phtml:16
__construct(GroupFactory $groupFactory, \Magento\Store\Model\ResourceModel\Group\CollectionFactory $groupCollectionFactory)