Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Data.php
Go to the documentation of this file.
1 <?php
9 
10 class Data implements DataInterface
11 {
17  protected $_data = [];
18 
24  protected $_source = [];
25 
31  {
33  $this->_data = $processor->process($this->arrayClone($data));
34  $this->_source = $data;
35  }
36 
40  public function getSource()
41  {
42  return $this->_source;
43  }
44 
48  public function getValue($path = null)
49  {
50  if ($path === null) {
51  return $this->_data;
52  }
53  $keys = explode('/', $path);
55  foreach ($keys as $key) {
56  if (is_array($data) && array_key_exists($key, $data)) {
57  $data = $data[$key];
58  } else {
59  return null;
60  }
61  }
62  return $data;
63  }
64 
68  public function setValue($path, $value)
69  {
70  $keys = explode('/', $path);
71  $lastKey = array_pop($keys);
72  $currentElement = & $this->_data;
73  foreach ($keys as $key) {
74  if (!isset($currentElement[$key])) {
75  $currentElement[$key] = [];
76  }
77  $currentElement = & $currentElement[$key];
78  }
79  $currentElement[$lastKey] = $value;
80  }
81 
88  private function arrayClone(array $data)
89  {
90  $clone = [];
91  foreach ($data as $key => $value) {
92  $clone[$key]= $value;
93  }
94  return $clone;
95  }
96 }
$processor
Definition: 404.php:10
$value
Definition: gender.phtml:16
__construct(MetadataProcessor $processor, array $data)
Definition: Data.php:30