PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/Microsoft/Log/Filter/Priority.php

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