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

Source for file Abstract.php

Documentation is available at Abstract.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 Writer
  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: Abstract.php 22632 2010-07-18 18:30:08Z ramon $
  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 Writer
  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: Abstract.php 22632 2010-07-18 18:30:08Z ramon $
  35.  */
  36. abstract class Microsoft_Log_Writer_Abstract implements Microsoft_Log_FactoryInterface
  37. {
  38.     /**
  39.      * @var array of Microsoft_Log_Filter_Interface
  40.      */
  41.     protected $_filters = array();
  42.  
  43.     /**
  44.      * Formats the log message before writing.
  45.      * @var Microsoft_Log_Formatter_Interface 
  46.      */
  47.     protected $_formatter;
  48.  
  49.     /**
  50.      * Add a filter specific to this writer.
  51.      *
  52.      * @param  Microsoft_Log_Filter_Interface  $filter 
  53.      * @return void 
  54.      */
  55.     public function addFilter($filter)
  56.     {
  57.         if (is_integer($filter)) {
  58.             $filter new Microsoft_Log_Filter_Priority($filter);
  59.         }
  60.  
  61.         if (!$filter instanceof Microsoft_Log_Filter_Interface{
  62.             /** @see Microsoft_Log_Exception */
  63.             require_once 'Microsoft/Log/Exception.php';
  64.             throw new Microsoft_Log_Exception('Invalid filter provided');
  65.         }
  66.  
  67.         $this->_filters[$filter;
  68.     }
  69.  
  70.     /**
  71.      * Log a message to this writer.
  72.      *
  73.      * @param  array     $event  log data event
  74.      * @return void 
  75.      */
  76.     public function write($event)
  77.     {
  78.         foreach ($this->_filters as $filter{
  79.             if ($filter->accept($event)) {
  80.                 return;
  81.             }
  82.         }
  83.  
  84.         // exception occurs on error
  85.         $this->_write($event);
  86.     }
  87.  
  88.     /**
  89.      * Set a new formatter for this writer
  90.      *
  91.      * @param  Microsoft_Log_Formatter_Interface $formatter 
  92.      * @return void 
  93.      */
  94.     public function setFormatter(Microsoft_Log_Formatter_Interface $formatter)
  95.     {
  96.         $this->_formatter = $formatter;
  97.     }
  98.  
  99.     /**
  100.      * Perform shutdown activites such as closing open resources
  101.      *
  102.      * @return void 
  103.      */
  104.     public function shutdown()
  105.     {}
  106.  
  107.     /**
  108.      * Write a message to the log.
  109.      *
  110.      * @param  array  $event  log data event
  111.      * @return void 
  112.      */
  113.     abstract protected function _write($event);
  114.  
  115.     /**
  116.      * Validate and optionally convert the config to array
  117.      *
  118.      * @param  array $config 
  119.      * @return array 
  120.      * @throws Zend_Log_Exception
  121.      */
  122.     static protected function _parseConfig($config)
  123.     {
  124.         if (!is_array($config)) {
  125.             require_once 'Microsoft/Log/Exception.php';
  126.             throw new Microsoft_Log_Exception(
  127.                 'Configuration must be an array'
  128.             );
  129.         }
  130.  
  131.         return $config;
  132.     }
  133. }

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