Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Zend_Config_Ini Class Reference
Inheritance diagram for Zend_Config_Ini:
Zend_Config

Public Member Functions

 __construct ($filename, $section=null, $options=false)
 
- Public Member Functions inherited from Zend_Config
 __construct (array $array, $allowModifications=false)
 
 get ($name, $default=null)
 
 __get ($name)
 
 __set ($name, $value)
 
 __clone ()
 
 toArray ()
 
 __isset ($name)
 
 __unset ($name)
 
 count ()
 
 current ()
 
 key ()
 
 next ()
 
 rewind ()
 
 valid ()
 
 getSectionName ()
 
 areAllSectionsLoaded ()
 
 merge (Zend_Config $merge)
 
 setReadOnly ()
 
 readOnly ()
 
 getExtends ()
 
 setExtend ($extendingSection, $extendedSection=null)
 
 _loadFileErrorHandler ($errno, $errstr, $errfile, $errline)
 

Protected Member Functions

 _parseIniFile ($filename)
 
 _loadIniFile ($filename)
 
 _processSection ($iniArray, $section, $config=array())
 
 _processKey ($config, $key, $value)
 
- Protected Member Functions inherited from Zend_Config
 _assertValidExtend ($extendingSection, $extendedSection)
 
 _arrayMergeRecursive ($firstArray, $secondArray)
 

Protected Attributes

 $_nestSeparator = '.'
 
 $_sectionSeparator = ':'
 
 $_skipExtends = false
 
- Protected Attributes inherited from Zend_Config
 $_allowModifications
 
 $_index
 
 $_count
 
 $_data
 
 $_skipNextIteration
 
 $_loadedSection
 
 $_extends = array()
 
 $_loadFileErrorStr = null
 

Detailed Description

Definition at line 35 of file Ini.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $filename,
  $section = null,
  $options = false 
)

Loads the section $section from the config file $filename for access facilitated by nested object properties.

If the section name contains a ":" then the section name to the right is loaded and included into the properties. Note that the keys in this $section will override any keys of the same name in the sections that have been included via ":".

If the $section is null, then all sections in the ini file are loaded.

If any key includes a ".", then this will act as a separator to create a sub-property.

example ini file: [all] db.connection = database hostname = live

[staging : all] hostname = staging

after calling $data = new Zend_Config_Ini($file, 'staging'); then $data->hostname === "staging" $data->db->connection === "database"

The $options parameter may be provided as either a boolean or an array. If provided as a boolean, this sets the $allowModifications option of Zend_Config. If provided as an array, there are three configuration directives that may be set. For example:

$options = array( 'allowModifications' => false, 'nestSeparator' => ':', 'skipExtends' => false, );

Parameters
string$filename
mixed$section
boolean | array$options
Exceptions
Zend_Config_Exception
Returns
void
See also
Zend_Config_Exception
Zend_Config_Exception

Definition at line 101 of file Ini.php.

