~chroot64bit/zivios/gentoo-experimental

« back to all changes in this revision

Viewing changes to application/library/Zend/Log/Formatter/Xml.php

  • Committer: Mustafa A. Hashmi
  • Date: 2008-12-04 13:32:21 UTC
  • Revision ID: mhashmi@zivios.org-20081204133221-0nd1trunwevijj38
Inclusion of new installation framework with ties to zend layout and dojo layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Zend Framework
 
4
 *
 
5
 * LICENSE
 
6
 *
 
7
 * This source file is subject to the new BSD license that is bundled
 
8
 * with this package in the file LICENSE.txt.
 
9
 * It is also available through the world-wide-web at this URL:
 
10
 * http://framework.zend.com/license/new-bsd
 
11
 * If you did not receive a copy of the license and are unable to
 
12
 * obtain it through the world-wide-web, please send an email
 
13
 * to license@zend.com so we can send you a copy immediately.
 
14
 *
 
15
 * @category   Zend
 
16
 * @package    Zend_Log
 
17
 * @subpackage Formatter
 
18
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
19
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
20
 * @version    $Id: Xml.php 12363 2008-11-07 10:45:22Z beberlei $
 
21
 */
 
22
 
 
23
/** Zend_Log_Formatter_Interface */
 
24
require_once 'Zend/Log/Formatter/Interface.php';
 
25
 
 
26
/**
 
27
 * @category   Zend
 
28
 * @package    Zend_Log
 
29
 * @subpackage Formatter
 
30
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
31
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
32
 * @version    $Id: Xml.php 12363 2008-11-07 10:45:22Z beberlei $
 
33
 */
 
34
class Zend_Log_Formatter_Xml implements Zend_Log_Formatter_Interface
 
35
{
 
36
    /**
 
37
     * @var Relates XML elements to log data field keys.
 
38
     */
 
39
    protected $_rootElement;
 
40
 
 
41
    /**
 
42
     * @var Relates XML elements to log data field keys.
 
43
     */
 
44
    protected $_elementMap;
 
45
 
 
46
    /**
 
47
     * Class constructor
 
48
     *
 
49
     * @param array $elementMap
 
50
     */
 
51
    public function __construct($rootElement = 'logEntry', $elementMap = null)
 
52
    {
 
53
        $this->_rootElement = $rootElement;
 
54
        $this->_elementMap  = $elementMap;
 
55
    }
 
56
 
 
57
    /**
 
58
     * Formats data into a single line to be written by the writer.
 
59
     *
 
60
     * @param  array    $event    event data
 
61
     * @return string             formatted line to write to the log
 
62
     */
 
63
    public function format($event)
 
64
    {
 
65
        if ($this->_elementMap === null) {
 
66
            $dataToInsert = $event;
 
67
        } else {
 
68
            $dataToInsert = array();
 
69
            foreach ($this->_elementMap as $elementName => $fieldKey) {
 
70
                $dataToInsert[$elementName] = $event[$fieldKey];
 
71
            }
 
72
        }
 
73
 
 
74
        $dom = new DOMDocument();
 
75
        $elt = $dom->appendChild(new DOMElement($this->_rootElement));
 
76
 
 
77
        foreach ($dataToInsert as $key => $value) {
 
78
            if($key == "message") {
 
79
                $value = htmlspecialchars($value);
 
80
            }
 
81
            $elt->appendChild(new DOMElement($key, $value));
 
82
        }
 
83
 
 
84
        $xml = $dom->saveXML();
 
85
        $xml = preg_replace('/<\?xml version="1.0"( encoding="[^\"]*")?\?>\n/u', '', $xml);
 
86
 
 
87
        return $xml . PHP_EOL;
 
88
    }
 
89
 
 
90
}