13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Log |
16 * @package Zend_Log |
17 * @subpackage Writer |
17 * @subpackage Writer |
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id: Db.php 22513 2010-07-01 13:48:39Z ramon $ |
20 * @version $Id: Db.php 25247 2013-02-01 17:49:40Z frosch $ |
21 */ |
21 */ |
22 |
22 |
23 /** Zend_Log_Writer_Abstract */ |
23 /** Zend_Log_Writer_Abstract */ |
24 require_once 'Zend/Log/Writer/Abstract.php'; |
24 require_once 'Zend/Log/Writer/Abstract.php'; |
25 |
25 |
26 /** |
26 /** |
27 * @category Zend |
27 * @category Zend |
28 * @package Zend_Log |
28 * @package Zend_Log |
29 * @subpackage Writer |
29 * @subpackage Writer |
30 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
30 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
31 * @license http://framework.zend.com/license/new-bsd New BSD License |
31 * @license http://framework.zend.com/license/new-bsd New BSD License |
32 * @version $Id: Db.php 22513 2010-07-01 13:48:39Z ramon $ |
32 * @version $Id: Db.php 25247 2013-02-01 17:49:40Z frosch $ |
33 */ |
33 */ |
34 class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract |
34 class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract |
35 { |
35 { |
36 /** |
36 /** |
37 * Database adapter instance |
37 * Database adapter instance |
|
38 * |
38 * @var Zend_Db_Adapter |
39 * @var Zend_Db_Adapter |
39 */ |
40 */ |
40 private $_db; |
41 protected $_db; |
41 |
42 |
42 /** |
43 /** |
43 * Name of the log table in the database |
44 * Name of the log table in the database |
|
45 * |
44 * @var string |
46 * @var string |
45 */ |
47 */ |
46 private $_table; |
48 protected $_table; |
47 |
49 |
48 /** |
50 /** |
49 * Relates database columns names to log data field keys. |
51 * Relates database columns names to log data field keys. |
50 * |
52 * |
51 * @var null|array |
53 * @var null|array |
52 */ |
54 */ |
53 private $_columnMap; |
55 protected $_columnMap; |
54 |
56 |
55 /** |
57 /** |
56 * Class constructor |
58 * Class constructor |
57 * |
59 * |
58 * @param Zend_Db_Adapter $db Database adapter instance |
60 * @param Zend_Db_Adapter $db Database adapter instance |
59 * @param string $table Log table in database |
61 * @param string $table Log table in database |
60 * @param array $columnMap |
62 * @param array $columnMap |
|
63 * @return void |
61 */ |
64 */ |
62 public function __construct($db, $table, $columnMap = null) |
65 public function __construct($db, $table, $columnMap = null) |
63 { |
66 { |
64 $this->_db = $db; |
67 $this->_db = $db; |
65 $this->_table = $table; |
68 $this->_table = $table; |
69 /** |
72 /** |
70 * Create a new instance of Zend_Log_Writer_Db |
73 * Create a new instance of Zend_Log_Writer_Db |
71 * |
74 * |
72 * @param array|Zend_Config $config |
75 * @param array|Zend_Config $config |
73 * @return Zend_Log_Writer_Db |
76 * @return Zend_Log_Writer_Db |
74 * @throws Zend_Log_Exception |
|
75 */ |
77 */ |
76 static public function factory($config) |
78 static public function factory($config) |
77 { |
79 { |
78 $config = self::_parseConfig($config); |
80 $config = self::_parseConfig($config); |
79 $config = array_merge(array( |
81 $config = array_merge(array( |
93 ); |
95 ); |
94 } |
96 } |
95 |
97 |
96 /** |
98 /** |
97 * Formatting is not possible on this writer |
99 * Formatting is not possible on this writer |
|
100 * |
|
101 * @return void |
|
102 * @throws Zend_Log_Exception |
98 */ |
103 */ |
99 public function setFormatter(Zend_Log_Formatter_Interface $formatter) |
104 public function setFormatter(Zend_Log_Formatter_Interface $formatter) |
100 { |
105 { |
101 require_once 'Zend/Log/Exception.php'; |
106 require_once 'Zend/Log/Exception.php'; |
102 throw new Zend_Log_Exception(get_class($this) . ' does not support formatting'); |
107 throw new Zend_Log_Exception(get_class($this) . ' does not support formatting'); |
115 /** |
120 /** |
116 * Write a message to the log. |
121 * Write a message to the log. |
117 * |
122 * |
118 * @param array $event event data |
123 * @param array $event event data |
119 * @return void |
124 * @return void |
|
125 * @throws Zend_Log_Exception |
120 */ |
126 */ |
121 protected function _write($event) |
127 protected function _write($event) |
122 { |
128 { |
123 if ($this->_db === null) { |
129 if ($this->_db === null) { |
124 require_once 'Zend/Log/Exception.php'; |
130 require_once 'Zend/Log/Exception.php'; |
128 if ($this->_columnMap === null) { |
134 if ($this->_columnMap === null) { |
129 $dataToInsert = $event; |
135 $dataToInsert = $event; |
130 } else { |
136 } else { |
131 $dataToInsert = array(); |
137 $dataToInsert = array(); |
132 foreach ($this->_columnMap as $columnName => $fieldKey) { |
138 foreach ($this->_columnMap as $columnName => $fieldKey) { |
133 $dataToInsert[$columnName] = $event[$fieldKey]; |
139 if (isset($event[$fieldKey])) { |
|
140 $dataToInsert[$columnName] = $event[$fieldKey]; |
|
141 } |
134 } |
142 } |
135 } |
143 } |
136 |
144 |
137 $this->_db->insert($this->_table, $dataToInsert); |
145 $this->_db->insert($this->_table, $dataToInsert); |
138 } |
146 } |