b2evolution PHP Cross Reference Blogging Systems

Source: /inc/_core/_class5.funcs.php - 104 lines - 3062 bytes - Summary - Text - Print

Description: Function for handling Classes in PHP 5. In PHP4, _class4.funcs.php should be used instead.

   1  <?php
   2  /**
   3   * Function for handling Classes in PHP 5.
   4   *
   5   * In PHP4, _class4.funcs.php should be used instead.
   6   *
   7   * This file is part of the evoCore framework - {@link http://evocore.net/}
   8   * See also {@link http://sourceforge.net/projects/evocms/}.
   9   *
  10   * @copyright (c)2010-2014 by Francois PLANQUE - {@link http://fplanque.net/}
  11   * Parts of this file are copyright (c)2009 by Daniel HAHLER - {@link http://daniel.hahler.de/}.
  12   *
  13   * {@internal License choice
  14   * - If you have received this file as part of a package, please find the license.txt file in
  15   *   the same folder or the closest folder above for complete license terms.
  16   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  17   *   then you must choose one of the following licenses before using the file:
  18   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  19   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  20   * }}
  21   *
  22   * {@internal Open Source relicensing agreement:
  23   * Daniel HAHLER grants Francois PLANQUE the right to license
  24   * Daniel HAHLER's contributions to this file and the b2evolution project
  25   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  26   * }}
  27   *
  28   * @package evocore
  29   *
  30   * @version $Id: _class5.funcs.php 6136 2014-03-08 07:59:48Z manuel $
  31   */
  32  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  33  
  34  /**
  35   * Dynamic list of class mapping.
  36   *
  37   * Controllers should call load_class() to register classes they may need to have autoloaded when they use them.
  38   *
  39   * @var marray
  40   */
  41  $map_class_path = array();
  42  
  43  /**
  44   * Autoload the required .class.php file when a class is accessed but not defined yet.
  45   * This gets hooked into spl_autoload_register (preferred) or called through __autoload.
  46   * Requires PHP5.
  47   */
  48  function evocms_autoload_class( $classname )
  49  {
  50      global $map_class_path;
  51  
  52      $classname = strtolower($classname);
  53      if( isset($map_class_path[$classname]) )
  54      {
  55          require_once $map_class_path[$classname];
  56      }
  57  }
  58  
  59  
  60  /*
  61   * Use spl_autoload_register mechanism, if available (PHP>=5.1.2).
  62   * This way a stacked set of autoload functions can be used.
  63   */
  64  if( function_exists('spl_autoload_register') )
  65  {
  66      // spl_autoload_register( 'var_dump' );
  67      spl_autoload_register( 'evocms_autoload_class' );
  68  }
  69  else
  70  {
  71      // PHP<5.1.2: Use the fallback method.
  72  	function __autoload( $classname )
  73      {
  74          return evocms_autoload_class($classname);
  75      }
  76  }
  77  
  78  
  79  /**
  80   * In PHP4, this really loads the class. In PHP5, it's smarter than that:
  81   * It only registers the class & file name so that __autoload() can later
  82   * load the class IF and ONLY IF the class is actually needed during execution.
  83   */
  84  function load_class( $class_path, $classname )
  85  {
  86      global $map_class_path, $inc_path;
  87      if( !is_null($classname) )
  88      {
  89          $map_class_path[strtolower($classname)] = $inc_path.$class_path;
  90      }
  91      return true;
  92  }
  93  
  94  
  95  /**
  96   * Create a copy of an object (abstraction from PHP4 vs PHP5)
  97   */
  98  function duplicate( $Obj )
  99  {
 100      $Copy = clone $Obj;
 101      return $Copy;
 102  }
 103  
 104  ?>

title

Description

title

Description

title

Description

title

title

Body