Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CompositeConverter.php
Go to the documentation of this file.
1 <?php
7 
10 
17 {
21  private $converters;
22 
28  public function __construct(array $converters)
29  {
30  $this->converters = [];
31  $converters = $this->sortConverters($converters);
32  foreach ($converters as $name => $converterInfo) {
33  if (!isset($converterInfo['converter']) || !($converterInfo['converter'] instanceof ConverterInterface)) {
34  throw new \InvalidArgumentException(
35  new Phrase(
36  'Converter [%name] must implement Magento\Framework\Config\ConverterInterface',
37  ['name' => $name]
38  )
39  );
40  }
41  $this->converters[] = $converterInfo['converter'];
42  }
43  }
44 
48  public function convert($source)
49  {
50  $result = [];
51  foreach ($this->converters as $converter) {
52  $result = array_replace_recursive($result, $converter->convert($source));
53  }
54  return $result;
55  }
56 
63  private function sortConverters(array $converters)
64  {
65  usort(
66  $converters,
67  function ($firstItem, $secondItem) {
68  $firstValue = 0;
69  $secondValue = 0;
70  if (isset($firstItem['sortOrder'])) {
71  $firstValue = intval($firstItem['sortOrder']);
72  }
73  if (isset($secondItem['sortOrder'])) {
74  $secondValue = intval($secondItem['sortOrder']);
75  }
76  return $firstValue <=> $secondValue;
77  }
78  );
79  return $converters;
80  }
81 }
$source
Definition: source.php:23
if(!isset($_GET['name'])) $name
Definition: log.php:14