• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Zend/Log/Formatter/Xml.php

00001 <?php
00024 require_once 'Zend/Log/Formatter/Interface.php';
00025 
00034 class Zend_Log_Formatter_Xml implements Zend_Log_Formatter_Interface
00035 {
00039     protected $_rootElement;
00040 
00044     protected $_elementMap;
00045 
00049     protected $_encoding;
00050 
00058     public function __construct($rootElement = 'logEntry', $elementMap = null, $encoding = 'UTF-8')
00059     {
00060         $this->_rootElement = $rootElement;
00061         $this->_elementMap  = $elementMap;
00062         $this->setEncoding($encoding);
00063     }
00064 
00070     public function getEncoding()
00071     {
00072         return $this->_encoding;
00073     }
00074 
00081     public function setEncoding($value)
00082     {
00083         $this->_encoding = (string) $value;
00084         return $this;
00085     }
00086 
00093     public function format($event)
00094     {
00095         if ($this->_elementMap === null) {
00096             $dataToInsert = $event;
00097         } else {
00098             $dataToInsert = array();
00099             foreach ($this->_elementMap as $elementName => $fieldKey) {
00100                 $dataToInsert[$elementName] = $event[$fieldKey];
00101             }
00102         }
00103 
00104         $enc = $this->getEncoding();
00105         $dom = new DOMDocument('1.0', $enc);
00106         $elt = $dom->appendChild(new DOMElement($this->_rootElement));
00107 
00108         foreach ($dataToInsert as $key => $value) {
00109             if($key == "message") {
00110                 $value = htmlspecialchars($value, ENT_COMPAT, $enc);
00111             }
00112             $elt->appendChild(new DOMElement($key, $value));
00113         }
00114 
00115         $xml = $dom->saveXML();
00116         $xml = preg_replace('/<\?xml version="1.0"( encoding="[^\"]*")?\?>\n/u', '', $xml);
00117 
00118         return $xml . PHP_EOL;
00119     }
00120 
00121 }

Generated on Thu Apr 19 2012 17:01:17 for openbiz by  doxygen 1.7.2