web/lib/Zend/Log/Formatter/Xml.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
--- a/web/lib/Zend/Log/Formatter/Xml.php	Thu Mar 21 17:31:31 2013 +0100
+++ b/web/lib/Zend/Log/Formatter/Xml.php	Thu Mar 21 19:50:53 2013 +0100
@@ -15,31 +15,31 @@
  * @category   Zend
  * @package    Zend_Log
  * @subpackage Formatter
- * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
- * @version    $Id: Xml.php 20104 2010-01-06 21:26:01Z matthew $
+ * @version    $Id: Xml.php 24593 2012-01-05 20:35:02Z matthew $
  */
 
-/** Zend_Log_Formatter_Interface */
-require_once 'Zend/Log/Formatter/Interface.php';
+/** Zend_Log_Formatter_Abstract */
+require_once 'Zend/Log/Formatter/Abstract.php';
 
 /**
  * @category   Zend
  * @package    Zend_Log
  * @subpackage Formatter
- * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
- * @version    $Id: Xml.php 20104 2010-01-06 21:26:01Z matthew $
+ * @version    $Id: Xml.php 24593 2012-01-05 20:35:02Z matthew $
  */
-class Zend_Log_Formatter_Xml implements Zend_Log_Formatter_Interface
+class Zend_Log_Formatter_Xml extends Zend_Log_Formatter_Abstract
 {
     /**
-     * @var Relates XML elements to log data field keys.
+     * @var string Name of root element
      */
     protected $_rootElement;
 
     /**
-     * @var Relates XML elements to log data field keys.
+     * @var array Relates XML elements to log data field keys.
      */
     protected $_elementMap;
 
@@ -50,16 +50,56 @@
 
     /**
      * Class constructor
+     * (the default encoding is UTF-8)
      *
-     * @param string $rootElement Name of root element
-     * @param array $elementMap
-     * @param string $encoding Encoding to use (defaults to UTF-8)
+     * @param array|Zend_Config $options
+     * @return void
      */
-    public function __construct($rootElement = 'logEntry', $elementMap = null, $encoding = 'UTF-8')
+    public function __construct($options = array())
     {
-        $this->_rootElement = $rootElement;
-        $this->_elementMap  = $elementMap;
-        $this->setEncoding($encoding);
+        if ($options instanceof Zend_Config) {
+            $options = $options->toArray();
+        } elseif (!is_array($options)) {
+            $args = func_get_args();
+
+            $options = array(
+            	'rootElement' => array_shift($args)
+            );
+
+            if (count($args)) {
+                $options['elementMap'] = array_shift($args);
+            }
+
+            if (count($args)) {
+                $options['encoding'] = array_shift($args);
+            }
+        }
+
+        if (!array_key_exists('rootElement', $options)) {
+            $options['rootElement'] = 'logEntry';
+        }
+
+        if (!array_key_exists('encoding', $options)) {
+            $options['encoding'] = 'UTF-8';
+        }
+
+        $this->_rootElement = $options['rootElement'];
+        $this->setEncoding($options['encoding']);
+
+        if (array_key_exists('elementMap', $options)) {
+            $this->_elementMap  = $options['elementMap'];
+        }
+    }
+
+    /**
+	 * Factory for Zend_Log_Formatter_Xml classe
+	 *
+	 * @param array|Zend_Config $options
+	 * @return Zend_Log_Formatter_Xml
+     */
+    public static function factory($options)
+    {
+        return new self($options);
     }
 
     /**
@@ -106,10 +146,15 @@
         $elt = $dom->appendChild(new DOMElement($this->_rootElement));
 
         foreach ($dataToInsert as $key => $value) {
-            if($key == "message") {
-                $value = htmlspecialchars($value, ENT_COMPAT, $enc);
+            if (empty($value) 
+                || is_scalar($value) 
+                || (is_object($value) && method_exists($value,'__toString'))
+            ) {
+                if($key == "message") {
+                    $value = htmlspecialchars($value, ENT_COMPAT, $enc);
+                }
+                $elt->appendChild(new DOMElement($key, (string)$value));
             }
-            $elt->appendChild(new DOMElement($key, $value));
         }
 
         $xml = $dom->saveXML();
@@ -117,5 +162,4 @@
 
         return $xml . PHP_EOL;
     }
-
 }