Source for file fof.php

Documentation is available at fof.php

  1. <?php
  2. /**
  3.  *  @package     FrameworkOnFramework
  4.  *  @subpackage  autoloader
  5.  *  @copyright   Copyright (c)2010-2012 Nicholas K. Dionysopoulos
  6.  *  @license     GNU General Public License version 2, or later
  7.  */
  8.  
  9. defined('FOF_INCLUDED'or die();
  10.  
  11. /**
  12.  * The main class autoloader for FOF itself
  13.  *
  14.  * @package     FrameworkOnFramework
  15.  * @subpackage  autoloader
  16.  * @since       2.1
  17.  */
  18. {
  19.     /**
  20.      * An instance of this autoloader
  21.      *
  22.      * @var   FOFAutoloaderFof 
  23.      */
  24.     public static $autoloader null;
  25.  
  26.     /**
  27.      * The path to the FOF root directory
  28.      *
  29.      * @var   string 
  30.      */
  31.     public static $fofPath null;
  32.  
  33.     /**
  34.      * Initialise this autoloader
  35.      *
  36.      * @return  FOFAutoloaderFof 
  37.      */
  38.     public static function init()
  39.     {
  40.         if (self::$autoloader == null)
  41.         {
  42.             self::$autoloader new self;
  43.         }
  44.  
  45.         return self::$autoloader;
  46.     }
  47.  
  48.     /**
  49.      * Public constructor. Registers the autoloader with PHP.
  50.      */
  51.     public function __construct()
  52.     {
  53.         self::$fofPath realpath(__DIR__ . '/../');
  54.  
  55.         spl_autoload_register(array($this,'autoload_fof_core'));
  56.     }
  57.  
  58.     /**
  59.      * The actual autoloader
  60.      *
  61.      * @param   string  $class_name  The name of the class to load
  62.      *
  63.      * @return  void 
  64.      */
  65.     public function autoload_fof_core($class_name)
  66.     {
  67.         // Make sure the class has a FOF prefix
  68.         if (substr($class_name03!= 'FOF')
  69.         {
  70.             return;
  71.         }
  72.  
  73.         // Remove the prefix
  74.         $class substr($class_name3);
  75.  
  76.         // Change from camel cased (e.g. ViewHtml) into a lowercase array (e.g. 'view','html')
  77.         $class preg_replace('/(\s)+/''_'$class);
  78.         $class strtolower(preg_replace('/(?<=\\w)([A-Z])/''_\\1'$class));
  79.         $class explode('_'$class);
  80.  
  81.         // First try finding in structured directory format (preferred)
  82.         $path self::$fofPath '/' implode('/'$class'.php';
  83.  
  84.         if (@file_exists($path))
  85.         {
  86.             include_once $path;
  87.         }
  88.  
  89.         // Then try the duplicate last name structured directory format (not recommended)
  90.  
  91.         if (!class_exists($class_namefalse))
  92.         {
  93.             reset($class);
  94.             $lastPart end($class);
  95.             $path self::$fofPath '/' implode('/'$class'/' $lastPart '.php';
  96.  
  97.             if (@file_exists($path))
  98.             {
  99.                 include_once $path;
  100.             }
  101.         }
  102.  
  103.         // If it still fails, try looking in the legacy folder (used for backwards compatibility)
  104.  
  105.         if (!class_exists($class_namefalse))
  106.         {
  107.             $path self::$fofPath '/legacy/' implode('/'$class'.php';
  108.  
  109.             if (@file_exists($path))
  110.             {
  111.                 include_once $path;
  112.             }
  113.         }
  114.     }
  115. }

Documentation generated on Tue, 19 Nov 2013 15:03:24 +0100 by phpDocumentor 1.4.3