1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-30 19:30:25 +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 in
bdef2707b4 and the unused autoload code
introduced in f4cee92890.
This commit is contained in:
Nick Liu
2018-10-31 08:22:14 -05:00
parent ee1a5b1278
commit 4c6828be93
4 changed files with 9 additions and 80 deletions

View File

@@ -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)