[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 class.base.php

Zen Cart 源代码 class.base.php




下载文件

文件名: class.base.php
文件类型: PHP文件
文件大小: 2.62 KiB
MD5: 20b642f84038dd47204301eab7c2620a

class.base.php - 关闭高亮
  1. <?php
  2. /**
  3.  * File contains just the base class
  4.  *
  5.  * @package classes
  6.  * @copyright Copyright 2003-2009 Zen Cart Development Team
  7.  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  8.  * @version $Id: class.base.php 14535 2009-10-07 22:16:19Z wilt $
  9.  */
  10. /**
  11.  * abstract class base
  12.  *
  13.  * any class that wants to notify or listen for events must extend this base class
  14.  *
  15.  * @package classes
  16.  */
  17. class base {
  18.   /**
  19.    * method used to an attach an observer to the notifier object
  20.    *
  21.    * NB. We have to get a little sneaky here to stop session based classes adding events ad infinitum
  22.    * To do this we first concatenate the class name with the event id, as a class is only ever going to attach to an
  23.    * event id once, this provides a unigue key. To ensure there are no naming problems with the array key, we md5 the unique
  24.    * name to provide a unique hashed key.
  25.    *
  26.    * @param object Reference to the observer class
  27.    * @param array An array of eventId's to observe
  28.    */
  29.   function attach(&$observer, $eventIDArray) {
  30.     foreach($eventIDArray as $eventID) {
  31.       $nameHash = md5(get_class($observer).$eventID);
  32.       base::setStaticObserver($nameHash, array('obs'=>&$observer, 'eventID'=>$eventID));
  33.     }
  34.   }
  35.   /**
  36.    * method used to detach an observer from the notifier object
  37.    * @param object
  38.    * @param array
  39.    */
  40.   function detach($observer, $eventIDArray) {
  41.     foreach($eventIDArray as $eventID) {    
  42.       $nameHash = md5(get_class($observer).$eventID);
  43.       base::unsetStaticObserver($nameHash);
  44.     }
  45.   }
  46.   /**
  47.    * method to notify observers that an event as occurred in the notifier object
  48.    *
  49.    * @param string The event ID to notify for
  50.    * @param array paramters to pass to the observer, useful for passing stuff which is outside of the 'scope' of the observed class.
  51.    */
  52.   function notify($eventID, $paramArray = array()) {
  53.     $observers = & base::getStaticObserver();
  54.     if (!is_null($observers))
  55.     {
  56.       foreach($observers as $key=>$obs) {
  57.         if ($obs['eventID'] == $eventID) {
  58.           $obs['obs']->update($this, $eventID, $paramArray);
  59.         }
  60.       }
  61.     }
  62.   }
  63.   function & getStaticProperty($var)
  64.   {
  65.     static $staticProperty;
  66.     return $staticProperty;
  67.   }
  68.   function & getStaticObserver() {
  69.     return base::getStaticProperty('observer');
  70.   }
  71.   function & setStaticObserver($element, $value)
  72.   {
  73.     $observer =  & base::getStaticObserver();
  74.     $observer[$element] = $value;
  75.   }
  76.   function & unsetStaticObserver($element)
  77.   {
  78.     $observer =  & base::getStaticObserver();
  79.     unset($observer[$element]);
  80.   }
  81. }