Microsoft_Log
[ class tree: Microsoft_Log ] [ index: Microsoft_Log ] [ all elements ]

Source for file Priority.php

Documentation is available at Priority.php

  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   Microsoft
  16.  * @package    Microsoft_Log
  17.  * @subpackage Filter
  18.  * @copyright  Copyright (c) 2005-2010 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 20260 2010-01-13 18:29:22Z ralph $
  21.  */
  22.  
  23. /**
  24.  * @see Microsoft_AutoLoader
  25.  */
  26. require_once dirname(__FILE__'/../../AutoLoader.php';
  27.  
  28. /**
  29.  * @category   Microsoft
  30.  * @package    Microsoft_Log
  31.  * @subpackage Filter
  32.  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  33.  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  34.  * @version    $Id: Priority.php 20260 2010-01-13 18:29:22Z ralph $
  35.  */
  36. {
  37.     /**
  38.      * @var integer 
  39.      */
  40.     protected $_priority;
  41.  
  42.     /**
  43.      * @var string 
  44.      */
  45.     protected $_operator;
  46.  
  47.     /**
  48.      * Filter logging by $priority.  By default, it will accept any log
  49.      * event whose priority value is less than or equal to $priority.
  50.      *
  51.      * @param  integer  $priority  Priority
  52.      * @param  string   $operator  Comparison operator
  53.      * @throws Microsoft_Log_Exception
  54.      */
  55.     public function __construct($priority$operator NULL)
  56.     {
  57.         if (is_integer($priority)) {
  58.             require_once 'Microsoft/Log/Exception.php';
  59.             throw new Microsoft_Log_Exception('Priority must be an integer');
  60.         }
  61.  
  62.         $this->_priority = $priority;
  63.         $this->_operator = is_null($operator'<=' $operator;
  64.     }
  65.  
  66.     /**
  67.      * Create a new instance of Microsoft_Log_Filter_Priority
  68.      * 
  69.      * @param  array $config 
  70.      * @return Microsoft_Log_Filter_Priority 
  71.      * @throws Microsoft_Log_Exception
  72.      */
  73.     static public function factory($config
  74.     {
  75.         $config self::_parseConfig($config);
  76.         $config array_merge(array(
  77.             'priority' => null
  78.             'operator' => null,
  79.         )$config);
  80.  
  81.         // Add support for constants
  82.         if (!is_numeric($config['priority']&& isset($config['priority']&& defined($config['priority'])) {
  83.             $config['priority'constant($config['priority']);
  84.         }
  85.  
  86.         return new self(
  87.             (int) $config['priority']
  88.             $config['operator']
  89.         );
  90.     }
  91.  
  92.     /**
  93.      * Returns TRUE to accept the message, FALSE to block it.
  94.      *
  95.      * @param  array    $event    event data
  96.      * @return boolean            accepted?
  97.      */
  98.     public function accept($event)
  99.     {
  100.         return version_compare($event['priority']$this->_priority$this->_operator);
  101.     }
  102. }

Documentation generated on Wed, 18 May 2011 12:06:43 +0200 by phpDocumentor 1.4.3