Automatically exported from code.google.com/p/planningalerts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

126 lines
4.0 KiB

  1. <?php
  2. /**
  3. * $Header: /home/ppcvs/paypal_php_sdk/Log/observer.php,v 1.1 2006/02/19 08:22:29 dennis Exp $
  4. * $Horde: horde/lib/Log/observer.php,v 1.5 2000/06/28 21:36:13 jon Exp $
  5. *
  6. * @version $Revision: 1.1 $
  7. * @package Log
  8. */
  9. /**
  10. * The Log_observer:: class implements the Observer end of a Subject-Observer
  11. * pattern for watching log activity and taking actions on exceptional events.
  12. *
  13. * @author Chuck Hagenbuch <chuck@horde.org>
  14. * @since Horde 1.3
  15. * @since Log 1.0
  16. * @package Log
  17. *
  18. * @example observer_mail.php An example Log_observer implementation.
  19. */
  20. class Log_observer
  21. {
  22. /**
  23. * Instance-specific unique identification number.
  24. *
  25. * @var integer
  26. * @access private
  27. */
  28. var $_id = 0;
  29. /**
  30. * The minimum priority level of message that we want to hear about.
  31. * PEAR_LOG_EMERG is the highest priority, so we will only hear messages
  32. * with an integer priority value less than or equal to ours. It defaults
  33. * to PEAR_LOG_INFO, which listens to everything except PEAR_LOG_DEBUG.
  34. *
  35. * @var string
  36. * @access private
  37. */
  38. var $_priority = PEAR_LOG_INFO;
  39. /**
  40. * Creates a new basic Log_observer instance.
  41. *
  42. * @param integer $priority The highest priority at which to receive
  43. * log event notifications.
  44. *
  45. * @access public
  46. */
  47. function Log_observer($priority = PEAR_LOG_INFO)
  48. {
  49. $this->_id = md5(microtime());
  50. $this->_priority = $priority;
  51. }
  52. /**
  53. * Attempts to return a new concrete Log_observer instance of the requested
  54. * type.
  55. *
  56. * @param string $type The type of concreate Log_observer subclass
  57. * to return.
  58. * @param integer $priority The highest priority at which to receive
  59. * log event notifications.
  60. * @param array $conf Optional associative array of additional
  61. * configuration values.
  62. *
  63. * @return object The newly created concrete Log_observer
  64. * instance, or null on an error.
  65. */
  66. function &factory($type, $priority = PEAR_LOG_INFO, $conf = array())
  67. {
  68. $type = strtolower($type);
  69. $class = 'Log_observer_' . $type;
  70. /* Support both the new-style and old-style file naming conventions. */
  71. if (file_exists(dirname(__FILE__) . '/observer_' . $type . '.php')) {
  72. $classfile = 'Log/observer_' . $type . '.php';
  73. $newstyle = true;
  74. } else {
  75. $classfile = 'Log/' . $type . '.php';
  76. $newstyle = false;
  77. }
  78. /* Issue a warning if the old-style conventions are being used. */
  79. if (!$newstyle)
  80. {
  81. trigger_error('Using old-style Log_observer conventions',
  82. E_USER_WARNING);
  83. }
  84. /*
  85. * Attempt to include our version of the named class, but don't treat
  86. * a failure as fatal. The caller may have already included their own
  87. * version of the named class.
  88. */
  89. @include_once $classfile;
  90. /* If the class exists, return a new instance of it. */
  91. if (class_exists($class)) {
  92. /* Support both new-style and old-style construction. */
  93. if ($newstyle) {
  94. $object =& new $class($priority, $conf);
  95. } else {
  96. $object =& new $class($priority);
  97. }
  98. return $object;
  99. }
  100. return null;
  101. }
  102. /**
  103. * This is a stub method to make sure that Log_Observer classes do
  104. * something when they are notified of a message. The default behavior
  105. * is to just print the message, which is obviously not desireable in
  106. * practically any situation - which is why you need to override this
  107. * method. :)
  108. *
  109. * @param array $event A hash describing the log event.
  110. */
  111. function notify($event)
  112. {
  113. print_r($event);
  114. }
  115. }