[ Index ]
 

Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/includes/classes/ -> class.base.php (source)

   1  <?php
   2  /** 

   3   * File contains just the base class

   4   *

   5   * @package classes

   6   * @copyright Copyright 2003-2005 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 3041 2006-02-15 21:56:45Z 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     * array to hold the list of observer classes

  20     * @var array

  21     */
  22    var $observers = array();
  23    /**

  24     * method used to an attach an observer to the notifier object

  25     * 

  26     * NB. We have to get a little sneaky here to stop session based classes adding events ad infinitum

  27     * To do this we first concatenate the class name with the event id, as a class is only ever going to attach to an

  28     * event id once, this provides a unigue key. To ensure there are no naming problems with the array key, we md5 the unique

  29     * name to provide a unique hashed key. 

  30     * 

  31     * @param object Reference to the observer class

  32     * @param array An array of eventId's to observe

  33     */
  34    function attach(&$observer, $eventIDArray) {
  35      foreach($eventIDArray as $eventID) {
  36        $nameHash = md5(get_class($observer).$eventID);
  37        $this->observers[$nameHash] = array('obs'=>&$observer, 'eventID'=>$eventID);
  38      }
  39    }
  40    /**

  41     * method used to detach an observer from the notifier object

  42     * @param object

  43     * @param array

  44     */
  45    function detach($observer, $eventIDArray) {
  46      foreach($eventIDArray as $eventID) {    
  47        $nameHash = md5(get_class($observer).$eventID);
  48        unset($this->observers[$nameHash]);
  49      }
  50    }
  51    /**

  52     * method to notify observers that an event as occurred in the notifier object

  53     * 

  54     * @param string The event ID to notify for

  55     * @param array paramters to pass to the observer, useful for passing stuff which is outside of the 'scope' of the observed class.

  56     */
  57    function notify($eventID, $paramArray = array()) {
  58      foreach($this->observers as $key=>$obs) {
  59        if ($obs['eventID'] == $eventID) {
  60          $obs['obs']->update($this, $eventID, $paramArray);
  61        }
  62      }
  63    }
  64  }
  65  ?>


Généré le : Mon Nov 26 16:45:43 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics