PageRenderTime 74ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Zend/Log/Filter/Priority.php

https://bitbucket.org/simukti/zf1
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. /** 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-2012 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @version $Id: Priority.php 24593 2012-01-05 20:35:02Z matthew $
  31. */
  32. class Zend_Log_Filter_Priority extends Zend_Log_Filter_Abstract
  33. {
  34. /**
  35. * @var integer
  36. */
  37. protected $_priority;
  38. /**
  39. * @var string
  40. */
  41. protected $_operator;
  42. /**
  43. * Filter logging by $priority. By default, it will accept any log
  44. * event whose priority value is less than or equal to $priority.
  45. *
  46. * @param integer $priority Priority
  47. * @param string $operator Comparison operator
  48. * @return void
  49. * @throws Zend_Log_Exception
  50. */
  51. public function __construct($priority, $operator = null)
  52. {
  53. if (! is_int($priority)) {
  54. require_once 'Zend/Log/Exception.php';
  55. throw new Zend_Log_Exception('Priority must be an integer');
  56. }
  57. $this->_priority = $priority;
  58. $this->_operator = $operator === null ? '<=' : $operator;
  59. }
  60. /**
  61. * Create a new instance of Zend_Log_Filter_Priority
  62. *
  63. * @param array|Zend_Config $config
  64. * @return Zend_Log_Filter_Priority
  65. */
  66. static public function factory($config)
  67. {
  68. $config = self::_parseConfig($config);
  69. $config = array_merge(array(
  70. 'priority' => null,
  71. 'operator' => null,
  72. ), $config);
  73. // Add support for constants
  74. if (!is_numeric($config['priority']) && isset($config['priority']) && defined($config['priority'])) {
  75. $config['priority'] = constant($config['priority']);
  76. }
  77. return new self(
  78. (int) $config['priority'],
  79. $config['operator']
  80. );
  81. }
  82. /**
  83. * Returns TRUE to accept the message, FALSE to block it.
  84. *
  85. * @param array $event event data
  86. * @return boolean accepted?
  87. */
  88. public function accept($event)
  89. {
  90. return version_compare($event['priority'], $this->_priority, $this->_operator);
  91. }
  92. }