102  {
103  if (empty($filename)) {
107  #require_once 'Zend/Config/Exception.php';
108  throw new Zend_Config_Exception('Filename is not set');
109  }
110 
111  $allowModifications = false;
112  if (is_bool($options)) {
113  $allowModifications = $options;
114  } elseif (is_array($options)) {
115  if (isset($options['allowModifications'])) {
116  $allowModifications = (bool) $options['allowModifications'];
117  }
118  if (isset($options['nestSeparator'])) {
119  $this->_nestSeparator = (string) $options['nestSeparator'];
120  }
121  if (isset($options['skipExtends'])) {
122  $this->_skipExtends = (bool) $options['skipExtends'];
123  }
124  }
125 
126  $iniArray = $this->_loadIniFile($filename);
127 
128  if (null === $section) {
129  // Load entire file
130  $dataArray = array();
131  foreach ($iniArray as $sectionName => $sectionData) {
132  if(!is_array($sectionData)) {
133  $dataArray = $this->_arrayMergeRecursive($dataArray, $this->_processKey(array(), $sectionName, $sectionData));
134  } else {
135  $dataArray[$sectionName] = $this->_processSection($iniArray, $sectionName);
136  }
137  }
138  parent::__construct($dataArray, $allowModifications);
139  } else {
140  // Load one or more sections
141  if (!is_array($section)) {
142  $section = array($section);
143  }
144  $dataArray = array();
145  foreach ($section as $sectionName) {
146  if (!isset($iniArray[$sectionName])) {
150  #require_once 'Zend/Config/Exception.php';
151  throw new Zend_Config_Exception("Section '$sectionName' cannot be found in $filename");
152  }
153  $dataArray = $this->_arrayMergeRecursive($this->_processSection($iniArray, $sectionName), $dataArray);
154 
155  }
156  parent::__construct($dataArray, $allowModifications);
157  }
158 
159  $this->_loadedSection = $section;
160  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
_loadIniFile($filename)
Definition: Ini.php:200
_processSection($iniArray, $section, $config=array())
Definition: Ini.php:241
_processKey($config, $key, $value)
Definition: Ini.php:277
_arrayMergeRecursive($firstArray, $secondArray)
Definition: Config.php:464

Member Function Documentation

◆ _loadIniFile()

_loadIniFile (   $filename)
protected

Load the ini file and preprocess the section separator (':' in the section name (that is used for section extension) so that the resultant array has the correct section names and the extension information is stored in a sub-key called ';extends'. We use ';extends' as this can never be a valid key name in an INI file that has been loaded using parse_ini_file().

Parameters
string$filename
Exceptions
Zend_Config_Exception
Returns
array
See also
Zend_Config_Exception

Definition at line 200 of file Ini.php.

201  {
202  $loaded = $this->_parseIniFile($filename);
203  $iniArray = array();
204  foreach ($loaded as $key => $data)
205  {
206  $pieces = explode($this->_sectionSeparator, $key);
207  $thisSection = trim($pieces[0]);
208  switch (count($pieces)) {
209  case 1:
210  $iniArray[$thisSection] = $data;
211  break;
212 
213  case 2:
214  $extendedSection = trim($pieces[1]);
215  $iniArray[$thisSection] = array_merge(array(';extends'=>$extendedSection), $data);
216  break;
217 
218  default:
222  #require_once 'Zend/Config/Exception.php';
223  throw new Zend_Config_Exception("Section '$thisSection' may not extend multiple sections in $filename");
224  }
225  }
226 
227  return $iniArray;
228  }
_parseIniFile($filename)
Definition: Ini.php:170

◆ _parseIniFile()

_parseIniFile (   $filename)
protected

Load the INI file from disk using parse_ini_file(). Use a private error handler to convert any loading errors into a Zend_Config_Exception

Parameters
string$filename
Exceptions
Zend_Config_Exception
Returns
array
See also
Zend_Config_Exception

Definition at line 170 of file Ini.php.

171  {
172  set_error_handler(array($this, '_loadFileErrorHandler'));
173  $iniArray = parse_ini_file($filename, true); // Warnings and errors are suppressed
174  restore_error_handler();
175 
176  // Check if there was a error while loading file
177  if ($this->_loadFileErrorStr !== null) {
181  #require_once 'Zend/Config/Exception.php';
182  throw new Zend_Config_Exception($this->_loadFileErrorStr);
183  }
184 
185  return $iniArray;
186  }

◆ _processKey()

_processKey (   $config,
  $key,
  $value 
)
protected

Assign the key's value to the property list. Handles the nest separator for sub-properties.

Parameters
array$config
string$key
string$value
Exceptions
Zend_Config_Exception
Returns
array
See also
Zend_Config_Exception
Zend_Config_Exception

Definition at line 277 of file Ini.php.

278  {
279  if (strpos($key, $this->_nestSeparator) !== false) {
280  $pieces = explode($this->_nestSeparator, $key, 2);
281  if (strlen($pieces[0]) && strlen($pieces[1])) {
282  if (!isset($config[$pieces[0]])) {
283  if ($pieces[0] === '0' && !empty($config)) {
284  // convert the current values in $config into an array
285  $config = array($pieces[0] => $config);
286  } else {
287  $config[$pieces[0]] = array();
288  }
289  } elseif (!is_array($config[$pieces[0]])) {
293  #require_once 'Zend/Config/Exception.php';
294  throw new Zend_Config_Exception("Cannot create sub-key for '{$pieces[0]}' as key already exists");
295  }
296  $config[$pieces[0]] = $this->_processKey($config[$pieces[0]], $pieces[1], $value);
297  } else {
301  #require_once 'Zend/Config/Exception.php';
302  throw new Zend_Config_Exception("Invalid key '$key'");
303  }
304  } else {
305  $config[$key] = $value;
306  }
307  return $config;
308  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$config
Definition: fraud_order.php:17
$value
Definition: gender.phtml:16
_processKey($config, $key, $value)
Definition: Ini.php:277

◆ _processSection()

_processSection (   $iniArray,
  $section,
  $config = array() 
)
protected

Process each element in the section and handle the ";extends" inheritance key. Passes control to _processKey() to handle the nest separator sub-property syntax that may be used within the key name.

Parameters
array$iniArray
string$section
array$config
Exceptions
Zend_Config_Exception
Returns
array
See also
Zend_Config_Exception

Definition at line 241 of file Ini.php.

242  {
243  $thisSection = $iniArray[$section];
244 
245  foreach ($thisSection as $key => $value) {
246  if (strtolower($key) == ';extends') {
247  if (isset($iniArray[$value])) {
248  $this->_assertValidExtend($section, $value);
249 
250  if (!$this->_skipExtends) {
251  $config = $this->_processSection($iniArray, $value, $config);
252  }
253  } else {
257  #require_once 'Zend/Config/Exception.php';
258  throw new Zend_Config_Exception("Parent section '$section' cannot be found");
259  }
260  } else {
261  $config = $this->_processKey($config, $key, $value);
262  }
263  }
264  return $config;
265  }
$config
Definition: fraud_order.php:17
$value
Definition: gender.phtml:16
_processSection($iniArray, $section, $config=array())
Definition: Ini.php:241
_processKey($config, $key, $value)
Definition: Ini.php:277
_assertValidExtend($extendingSection, $extendedSection)
Definition: Config.php:423

Field Documentation

◆ $_nestSeparator

$_nestSeparator = '.'
protected

Definition at line 42 of file Ini.php.

◆ $_sectionSeparator

$_sectionSeparator = ':'
protected

Definition at line 49 of file Ini.php.

◆ $_skipExtends

$_skipExtends = false
protected

Definition at line 56 of file Ini.php.


The documentation for this class was generated from the following file: