Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MetadataProcessor.php
Go to the documentation of this file.
1 <?php
9 
11 {
15  protected $_processorFactory;
16 
20  protected $_metadata = [];
21 
26  public function __construct(
28  Initial $initialConfig
29  ) {
30  $this->_processorFactory = $processorFactory;
31  $this->_metadata = $initialConfig->getMetadata();
32  }
33 
41  protected function _getValue(array $data, $path)
42  {
43  $keys = explode('/', $path);
44  foreach ($keys as $key) {
45  if (is_array($data) && array_key_exists($key, $data)) {
46  $data = $data[$key];
47  } else {
48  return null;
49  }
50  }
51  return $data;
52  }
53 
62  protected function _setValue(array &$container, $path, $value)
63  {
64  $segments = explode('/', $path);
65  $currentPointer = & $container;
66  foreach ($segments as $segment) {
67  if (!isset($currentPointer[$segment])) {
68  $currentPointer[$segment] = [];
69  }
70  $currentPointer = & $currentPointer[$segment];
71  }
72  $currentPointer = $value;
73  }
74 
81  public function process(array $data)
82  {
83  foreach ($this->_metadata as $path => $metadata) {
85  $processor = $this->_processorFactory->get($metadata['backendModel']);
86  $value = $processor->processValue($this->_getValue($data, $path));
87  $this->_setValue($data, $path, $value);
88  }
89  return $data;
90  }
91 }
$processorFactory
Definition: 404.php:9
$processor
Definition: 404.php:10
__construct(\Magento\Framework\App\Config\Data\ProcessorFactory $processorFactory, Initial $initialConfig)
$value
Definition: gender.phtml:16
_setValue(array &$container, $path, $value)