diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:39:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:39:39 +0000 |
commit | 8ca6cc32b2c789a3149861159ad258f2cb9491e3 (patch) | |
tree | 2492de6f1528dd44eaa169a5c1555026d9cb75ec /library/vendor/Zend/Log/Writer/Abstract.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-8ca6cc32b2c789a3149861159ad258f2cb9491e3.tar.xz icingaweb2-8ca6cc32b2c789a3149861159ad258f2cb9491e3.zip |
Adding upstream version 2.11.4.upstream/2.11.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/vendor/Zend/Log/Writer/Abstract.php')
-rw-r--r-- | library/vendor/Zend/Log/Writer/Abstract.php | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/library/vendor/Zend/Log/Writer/Abstract.php b/library/vendor/Zend/Log/Writer/Abstract.php new file mode 100644 index 0000000..c39be13 --- /dev/null +++ b/library/vendor/Zend/Log/Writer/Abstract.php @@ -0,0 +1,138 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +/** Zend_Log_Filter_Priority */ + +/** + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface +{ + /** + * @var array of Zend_Log_Filter_Interface + */ + protected $_filters = array(); + + /** + * Formats the log message before writing. + * + * @var Zend_Log_Formatter_Interface + */ + protected $_formatter; + + /** + * Add a filter specific to this writer. + * + * @param Zend_Log_Filter_Interface|int $filter Filter class or filter + * priority + * @return Zend_Log_Writer_Abstract + * @throws Zend_Log_Exception + */ + public function addFilter($filter) + { + if (is_int($filter)) { + $filter = new Zend_Log_Filter_Priority($filter); + } + + if (!$filter instanceof Zend_Log_Filter_Interface) { + /** @see Zend_Log_Exception */ + throw new Zend_Log_Exception('Invalid filter provided'); + } + + $this->_filters[] = $filter; + return $this; + } + + /** + * Log a message to this writer. + * + * @param array $event log data event + * @return void + */ + public function write($event) + { + /** @var Zend_Log_Filter_Interface $filter */ + foreach ($this->_filters as $filter) { + if (!$filter->accept($event)) { + return; + } + } + + // exception occurs on error + $this->_write($event); + } + + /** + * Set a new formatter for this writer + * + * @param Zend_Log_Formatter_Interface $formatter + * @return Zend_Log_Writer_Abstract + */ + public function setFormatter(Zend_Log_Formatter_Interface $formatter) + { + $this->_formatter = $formatter; + return $this; + } + + /** + * Perform shutdown activites such as closing open resources + * + * @return void + */ + public function shutdown() + {} + + /** + * Write a message to the log. + * + * @param array $event log data event + * @return void + */ + abstract protected function _write($event); + + /** + * Validate and optionally convert the config to array + * + * @param array|Zend_Config $config Zend_Config or Array + * @return array + * @throws Zend_Log_Exception + */ + static protected function _parseConfig($config) + { + if ($config instanceof Zend_Config) { + $config = $config->toArray(); + } + + if (!is_array($config)) { + throw new Zend_Log_Exception( + 'Configuration must be an array or instance of Zend_Config' + ); + } + + return $config; + } +} |