Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Ini.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Config/Writer/FileAbstract.php';
26 
34 {
40  protected $_nestSeparator = '.';
41 
47  protected $_renderWithoutSections = false;
48 
55  public function setNestSeparator($separator)
56  {
57  $this->_nestSeparator = $separator;
58 
59  return $this;
60  }
61 
71  public function setRenderWithoutSections($withoutSections=true)
72  {
73  $this->_renderWithoutSections = (bool)$withoutSections;
74  return $this;
75  }
76 
83  public function render()
84  {
85  $iniString = '';
86  $extends = $this->_config->getExtends();
87  $sectionName = $this->_config->getSectionName();
88 
89  if($this->_renderWithoutSections == true) {
90  $iniString .= $this->_addBranch($this->_config);
91  } else if (is_string($sectionName)) {
92  $iniString .= '[' . $sectionName . ']' . "\n"
93  . $this->_addBranch($this->_config)
94  . "\n";
95  } else {
96  $config = $this->_sortRootElements($this->_config);
97  foreach ($config as $sectionName => $data) {
98  if (!($data instanceof Zend_Config)) {
99  $iniString .= $sectionName
100  . ' = '
101  . $this->_prepareValue($data)
102  . "\n";
103  } else {
104  if (isset($extends[$sectionName])) {
105  $sectionName .= ' : ' . $extends[$sectionName];
106  }
107 
108  $iniString .= '[' . $sectionName . ']' . "\n"
109  . $this->_addBranch($data)
110  . "\n";
111  }
112  }
113  }
114 
115  return $iniString;
116  }
117 
124  protected function _addBranch(Zend_Config $config, $parents = array())
125  {
126  $iniString = '';
127 
128  foreach ($config as $key => $value) {
129  $group = array_merge($parents, array($key));
130 
131  if ($value instanceof Zend_Config) {
132  $iniString .= $this->_addBranch($value, $group);
133  } else {
134  $iniString .= implode($this->_nestSeparator, $group)
135  . ' = '
136  . $this->_prepareValue($value)
137  . "\n";
138  }
139  }
140 
141  return $iniString;
142  }
143 
150  protected function _prepareValue($value)
151  {
152  if (is_integer($value) || is_float($value)) {
153  return $value;
154  } elseif (is_bool($value)) {
155  return ($value ? 'true' : 'false');
156  } elseif (strpos($value, '"') === false) {
157  return '"' . $value . '"';
158  } else {
160  #require_once 'Zend/Config/Exception.php';
161  throw new Zend_Config_Exception('Value can not contain double quotes "');
162  }
163  }
164 
174  {
175  $configArray = $config->toArray();
176  $sections = array();
177 
178  // remove sections from config array
179  foreach ($configArray as $key => $value) {
180  if (is_array($value)) {
181  $sections[$key] = $value;
182  unset($configArray[$key]);
183  }
184  }
185 
186  // readd sections to the end
187  foreach ($sections as $key => $value) {
188  $configArray[$key] = $value;
189  }
190 
191  return new Zend_Config($configArray);
192  }
193 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$config
Definition: fraud_order.php:17
setRenderWithoutSections($withoutSections=true)
Definition: Ini.php:71
$group
Definition: sections.phtml:16
_prepareValue($value)
Definition: Ini.php:150
$value
Definition: gender.phtml:16
setNestSeparator($separator)
Definition: Ini.php:55
_sortRootElements(Zend_Config $config)
Definition: Ini.php:173
_addBranch(Zend_Config $config, $parents=array())
Definition: Ini.php:124