File indexing completed on 2024-12-22 05:36:50
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Log 0017 * @subpackage Writer 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** Zend_Log_Filter_Priority */ 0024 // require_once 'Zend/Log/Filter/Priority.php'; 0025 0026 /** 0027 * @category Zend 0028 * @package Zend_Log 0029 * @subpackage Writer 0030 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0031 * @license http://framework.zend.com/license/new-bsd New BSD License 0032 * @version $Id$ 0033 */ 0034 abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface 0035 { 0036 /** 0037 * @var array of Zend_Log_Filter_Interface 0038 */ 0039 protected $_filters = array(); 0040 0041 /** 0042 * Formats the log message before writing. 0043 * 0044 * @var Zend_Log_Formatter_Interface 0045 */ 0046 protected $_formatter; 0047 0048 /** 0049 * Add a filter specific to this writer. 0050 * 0051 * @param Zend_Log_Filter_Interface|int $filter Filter class or filter 0052 * priority 0053 * @return Zend_Log_Writer_Abstract 0054 * @throws Zend_Log_Exception 0055 */ 0056 public function addFilter($filter) 0057 { 0058 if (is_int($filter)) { 0059 $filter = new Zend_Log_Filter_Priority($filter); 0060 } 0061 0062 if (!$filter instanceof Zend_Log_Filter_Interface) { 0063 /** @see Zend_Log_Exception */ 0064 // require_once 'Zend/Log/Exception.php'; 0065 throw new Zend_Log_Exception('Invalid filter provided'); 0066 } 0067 0068 $this->_filters[] = $filter; 0069 return $this; 0070 } 0071 0072 /** 0073 * Log a message to this writer. 0074 * 0075 * @param array $event log data event 0076 * @return void 0077 */ 0078 public function write($event) 0079 { 0080 /** @var Zend_Log_Filter_Interface $filter */ 0081 foreach ($this->_filters as $filter) { 0082 if (!$filter->accept($event)) { 0083 return; 0084 } 0085 } 0086 0087 // exception occurs on error 0088 $this->_write($event); 0089 } 0090 0091 /** 0092 * Set a new formatter for this writer 0093 * 0094 * @param Zend_Log_Formatter_Interface $formatter 0095 * @return Zend_Log_Writer_Abstract 0096 */ 0097 public function setFormatter(Zend_Log_Formatter_Interface $formatter) 0098 { 0099 $this->_formatter = $formatter; 0100 return $this; 0101 } 0102 0103 /** 0104 * Perform shutdown activites such as closing open resources 0105 * 0106 * @return void 0107 */ 0108 public function shutdown() 0109 {} 0110 0111 /** 0112 * Write a message to the log. 0113 * 0114 * @param array $event log data event 0115 * @return void 0116 */ 0117 abstract protected function _write($event); 0118 0119 /** 0120 * Validate and optionally convert the config to array 0121 * 0122 * @param array|Zend_Config $config Zend_Config or Array 0123 * @return array 0124 * @throws Zend_Log_Exception 0125 */ 0126 static protected function _parseConfig($config) 0127 { 0128 if ($config instanceof Zend_Config) { 0129 $config = $config->toArray(); 0130 } 0131 0132 if (!is_array($config)) { 0133 // require_once 'Zend/Log/Exception.php'; 0134 throw new Zend_Log_Exception( 0135 'Configuration must be an array or instance of Zend_Config' 0136 ); 0137 } 0138 0139 return $config; 0140 } 0141 }