File indexing completed on 2024-12-22 05:36:23

0001 <?php
0002 /**
0003  *  ocs-webserver
0004  *
0005  *  Copyright 2016 by pling GmbH.
0006  *
0007  *    This file is part of ocs-webserver.
0008  *
0009  *    This program is free software: you can redistribute it and/or modify
0010  *    it under the terms of the GNU Affero General Public License as
0011  *    published by the Free Software Foundation, either version 3 of the
0012  *    License, or (at your option) any later version.
0013  *
0014  *    This program is distributed in the hope that it will be useful,
0015  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017  *    GNU Affero General Public License for more details.
0018  *
0019  *    You should have received a copy of the GNU Affero General Public License
0020  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021  **/
0022 
0023 class Local_Log_Filter_MinMax extends Zend_Log_Filter_Abstract
0024 {
0025 
0026     /** @var int */
0027     protected $minPriority;
0028     /** @var int */
0029     protected $maxPriority;
0030 
0031     /**
0032      *
0033      * Filter logging by $priority.  By default, it will accept any log
0034      * event whose priority value is less than or equal to $priorityMax
0035      * and greater or equal to $priorityMin.
0036      *
0037      * @param $priorityMin
0038      * @param $priorityMax
0039      * @throws Zend_Log_Exception
0040      * @link http://php.net/manual/en/language.oop5.decon.php
0041      */
0042     public function __construct($priorityMin, $priorityMax)
0043     {
0044         if (!is_int($priorityMin)) {
0045             throw new Zend_Log_Exception('minimal Priority must be an integer');
0046         }
0047 
0048         if (!is_int($priorityMax)) {
0049             throw new Zend_Log_Exception('maximal Priority must be an integer');
0050         }
0051 
0052         $this->minPriority = $priorityMin;
0053         $this->maxPriority = $priorityMax;
0054     }
0055 
0056     /**
0057      * Construct a Zend_Log driver
0058      *
0059      * @param  array|Zend_Config $config
0060      * @return Zend_Log_FactoryInterface
0061      */
0062     static public function factory($config)
0063     {
0064         $config = self::_parseConfig($config);
0065         $config = array_merge(array(
0066             'priorityMin' => null,
0067             'priorityMax' => null,
0068         ), $config);
0069 
0070         return new self(
0071             (int)$config['priorityMin'],
0072             $config['priorityMax']
0073         );
0074     }
0075 
0076     /**
0077      * Returns TRUE to accept the message, FALSE to block it.
0078      *
0079      * @param  array $event event data
0080      * @return boolean            accepted?
0081      */
0082     public function accept($event)
0083     {
0084         return (($event['priority'] >= $this->minPriority) AND ($event['priority'] <= $this->maxPriority));
0085     }
0086 
0087 }