Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Protected Attributes
Zend_Log_Formatter_Xml Class Reference
Inheritance diagram for Zend_Log_Formatter_Xml:
Zend_Log_Formatter_Abstract Zend_Log_Formatter_Interface Zend_Log_FactoryInterface

Public Member Functions

 __construct ($options=array())
 
 getEncoding ()
 
 setEncoding ($value)
 
 format ($event)
 

Static Public Member Functions

static factory ($options)
 

Protected Attributes

 $_rootElement
 
 $_elementMap
 
 $_encoding
 

Detailed Description

Definition at line 34 of file Xml.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = array())

Class constructor (the default encoding is UTF-8)

Parameters
array | Zend_Config$options
Returns
void

Definition at line 58 of file Xml.php.

59  {
60  if ($options instanceof Zend_Config) {
61  $options = $options->toArray();
62  } elseif (!is_array($options)) {
63  $args = func_get_args();
64 
65  $options = array(
66  'rootElement' => array_shift($args)
67  );
68 
69  if (count($args)) {
70  $options['elementMap'] = array_shift($args);
71  }
72 
73  if (count($args)) {
74  $options['encoding'] = array_shift($args);
75  }
76  }
77 
78  if (!array_key_exists('rootElement', $options)) {
79  $options['rootElement'] = 'logEntry';
80  }
81 
82  if (!array_key_exists('encoding', $options)) {
83  $options['encoding'] = 'UTF-8';
84  }
85 
86  $this->_rootElement = $options['rootElement'];
87  $this->setEncoding($options['encoding']);
88 
89  if (array_key_exists('elementMap', $options)) {
90  $this->_elementMap = $options['elementMap'];
91  }
92  }
setEncoding($value)
Definition: Xml.php:121
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

Member Function Documentation

◆ factory()

static factory (   $options)
static

Factory for Zend_Log_Formatter_Xml classe

Parameters
array | Zend_Config$options
Returns
Zend_Log_Formatter_Xml

Implements Zend_Log_FactoryInterface.

Definition at line 100 of file Xml.php.

101  {
102  return new self($options);
103  }

◆ format()

format (   $event)

Formats data into a single line to be written by the writer.

Parameters
array$eventevent data
Returns
string formatted line to write to the log

Implements Zend_Log_Formatter_Interface.

Definition at line 133 of file Xml.php.

134  {
135  if ($this->_elementMap === null) {
136  $dataToInsert = $event;
137  } else {
138  $dataToInsert = array();
139  foreach ($this->_elementMap as $elementName => $fieldKey) {
140  $dataToInsert[$elementName] = $event[$fieldKey];
141  }
142  }
143 
144  $enc = $this->getEncoding();
145  $dom = new DOMDocument('1.0', $enc);
146  $elt = $dom->appendChild(new DOMElement($this->_rootElement));
147 
148  foreach ($dataToInsert as $key => $value) {
149  if (empty($value)
150  || is_scalar($value)
151  || (is_object($value) && method_exists($value,'__toString'))
152  ) {
153  if($key == "message") {
154  $value = htmlspecialchars($value, ENT_COMPAT, $enc);
155  }
156  $elt->appendChild(new DOMElement($key, (string)$value));
157  }
158  }
159 
160  $xml = $dom->saveXML();
161  $xml = preg_replace('/<\?xml version="1.0"( encoding="[^\"]*")?\?>\n/u', '', $xml);
162 
163  return $xml . PHP_EOL;
164  }
$value
Definition: gender.phtml:16
$elementName
Definition: gallery.phtml:10

◆ getEncoding()

getEncoding ( )

Get encoding

Returns
string

Definition at line 110 of file Xml.php.

111  {
112  return $this->_encoding;
113  }

◆ setEncoding()

setEncoding (   $value)

Set encoding

Parameters
string$value
Returns
Zend_Log_Formatter_Xml

Definition at line 121 of file Xml.php.

122  {
123  $this->_encoding = (string) $value;
124  return $this;
125  }
$value
Definition: gender.phtml:16

Field Documentation

◆ $_elementMap

$_elementMap
protected

Definition at line 44 of file Xml.php.

◆ $_encoding

$_encoding
protected

Definition at line 49 of file Xml.php.

◆ $_rootElement

$_rootElement
protected

Definition at line 39 of file Xml.php.


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