Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DumpConfigSourceAggregated.php
Go to the documentation of this file.
1 <?php
7 
13 
18 {
22  const RULE_TYPE_INCLUDE = 'include';
23 
27  const RULE_TYPE_EXCLUDE = 'exclude';
28 
34  private $typePool;
35 
39  private $sources;
40 
44  private $excludedFields;
45 
49  private $data;
50 
77  private $rules;
78 
86  public function __construct(
87  ExcludeList $excludeList,
88  array $sources = [],
89  TypePool $typePool = null,
90  array $rules = []
91  ) {
92  $this->sources = $sources;
93  $this->typePool = $typePool ?: ObjectManager::getInstance()->get(TypePool::class);
94  $this->rules = $rules;
95  }
96 
103  public function get($path = '')
104  {
105  $path = (string)$path;
106  $data = [];
107 
108  if (isset($this->data[$path])) {
109  return $this->data[$path];
110  }
111 
112  $this->sortSources();
113 
114  foreach ($this->sources as $sourceConfig) {
116  $source = $sourceConfig['source'];
117  $data = array_replace_recursive($data, $source->get($path));
118  }
119 
120  $this->excludedFields = [];
121  $this->filterChain($path, $data);
122 
123  return $this->data[$path] = $data;
124  }
125 
133  private function filterChain($path, &$data)
134  {
135  foreach ($data as $subKey => &$subData) {
136  $newPath = $path ? $path . '/' . $subKey : $subKey;
137  $filteredPath = $this->filterPath($newPath);
138 
139  if (is_array($subData)) {
140  $this->filterChain($newPath, $subData);
141  } elseif ($this->isExcludedPath($filteredPath)) {
142  $this->excludedFields[$newPath] = $filteredPath;
143  unset($data[$subKey]);
144  }
145 
146  if (empty($subData) && isset($data[$subKey]) && is_array($data[$subKey])) {
147  unset($data[$subKey]);
148  }
149  }
150  }
151 
158  private function isExcludedPath($path)
159  {
160  if (empty($path)) {
161  return false;
162  }
163 
164  $defaultRule = isset($this->rules['default']) ?
165  $this->rules['default'] : self::RULE_TYPE_INCLUDE;
166 
167  foreach ($this->rules as $type => $rule) {
168  if ($type === 'default') {
169  continue;
170  }
171 
172  if ($this->typePool->isPresent($path, $type)) {
173  return $rule === self::RULE_TYPE_EXCLUDE;
174  }
175  }
176 
177  return $defaultRule === self::RULE_TYPE_EXCLUDE;
178  }
179 
186  private function filterPath($path)
187  {
188  $parts = explode('/', $path);
189 
190  // Check if there are enough parts to recognize scope
191  if (count($parts) < 3) {
192  return null;
193  }
194 
195  if ($parts[0] === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
196  unset($parts[0]);
197  } else {
198  unset($parts[0], $parts[1]);
199  }
200 
201  return implode('/', $parts);
202  }
203 
209  private function sortSources()
210  {
211  uasort($this->sources, function ($firstItem, $secondItem) {
212  return $firstItem['sortOrder'] > $secondItem['sortOrder'];
213  });
214  }
215 
220  public function getExcludedFields()
221  {
222  $this->get();
223 
224  $fields = array_values($this->excludedFields);
225  $fields = array_unique($fields);
226 
227  return $fields;
228  }
229 }
__construct(ExcludeList $excludeList, array $sources=[], TypePool $typePool=null, array $rules=[])
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$source
Definition: source.php:23
$fields
Definition: details.phtml:14
$type
Definition: item.phtml:13