Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions
Zend_Config_Writer_Xml Class Reference
Inheritance diagram for Zend_Config_Writer_Xml:
Zend_Config_Writer_FileAbstract Zend_Config_Writer

Public Member Functions

 render ()
 
- Public Member Functions inherited from Zend_Config_Writer_FileAbstract
 setFilename ($filename)
 
 setExclusiveLock ($exclusiveLock)
 
 write ($filename=null, Zend_Config $config=null, $exclusiveLock=null)
 
 render ()
 
- Public Member Functions inherited from Zend_Config_Writer
 __construct (array $options=null)
 
 setConfig (Zend_Config $config)
 
 setOptions (array $options)
 
 write ()
 

Protected Member Functions

 _addBranch (Zend_Config $config, SimpleXMLElement $xml, SimpleXMLElement $parent)
 

Additional Inherited Members

- Protected Attributes inherited from Zend_Config_Writer_FileAbstract
 $_filename = null
 
 $_exclusiveLock = false
 
- Protected Attributes inherited from Zend_Config_Writer
 $_skipOptions
 
 $_config = null
 

Detailed Description

Definition at line 38 of file Xml.php.

Member Function Documentation

◆ _addBranch()

_addBranch ( Zend_Config  $config,
SimpleXMLElement  $xml,
SimpleXMLElement  $parent 
)
protected

Add a branch to an XML object recursively

Parameters
Zend_Config$config
SimpleXMLElement$xml
SimpleXMLElement$parent
Returns
void

Definition at line 88 of file Xml.php.

89  {
90  $branchType = null;
91 
92  foreach ($config as $key => $value) {
93  if ($branchType === null) {
94  if (is_numeric($key)) {
95  $branchType = 'numeric';
96  $branchName = $xml->getName();
97  $xml = $parent;
98 
99  unset($parent->{$branchName});
100  } else {
101  $branchType = 'string';
102  }
103  } else if ($branchType !== (is_numeric($key) ? 'numeric' : 'string')) {
104  #require_once 'Zend/Config/Exception.php';
105  throw new Zend_Config_Exception('Mixing of string and numeric keys is not allowed');
106  }
107 
108  if ($branchType === 'numeric') {
109  if ($value instanceof Zend_Config) {
110  $child = $parent->addChild($branchName);
111 
112  $this->_addBranch($value, $child, $parent);
113  } else {
114  $parent->addChild($branchName, (string) $value);
115  }
116  } else {
117  if ($value instanceof Zend_Config) {
118  $child = $xml->addChild($key);
119 
120  $this->_addBranch($value, $child, $xml);
121  } else {
122  $xml->addChild($key, (string) $value);
123  }
124  }
125  }
126  }
$config
Definition: fraud_order.php:17
$value
Definition: gender.phtml:16
_addBranch(Zend_Config $config, SimpleXMLElement $xml, SimpleXMLElement $parent)
Definition: Xml.php:88

◆ render()

render ( )

Render a Zend_Config into a XML config string.

Since
1.10
Returns
string

Definition at line 46 of file Xml.php.

47  {
48  $xml = new SimpleXMLElement('<zend-config xmlns:zf="' . Zend_Config_Xml::XML_NAMESPACE . '"/>');
49  $extends = $this->_config->getExtends();
50  $sectionName = $this->_config->getSectionName();
51 
52  if (is_string($sectionName)) {
53  $child = $xml->addChild($sectionName);
54 
55  $this->_addBranch($this->_config, $child, $xml);
56  } else {
57  foreach ($this->_config as $sectionName => $data) {
58  if (!($data instanceof Zend_Config)) {
59  $xml->addChild($sectionName, (string) $data);
60  } else {
61  $child = $xml->addChild($sectionName);
62 
63  if (isset($extends[$sectionName])) {
64  $child->addAttribute('zf:extends', $extends[$sectionName], Zend_Config_Xml::XML_NAMESPACE);
65  }
66 
67  $this->_addBranch($data, $child, $xml);
68  }
69  }
70  }
71 
72  $dom = dom_import_simplexml($xml)->ownerDocument;
73  $dom->formatOutput = true;
74 
75  $xmlString = $dom->saveXML();
76 
77  return $xmlString;
78  }
const XML_NAMESPACE
Definition: Xml.php:46
_addBranch(Zend_Config $config, SimpleXMLElement $xml, SimpleXMLElement $parent)
Definition: Xml.php:88

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