PageRenderTime 56ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/system/libraries/Zend/Log/Filter/Message.php

https://bitbucket.org/micromax/vox-fw
PHP | 85 lines | 28 code | 6 blank | 51 comment | 1 complexity | 33d72285c1bba3342d8b8e7ca499b63d 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-2011 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 23775 2011-03-01 17:25:24Z ralph $
  21. */
  22. /** Zend_Log_Filter_Abstract */
  23. require_once 'Zend/Log/Filter/Abstract.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Log
  27. * @subpackage Filter
  28. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @version $Id: Message.php 23775 2011-03-01 17:25:24Z ralph $
  31. */
  32. class Zend_Log_Filter_Message extends Zend_Log_Filter_Abstract
  33. {
  34. /**
  35. * @var string
  36. */
  37. protected $_regexp;
  38. /**
  39. * Filter out any log messages not matching $regexp.
  40. *
  41. * @param string $regexp Regular expression to test the log message
  42. * @return void
  43. * @throws Zend_Log_Exception
  44. */
  45. public function __construct($regexp)
  46. {
  47. if (@preg_match($regexp, '') === false) {
  48. require_once 'Zend/Log/Exception.php';
  49. throw new Zend_Log_Exception("Invalid regular expression '$regexp'");
  50. }
  51. $this->_regexp = $regexp;
  52. }
  53. /**
  54. * Create a new instance of Zend_Log_Filter_Message
  55. *
  56. * @param array|Zend_Config $config
  57. * @return Zend_Log_Filter_Message
  58. */
  59. static public function factory($config)
  60. {
  61. $config = self::_parseConfig($config);
  62. $config = array_merge(array(
  63. 'regexp' => null
  64. ), $config);
  65. return new self(
  66. $config['regexp']
  67. );
  68. }
  69. /**
  70. * Returns TRUE to accept the message, FALSE to block it.
  71. *
  72. * @param array $event event data
  73. * @return boolean accepted?
  74. */
  75. public function accept($event)
  76. {
  77. return preg_match($this->_regexp, $event['message']) > 0;
  78. }
  79. }