mirror of
https://github.com/e107inc/e107.git
synced 2025-07-31 20:00:37 +02:00
Moved autoload responsibility to e107_class.php
Instead of every independently operating client code figuring out its own autoload policies, the e107 class file e107_class.php now takes care of autoloading. Any client that uses the e107 class will automatically benefit from autoloading for e107. This cuts down on potential code duplication, and e107::getSingleton() is no longer tied to trying to figure out the class path. This commit REMOVES support for the unused constant flag E107_DISABLE_AUTOLOAD introduced inbdef2707b4
and the unused autoload code introduced inf4cee92890
.
This commit is contained in:
67
class2.php
67
class2.php
@@ -261,73 +261,6 @@ $e107 = e107::getInstance()->initCore($e107_paths, e_ROOT, $sql_info, varset($E1
|
||||
|
||||
e107::getSingleton('eIPHandler'); // This auto-handles bans etc
|
||||
|
||||
|
||||
### NEW Register Autoload - do it asap
|
||||
if(!function_exists('spl_autoload_register'))
|
||||
{
|
||||
// PHP >= 5.1.2 required
|
||||
die('Fatal exception - spl_autoload_* required.');
|
||||
}
|
||||
|
||||
|
||||
// allow disable of autoloading - may be removed as e107::autoload_register() is flexible enough
|
||||
if(!defset('E107_DISABLE_AUTOLOAD', false))
|
||||
{
|
||||
/**
|
||||
* Generic autoloader. (didn't work while in e107_class.php)
|
||||
* @example if your plugin calls 'use Xxxxx\Yyyyy\Zzzzz;' it will attempt to load: ./vendor/Xxxxx/Yyyyy/Zzzzz.php
|
||||
*/
|
||||
function autoloadPsr0($className)
|
||||
{
|
||||
$className = str_replace("_", "\\", $className);
|
||||
$className = ltrim($className, '\\');
|
||||
$fileName = '';
|
||||
$namespace = '';
|
||||
|
||||
if ($lastNsPos = strripos($className, '\\'))
|
||||
{
|
||||
$namespace = substr($className, 0, $lastNsPos);
|
||||
$className = substr($className, $lastNsPos + 1);
|
||||
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
|
||||
|
||||
$fullPath = 'vendor'. DIRECTORY_SEPARATOR . $fileName;
|
||||
|
||||
if(file_exists($fullPath))
|
||||
{
|
||||
e107_require_once($fullPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
e107::autoload_register(array('e107', 'autoload'));
|
||||
// e107::autoload_register('autoloadPsr0'); // Generic 'use xxxx\yyyy\zzzz;' fix/solution for plugin developers.
|
||||
|
||||
}
|
||||
|
||||
function genericAutoload($className)
|
||||
{
|
||||
$className = str_replace("_", "\\", $className);
|
||||
$className = ltrim($className, '\\');
|
||||
$fileName = '';
|
||||
$namespace = '';
|
||||
if ($lastNsPos = strripos($className, '\\'))
|
||||
{
|
||||
$namespace = substr($className, 0, $lastNsPos);
|
||||
$className = substr($className, $lastNsPos + 1);
|
||||
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
|
||||
|
||||
e107_require_once($fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* NEW - system security levels
|
||||
* Could be overridden by e107_config.php OR $CLASS2_INCLUDE script (if not set earlier)
|
||||
|
@@ -4830,6 +4830,13 @@ class e107
|
||||
*/
|
||||
public static function autoload_register($function, $prepend = false)
|
||||
{
|
||||
### NEW Register Autoload - do it asap
|
||||
if(!function_exists('spl_autoload_register'))
|
||||
{
|
||||
// PHP >= 5.1.2 required
|
||||
die_fatal_error('Fatal exception - spl_autoload_* required.');
|
||||
}
|
||||
|
||||
if(!$prepend || false === ($registered = spl_autoload_functions()))
|
||||
{
|
||||
return spl_autoload_register($function);
|
||||
@@ -5155,3 +5162,5 @@ class e107
|
||||
|
||||
|
||||
}
|
||||
|
||||
e107::autoload_register(array(e107::class, 'autoload'));
|
12
install.php
12
install.php
@@ -163,18 +163,6 @@ if($e107->initInstall($e107_paths, $ebase, $override)===false)
|
||||
|
||||
unset($e107_paths,$override,$ebase);
|
||||
|
||||
|
||||
|
||||
### NEW Register Autoload - do it asap
|
||||
if(!function_exists('spl_autoload_register'))
|
||||
{
|
||||
// PHP >= 5.1.2 required
|
||||
die_fatal_error('Fatal exception - spl_autoload_* required.');
|
||||
}
|
||||
|
||||
// register core autoload
|
||||
e107::autoload_register(array('e107', 'autoload'));
|
||||
|
||||
// NEW - session handler
|
||||
require_once(e_HANDLER.'session_handler.php');
|
||||
define('e_SECURITY_LEVEL', e_session::SECURITY_LEVEL_NONE);
|
||||
|
Reference in New Issue
Block a user