PageRenderTime 102ms CodeModel.GetById 40ms app.highlight 2ms RepoModel.GetById 58ms app.codeStats 0ms

/library/Zend/Log/Filter/Message.php

https://bitbucket.org/hieronim1981/tunethemusic
PHP | 85 lines | 28 code | 6 blank | 51 comment | 1 complexity | dd1489c164fc35cbd161c3ae16236015 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: Message.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: Message.php 24593 2012-01-05 20:35:02Z matthew $
33 */
34class Zend_Log_Filter_Message extends Zend_Log_Filter_Abstract
35{
36    /**
37     * @var string
38     */
39    protected $_regexp;
40
41    /**
42     * Filter out any log messages not matching $regexp.
43     *
44     * @param  string  $regexp     Regular expression to test the log message
45     * @return void
46     * @throws Zend_Log_Exception
47     */
48    public function __construct($regexp)
49    {
50        if (@preg_match($regexp, '') === false) {
51            require_once 'Zend/Log/Exception.php';
52            throw new Zend_Log_Exception("Invalid regular expression '$regexp'");
53        }
54        $this->_regexp = $regexp;
55    }
56
57    /**
58     * Create a new instance of Zend_Log_Filter_Message
59     *
60     * @param  array|Zend_Config $config
61     * @return Zend_Log_Filter_Message
62     */
63    static public function factory($config)
64    {
65        $config = self::_parseConfig($config);
66        $config = array_merge(array(
67            'regexp' => null
68        ), $config);
69
70        return new self(
71            $config['regexp']
72        );
73    }
74
75    /**
76     * Returns TRUE to accept the message, FALSE to block it.
77     *
78     * @param  array    $event    event data
79     * @return boolean            accepted?
80     */
81    public function accept($event)
82    {
83        return preg_match($this->_regexp, $event['message']) > 0;
84    }
85}