[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文件
文件大小: 5.8 KiB
MD5: 0ecd83e29d5e445a4e5015972bb129a0

class.base.php - 关闭高亮
  1. <?php
  2. /**
  3.  * File contains just the base class
  4.  *
  5.  * @package classes
  6.  * @copyright Copyright 2003-2014 Zen Cart Development Team
  7.  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  8.  * @version GIT: $Id: Author: Ian Wilson  Wed Mar 12 20:31:27 2014 +0000 Modified in v1.5.3 $
  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 unique key. To ensure there are no naming problems with the array key, we md5 the
  24.    * unique 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 has occurred in the notifier object
  48.    * Can optionally pass parameters and variables to the observer, useful for passing stuff which is outside of the 'scope' of the observed class.
  49.    * Any of params 2-9 can be passed by reference, and will be updated in the calling location if the observer "update" function also receives them by reference
  50.    *
  51.    * @param string The event ID to notify.
  52.    * @param mixed passed as value only.
  53.    * @param mixed Passed by reference.
  54.    * @param mixed Passed by reference.
  55.    * @param mixed Passed by reference.
  56.    * @param mixed Passed by reference.
  57.    * @param mixed Passed by reference.
  58.    * @param mixed Passed by reference.
  59.    * @param mixed Passed by reference.
  60.    * @param mixed Passed by reference.
  61.    *
  62.    * NOTE: The $param1 is not received-by-reference, but params 2-9 are.
  63.    * NOTE: The $param1 value CAN be an array, and is sometimes typecast to be an array, but can also safely be a string or int etc if the notifier sends such and the observer class expects same.
  64.    */
  65.   function notify($eventID, $param1 = array(), & $param2 = NULL, & $param3 = NULL, & $param4 = NULL, & $param5 = NULL, & $param6 = NULL, & $param7 = NULL, & $param8 = NULL, & $param9 = NULL ) {
  66.     // notifier trace logging - for advanced debugging purposes only --- NOTE: This log file can get VERY big VERY quickly!
  67.     if (defined('NOTIFIER_TRACE') && NOTIFIER_TRACE != '' && NOTIFIER_TRACE != 'false' && NOTIFIER_TRACE != 'Off') {
  68.       $file = DIR_FS_LOGS . '/notifier_trace.log';
  69.       $paramArray = (is_array($param1) && sizeof($param1) == 0) ? array() : array('param1' => $param1);
  70.       for ($i = 2; $i < 10; $i++) {
  71.         $param_n = "param$i";
  72.         if ($$param_n !== NULL) {
  73.           $paramArray[$param_n] = $$param_n;
  74.         }
  75.       }
  76.       global $this_is_home_page, $PHP_SELF;
  77.       $main_page = (isset($this_is_home_page) && $this_is_home_page) ? 'index-home' : (IS_ADMIN_FLAG) ? basename($PHP_SELF) : (isset($_GET['main_page'])) ? $_GET['main_page'] : '';
  78.       $output = '';
  79.       if (count($paramArray)) {
  80.         $output = ', ';
  81.         if (NOTIFIER_TRACE == 'var_export' || NOTIFIER_TRACE == 'var_dump' || NOTIFIER_TRACE == 'true') {
  82.           $output .= var_export($paramArray, true);
  83.         } elseif (NOTIFIER_TRACE == 'print_r' || NOTIFIER_TRACE == 'On' || NOTIFIER_TRACE === TRUE) {
  84.           $output .= print_r($paramArray, true);
  85.         }
  86.       }
  87.       error_log( strftime("%Y-%m-%d %H:%M:%S") . ' [main_page=' . $main_page . '] ' . $eventID . $output . "\n", 3, $file);
  88.     }
  89.  
  90.     // handle observers
  91.     // observers can fire either a generic update() method, or a notifier-point-specific updateNotifierPointCamelCased() method. The specific one will fire if found; else the generic update() will fire instead.
  92.     $observers = & base::getStaticObserver();
  93.     if (is_null($observers)) {
  94.       return;
  95.     } else
  96.     {
  97.       foreach($observers as $key=>$obs) {
  98.         if ($obs['eventID'] == $eventID || $obs['eventID'] === '*') {
  99.          $method = 'update';
  100.          $testMethod = $method . self::camelize(strtolower($eventID), TRUE);
  101.          if (method_exists($obs['obs'], $testMethod))
  102.            $method = $testMethod;
  103.          $obs['obs']->{$method}($this, $eventID, $param1,$param2,$param3,$param4,$param5,$param6,$param7,$param8,$param9);
  104.         }
  105.       }
  106.     }
  107.   }
  108.   function & getStaticProperty($var)
  109.   {
  110.     static $staticProperty;
  111.     return $staticProperty;
  112.   }
  113.   function & getStaticObserver() {
  114.     return base::getStaticProperty('observer');
  115.   }
  116.   function setStaticObserver($element, $value)
  117.   {
  118.     $observer =  & base::getStaticObserver();
  119.     if (!is_array($observer)) {
  120.       $observer = array ();
  121.     }
  122.     $observer[$element] = $value;
  123.   }
  124.   function unsetStaticObserver($element)
  125.   {
  126.     $observer =  & base::getStaticObserver();
  127.     unset($observer[$element]);
  128.   }
  129.   public static function camelize($rawName, $camelFirst = FALSE)
  130.   {
  131.     if ($rawName == "")
  132.       return $rawName;
  133.     if ($camelFirst)
  134.     {
  135.       $rawName[0] = strtoupper($rawName[0]);
  136.     }
  137.     return preg_replace_callback('/[_-]([0-9,a-z])/', create_function('$matches', 'return strtoupper($matches[1]);'), $rawName);
  138.   }
  139. }
  140.