Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Generator Class Reference

Public Member Functions

 __construct ()
 
 getDom ()
 
 arrayToXml ($content)
 
 __toString ()
 
 save ($file)
 
 setIndexedArrayItemName ($name)
 

Data Fields

const DEFAULT_ENTITY_ITEM_NAME = 'item'
 

Protected Member Functions

 _getCurrentDom ()
 
 _setCurrentDom ($node)
 
 _getIndexedArrayItemName ()
 

Protected Attributes

 $_dom = null
 
 $_currentDom
 
 $_defaultIndexedArrayItemName
 

Detailed Description

Definition at line 8 of file Generator.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

Definition at line 33 of file Generator.php.

34  {
35  $this->_dom = new \DOMDocument('1.0');
36  $this->_dom->formatOutput = true;
37  $this->_currentDom = $this->_dom;
38  return $this;
39  }

Member Function Documentation

◆ __toString()

__toString ( )
Returns
string

Definition at line 115 of file Generator.php.

116  {
117  return $this->getDom()->saveXML();
118  }

◆ _getCurrentDom()

_getCurrentDom ( )
protected
Returns
\DOMDocument

Definition at line 52 of file Generator.php.

53  {
54  return $this->_currentDom;
55  }

◆ _getIndexedArrayItemName()

_getIndexedArrayItemName ( )
protected

Get xml node name to use instead of numeric index during numeric arrays conversion.

Returns
string

Definition at line 147 of file Generator.php.

148  {
149  return $this->_defaultIndexedArrayItemName ?? self::DEFAULT_ENTITY_ITEM_NAME;
150  }

◆ _setCurrentDom()

_setCurrentDom (   $node)
protected
Parameters
\DOMDocument$node
Returns
$this

Definition at line 61 of file Generator.php.

62  {
63  $this->_currentDom = $node;
64  return $this;
65  }

◆ arrayToXml()

arrayToXml (   $content)
Parameters
array$content
Returns
$this
Exceptions

Definition at line 73 of file Generator.php.

74  {
75  $parentNode = $this->_getCurrentDom();
76  if (!$content || !count($content)) {
77  return $this;
78  }
79  foreach ($content as $_key => $_item) {
80  $node = $this->getDom()->createElement(preg_replace('/[^\w-]/i', '', $_key));
81  $parentNode->appendChild($node);
82  if (is_array($_item) && isset($_item['_attribute'])) {
83  if (is_array($_item['_value'])) {
84  if (isset($_item['_value'][0])) {
85  foreach ($_item['_value'] as $_v) {
86  $this->_setCurrentDom($node)->arrayToXml($_v);
87  }
88  } else {
89  $this->_setCurrentDom($node)->arrayToXml($_item['_value']);
90  }
91  } else {
92  $child = $this->getDom()->createTextNode($_item['_value']);
93  $node->appendChild($child);
94  }
95  foreach ($_item['_attribute'] as $_attributeKey => $_attributeValue) {
96  $node->setAttribute($_attributeKey, $_attributeValue);
97  }
98  } elseif (is_string($_item)) {
99  $text = $this->getDom()->createTextNode($_item);
100  $node->appendChild($text);
101  } elseif (is_array($_item) && !isset($_item[0])) {
102  $this->_setCurrentDom($node)->arrayToXml($_item);
103  } elseif (is_array($_item) && isset($_item[0])) {
104  foreach ($_item as $v) {
105  $this->_setCurrentDom($node)->arrayToXml([$this->_getIndexedArrayItemName() => $v]);
106  }
107  }
108  }
109  return $this;
110  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
endifif( $block->getLastPageNum()>1)( 'Page') ?></strong >< ul class $text
Definition: pager.phtml:43
$_item
Definition: default.phtml:11

◆ getDom()

getDom ( )
Returns
\DOMDocument|null

Definition at line 44 of file Generator.php.

45  {
46  return $this->_dom;
47  }

◆ save()

save (   $file)
Parameters
string$file
Returns
$this

Definition at line 124 of file Generator.php.

125  {
126  $this->getDom()->save($file);
127  return $this;
128  }

◆ setIndexedArrayItemName()

setIndexedArrayItemName (   $name)

Set xml node name to use instead of numeric index during numeric arrays conversion.

Parameters
string$name
Returns
$this

Definition at line 136 of file Generator.php.

137  {
138  $this->_defaultIndexedArrayItemName = $name;
139  return $this;
140  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

Field Documentation

◆ $_currentDom

$_currentDom
protected

Definition at line 23 of file Generator.php.

◆ $_defaultIndexedArrayItemName

$_defaultIndexedArrayItemName
protected

Definition at line 28 of file Generator.php.

◆ $_dom

$_dom = null
protected

Definition at line 18 of file Generator.php.

◆ DEFAULT_ENTITY_ITEM_NAME

const DEFAULT_ENTITY_ITEM_NAME = 'item'

This value is used to replace numeric keys while formatting data for xml output.

Definition at line 13 of file Generator.php.


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