Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Pool.php
Go to the documentation of this file.
1 <?php
8 
10 
15 {
19  protected $modifiers = [];
20 
24  protected $modifiersInstances = [];
25 
29  protected $factory;
30 
35  public function __construct(
37  array $modifiers = []
38  ) {
39  $this->factory = $factory;
40  $this->modifiers = $this->sort($modifiers);
41  }
42 
48  public function getModifiers()
49  {
50  return $this->modifiers;
51  }
52 
59  public function getModifiersInstances()
60  {
61  if ($this->modifiersInstances) {
63  }
64 
65  foreach ($this->modifiers as $modifier) {
66  if (empty($modifier['class'])) {
67  throw new LocalizedException(__('The parameter "class" is missing. Set the "class" and try again.'));
68  }
69 
70  if (empty($modifier['sortOrder'])) {
71  throw new LocalizedException(
72  __('The parameter "sortOrder" is missing. Set the "sortOrder" and try again.')
73  );
74  }
75 
76  $this->modifiersInstances[$modifier['class']] = $this->factory->create($modifier['class']);
77  }
78 
80  }
81 
88  protected function sort(array $data)
89  {
90  usort($data, function (array $a, array $b) {
91  $a['sortOrder'] = $this->getSortOrder($a);
92  $b['sortOrder'] = $this->getSortOrder($b);
93 
94  if ($a['sortOrder'] == $b['sortOrder']) {
95  return 0;
96  }
97 
98  return ($a['sortOrder'] < $b['sortOrder']) ? -1 : 1;
99  });
100 
101  return $data;
102  }
103 
110  protected function getSortOrder(array $variable)
111  {
112  return !empty($variable['sortOrder']) ? $variable['sortOrder'] : 0;
113  }
114 }
__construct(ModifierFactory $factory, array $modifiers=[])
Definition: Pool.php:35
__()
Definition: __.php:13
$variable
Definition: variable.php:7