Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Config Class Reference
Inheritance diagram for Config:
Base Layout Ordered Proxy Page Layout Collector Base Config Config

Public Member Functions

 __construct ($sourceData=null)
 
 setXml (Element $node)
 
 getNode ($path=null)
 
 getXpath ($xpath)
 
 getXmlString ()
 
 loadFile ($filePath)
 
 loadString ($string)
 
 loadDom (\DOMNode $dom)
 
 setNode ($path, $value, $overwrite=true)
 
 applyExtends ()
 
 processFileData ($text)
 
 extend (Config $config, $overwrite=true)
 
 __destruct ()
 

Protected Member Functions

 getXml ()
 

Protected Attributes

 $_xml = null
 
 $_elementClass = \Magento\Framework\Simplexml\Element::class
 
 $_xpathExtends = "//*[@extends]"
 

Detailed Description

Base class for simplexml based configurations

@api

Since
100.0.2

Definition at line 14 of file Config.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $sourceData = null)

Constructor

Initializes XML for this configuration

See also
\Magento\Framework\Simplexml\Config::setXml
Parameters
Element | string$sourceData

Definition at line 45 of file Config.php.

46  {
47  if ($sourceData === null) {
48  return;
49  }
50  if ($sourceData instanceof Element) {
51  $this->setXml($sourceData);
52  } elseif (is_string($sourceData) && !empty($sourceData)) {
53  if (strlen($sourceData) < 1000 && is_readable($sourceData)) {
54  $this->loadFile($sourceData);
55  } else {
56  $this->loadString($sourceData);
57  }
58  }
59  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ __destruct()

__destruct ( )

Cleanup circular references

Destructor should be called explicitly in order to work around the PHP bug https://bugs.php.net/bug.php?id=62468

Returns
void

Definition at line 242 of file Config.php.

243  {
244  $this->_xml = null;
245  }

Member Function Documentation

◆ applyExtends()

applyExtends ( )

Process configuration xml

Returns
$this

Definition at line 193 of file Config.php.

194  {
195  $targets = $this->getXpath($this->_xpathExtends);
196  if (!$targets) {
197  return $this;
198  }
199  foreach ($targets as $target) {
200  $sources = $this->getXpath((string)$target['extends']);
201  if ($sources) {
202  foreach ($sources as $source) {
203  $target->extend($source);
204  }
205  }
206  }
207  return $this;
208  }
$source
Definition: source.php:23
$target
Definition: skip.phtml:8

◆ extend()

extend ( Config  $config,
  $overwrite = true 
)

Enter description here...

Parameters
Config$config
boolean$overwrite
Returns
$this

Definition at line 228 of file Config.php.

229  {
230  $this->getNode()->extend($config->getNode(), $overwrite);
231  return $this;
232  }
$config
Definition: fraud_order.php:17

◆ getNode()

getNode (   $path = null)

Returns node found by the $path

See also
\Magento\Framework\Simplexml\Element::descend
Parameters
string$path
Returns
Element|bool

Definition at line 80 of file Config.php.

81  {
82  if (!$this->getXml() instanceof Element) {
83  return false;
84  } elseif ($path === null) {
85  return $this->getXml();
86  } else {
87  return $this->getXml()->descend($path);
88  }
89  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ getXml()

getXml ( )
protected

Getter for xml element

Returns
Element

Definition at line 252 of file Config.php.

253  {
254  return $this->_xml;
255  }

◆ getXmlString()

getXmlString ( )

Return Xml of node as string

Returns
string

Definition at line 116 of file Config.php.

117  {
118  return $this->getNode()->asNiceXml('', false);
119  }

◆ getXpath()

getXpath (   $xpath)

Returns nodes found by xpath expression

Parameters
string$xpath
Returns
Element[]|bool

Definition at line 97 of file Config.php.

98  {
99  $xml = $this->getXml();
100  if (empty($xml)) {
101  return false;
102  }
103 
104  if (!($result = @$xml->xpath($xpath))) {
105  return false;
106  }
107 
108  return $result;
109  }

◆ loadDom()

loadDom ( \DOMNode  $dom)

Imports DOM node

Parameters
\DOMNode$dom
Returns
bool

Definition at line 163 of file Config.php.

164  {
165  $xml = simplexml_import_dom($dom, $this->_elementClass);
166  if ($xml) {
167  $this->setXml($xml);
168  return true;
169  }
170 
171  return false;
172  }

◆ loadFile()

loadFile (   $filePath)

Imports XML file

Parameters
string$filePath
Returns
boolean

Definition at line 127 of file Config.php.

128  {
129  if (!is_readable($filePath)) {
130  //throw new \Exception('Can not read xml file '.$filePath);
131  return false;
132  }
133 
134  $fileData = file_get_contents($filePath);
135  $fileData = $this->processFileData($fileData);
136  return $this->loadString($fileData);
137  }

◆ loadString()

loadString (   $string)

Imports XML string

Parameters
string$string
Returns
boolean

Definition at line 145 of file Config.php.

146  {
147  if (!empty($string)) {
148  $xml = simplexml_load_string($string, $this->_elementClass);
149  if ($xml) {
150  $this->setXml($xml);
151  return true;
152  }
153  }
154  return false;
155  }

◆ processFileData()

processFileData (   $text)

Stub method for processing file data right after loading the file text

Parameters
string$text
Returns
string

Definition at line 216 of file Config.php.

217  {
218  return $text;
219  }
endifif( $block->getLastPageNum()>1)( 'Page') ?></strong >< ul class $text
Definition: pager.phtml:43

◆ setNode()

setNode (   $path,
  $value,
  $overwrite = true 
)

Create node by $path and set its value.

Parameters
string$pathseparated by slashes
string$value
boolean$overwrite
Returns
$this

Definition at line 182 of file Config.php.

183  {
184  $this->getXml()->setNode($path, $value, $overwrite);
185  return $this;
186  }
$value
Definition: gender.phtml:16

◆ setXml()

setXml ( Element  $node)

Sets xml for this configuration

Parameters
Element$node
Returns
$this

Definition at line 67 of file Config.php.

68  {
69  $this->_xml = $node;
70  return $this;
71  }

Field Documentation

◆ $_elementClass

$_elementClass = \Magento\Framework\Simplexml\Element::class
protected

Definition at line 28 of file Config.php.

◆ $_xml

$_xml = null
protected

Definition at line 21 of file Config.php.

◆ $_xpathExtends

$_xpathExtends = "//*[@extends]"
protected

Definition at line 35 of file Config.php.


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