PageRenderTime 287ms CodeModel.GetById 91ms app.highlight 13ms RepoModel.GetById 146ms app.codeStats 1ms

/library/Zend/Log/Filter/Priority.php

https://bitbucket.org/hieronim1981/tunethemusic
PHP | 101 lines | 35 code | 9 blank | 57 comment | 4 complexity | 85bd9978d485986e1c57ae002d7b8882 MD5 | raw file
  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 Filter
 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
 20 * @version    $Id: Priority.php 24593 2012-01-05 20:35:02Z matthew $
 21 */
 22
 23/** Zend_Log_Filter_Abstract */
 24require_once 'Zend/Log/Filter/Abstract.php';
 25
 26/**
 27 * @category   Zend
 28 * @package    Zend_Log
 29 * @subpackage Filter
 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
 32 * @version    $Id: Priority.php 24593 2012-01-05 20:35:02Z matthew $
 33 */
 34class Zend_Log_Filter_Priority extends Zend_Log_Filter_Abstract
 35{
 36    /**
 37     * @var integer
 38     */
 39    protected $_priority;
 40
 41    /**
 42     * @var string
 43     */
 44    protected $_operator;
 45
 46    /**
 47     * Filter logging by $priority.  By default, it will accept any log
 48     * event whose priority value is less than or equal to $priority.
 49     *
 50     * @param  integer  $priority  Priority
 51     * @param  string   $operator  Comparison operator
 52     * @return void
 53     * @throws Zend_Log_Exception
 54     */
 55    public function __construct($priority, $operator = null)
 56    {
 57        if (! is_int($priority)) {
 58            require_once 'Zend/Log/Exception.php';
 59            throw new Zend_Log_Exception('Priority must be an integer');
 60        }
 61
 62        $this->_priority = $priority;
 63        $this->_operator = $operator === null ? '<=' : $operator;
 64    }
 65
 66    /**
 67     * Create a new instance of Zend_Log_Filter_Priority
 68     *
 69     * @param  array|Zend_Config $config
 70     * @return Zend_Log_Filter_Priority
 71     */
 72    static public function factory($config)
 73    {
 74        $config = self::_parseConfig($config);
 75        $config = array_merge(array(
 76            'priority' => null,
 77            'operator' => null,
 78        ), $config);
 79
 80        // Add support for constants
 81        if (!is_numeric($config['priority']) && isset($config['priority']) && defined($config['priority'])) {
 82            $config['priority'] = constant($config['priority']);
 83        }
 84
 85        return new self(
 86            (int) $config['priority'],
 87            $config['operator']
 88        );
 89    }
 90
 91    /**
 92     * Returns TRUE to accept the message, FALSE to block it.
 93     *
 94     * @param  array    $event    event data
 95     * @return boolean            accepted?
 96     */
 97    public function accept($event)
 98    {
 99        return version_compare($event['priority'], $this->_priority, $this->_operator);
100    }
101}