gluon-web-remote

Web remote Administration for big size of gluon routers
git clone git://archive.git.mtrnord.blog/MTRNord/gluon-web-remote.git
Log | Files | Refs | README

Autoloader.php (5737B)


      1 <?php
      2 /**
      3  * Smarty Autoloader
      4  *
      5  * @package    Smarty
      6  */
      7 
      8 /**
      9  * Smarty Autoloader
     10  *
     11  * @package    Smarty
     12  * @author     Uwe Tews
     13  *             Usage:
     14  *             require_once '...path/Autoloader.php';
     15  *             Smarty_Autoloader::register();
     16  *             $smarty = new Smarty();
     17  *             Note:       This autoloader is not needed if you use Composer.
     18  *             Composer will automatically add the classes of the Smarty package to it common autoloader.
     19  */
     20 class Smarty_Autoloader
     21 {
     22     /**
     23      * Filepath to Smarty root
     24      *
     25      * @var string
     26      */
     27     public static $SMARTY_DIR = '';
     28     /**
     29      * Filepath to Smarty internal plugins
     30      *
     31      * @var string
     32      */
     33     public static $SMARTY_SYSPLUGINS_DIR = '';
     34     /**
     35      * Array of not existing classes to avoid is_file calls for  already tested classes
     36      *
     37      * @var array
     38      */
     39     public static $unknown = array();
     40     /**
     41      * Array with Smarty core classes and their filename
     42      *
     43      * @var array
     44      */
     45     public static $rootClasses = array('Smarty'   => 'Smarty.class.php',
     46                                        'SmartyBC' => 'SmartyBC.class.php',
     47     );
     48 
     49     private static $syspluginsClasses = array(
     50         'smarty_config_source'                  => true,
     51         'smarty_security'                       => true,
     52         'smarty_cacheresource'                  => true,
     53         'smarty_compiledresource'               => true,
     54         'smarty_cacheresource_custom'           => true,
     55         'smarty_cacheresource_keyvaluestore'    => true,
     56         'smarty_resource'                       => true,
     57         'smarty_resource_custom'                => true,
     58         'smarty_resource_uncompiled'            => true,
     59         'smarty_resource_recompiled'            => true,
     60         'smarty_template_source'                => true,
     61         'smarty_template_compiled'              => true,
     62         'smarty_template_cached'                => true,
     63         'smarty_template_config'                => true,
     64         'smarty_data'                           => true,
     65         'smarty_variable'                       => true,
     66         'smarty_undefined_variable'             => true,
     67         'smartyexception'                       => true,
     68         'smartycompilerexception'               => true,
     69         'smarty_internal_data'                  => true,
     70         'smarty_internal_template'              => true,
     71         'smarty_internal_templatebase'          => true,
     72         'smarty_internal_resource_file'         => true,
     73         'smarty_internal_resource_extends'      => true,
     74         'smarty_internal_resource_eval'         => true,
     75         'smarty_internal_resource_string'       => true,
     76         'smarty_internal_resource_registered'   => true,
     77         'smarty_internal_extension_codeframe'   => true,
     78         'smarty_internal_extension_config'      => true,
     79         'smarty_internal_filter_handler'        => true,
     80         'smarty_internal_function_call_handler' => true,
     81         'smarty_internal_cacheresource_file'    => true,
     82         'smarty_internal_write_file'    => true,
     83     );
     84 
     85     /**
     86      * Registers Smarty_Autoloader backward compatible to older installations.
     87      *
     88      * @param bool $prepend Whether to prepend the autoloader or not.
     89      */
     90     public static function registerBC($prepend = false)
     91     {
     92         /**
     93          * register the class autoloader
     94          */
     95         if (!defined('SMARTY_SPL_AUTOLOAD')) {
     96             define('SMARTY_SPL_AUTOLOAD', 0);
     97         }
     98         if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false) {
     99             $registeredAutoLoadFunctions = spl_autoload_functions();
    100             if (!isset($registeredAutoLoadFunctions['spl_autoload'])) {
    101                 spl_autoload_register();
    102             }
    103         } else {
    104             self::register($prepend);
    105         }
    106     }
    107 
    108     /**
    109      * Registers Smarty_Autoloader as an SPL autoloader.
    110      *
    111      * @param bool $prepend Whether to prepend the autoloader or not.
    112      */
    113     public static function register($prepend = false)
    114     {
    115         self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : dirname(__FILE__) . '/';
    116         self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR : self::$SMARTY_DIR . 'sysplugins/';
    117         if (version_compare(phpversion(), '5.3.0', '>=')) {
    118             spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
    119         } else {
    120             spl_autoload_register(array(__CLASS__, 'autoload'));
    121         }
    122     }
    123 
    124     /**
    125      * Handles autoloading of classes.
    126      *
    127      * @param string $class A class name.
    128      */
    129     public static function autoload($class)
    130     {
    131         // Request for Smarty or already unknown class
    132         if (isset(self::$unknown[$class])) {
    133             return;
    134         }
    135         $_class = strtolower($class);
    136         if (isset(self::$syspluginsClasses[$_class])) {
    137             $_class = (self::$syspluginsClasses[$_class] === true) ? $_class : self::$syspluginsClasses[$_class];
    138             $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
    139             require_once $file;
    140             return;
    141         } elseif (0 !== strpos($_class, 'smarty_internal_')) {
    142             if (isset(self::$rootClasses[$class])) {
    143                 $file = self::$SMARTY_DIR . self::$rootClasses[$class];
    144                 require_once $file;
    145                 return;
    146             }
    147             self::$unknown[$class] = true;
    148             return;
    149         }
    150         $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
    151         if (is_file($file)) {
    152             require_once $file;
    153             return;
    154         }
    155         self::$unknown[$class] = true;
    156         return;
    157     }
    158 }