Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ImporterPool.php
Go to the documentation of this file.
1 <?php
8 
12 
19 {
63  private $importers = [];
64 
80  private $sortedImporters = [];
81 
87  private $objectManager;
88 
95  private $validatorFactory;
96 
102  public function __construct(
103  ObjectManagerInterface $objectManager,
104  ValidatorFactory $validatorFactory,
105  array $importers = []
106  ) {
107  $this->objectManager = $objectManager;
108  $this->validatorFactory = $validatorFactory;
109  $this->importers = $importers;
110  }
111 
126  public function getSections()
127  {
128  return array_keys($this->importers);
129  }
130 
145  public function getImporters()
146  {
147  if (!$this->sortedImporters) {
148  $sortedImporters = [];
149 
150  foreach ($this->sort($this->importers) as $section => $importer) {
151  if (empty($importer['importer_class'])) {
153  __('The parameter "importer_class" is missing. Set the "importer_class" and try again.')
154  );
155  }
156 
157  $sortedImporters[$section] = $importer['importer_class'];
158  }
159 
160  $this->sortedImporters = $sortedImporters;
161  }
162 
163  return $this->sortedImporters;
164  }
165 
173  public function getValidator($section)
174  {
175  if (isset($this->importers[$section]) && !empty($this->importers[$section]['validator_class'])) {
176  return $this->validatorFactory->create($this->importers[$section]['validator_class']);
177  }
178  return null;
179  }
180 
187  private function sort(array $data)
188  {
189  uasort($data, function (array $a, array $b) {
190  $a['sort_order'] = $this->getSortOrder($a);
191  $b['sort_order'] = $this->getSortOrder($b);
192 
193  if ($a['sort_order'] == $b['sort_order']) {
194  return 0;
195  }
196 
197  return ($a['sort_order'] < $b['sort_order']) ? -1 : 1;
198  });
199 
200  return $data;
201  }
202 
209  private function getSortOrder(array $variable)
210  {
211  return !empty($variable['sort_order']) ? $variable['sort_order'] : 0;
212  }
213 }
__construct(ObjectManagerInterface $objectManager, ValidatorFactory $validatorFactory, array $importers=[])
$objectManager
Definition: bootstrap.php:17
__()
Definition: __.php:13
$variable
Definition: variable.php:7