[ Index ]
 

Code source de SPIP Agora 1.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Pear/Log/ -> observer.php (source)

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


Généré le : Sat Feb 24 14:40:03 2007 par Balluche grâce à PHPXref 0.7