Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfigData.php
Go to the documentation of this file.
1 <?php
8 
15 {
21  private $fileKey;
22 
28  private $data = [];
29 
35  private $overrideWhenSave = false;
36 
42  public function __construct($fileKey)
43  {
44  $this->fileKey = $fileKey;
45  }
46 
52  public function getFileKey()
53  {
54  return $this->fileKey;
55  }
56 
62  public function getData()
63  {
64  return $this->data;
65  }
66 
74  public function setOverrideWhenSave($overrideWhenSave)
75  {
76  $this->overrideWhenSave = $overrideWhenSave;
77  }
78 
85  public function isOverrideWhenSave()
86  {
87  return $this->overrideWhenSave;
88  }
89 
97  public function set($path, $value)
98  {
99  $chunks = $this->expand($path);
100  $data = [];
101  $element = &$data;
102 
103  while ($chunks) {
104  $key = array_shift($chunks);
105  if ($chunks) {
106  $element[$key] = [];
107  $element = &$element[$key];
108  } else {
109  $element[$key] = $value;
110  }
111  }
112 
113  $this->data = array_replace_recursive($this->data, $data);
114  }
115 
125  private function expand($path)
126  {
127  $chunks = explode('/', $path);
128 
129  foreach ($chunks as $chunk) {
130  if ('' == $chunk) {
131  throw new \InvalidArgumentException(
132  "Path '$path' is invalid. It cannot be empty nor start or end with '/'"
133  );
134  }
135  }
136 
137  return $chunks;
138  }
139 }
$value
Definition: gender.phtml:16
$element
Definition: element.phtml:12