|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Feb 17, 2016 9:53 pm Post subject: Why Smarty_Autoloader::autoload() is so overcomplicated? |
|
|
I was skimming through Smarty codebase while setting up a new workspace. And stumbled upon this piece of code: Code: | public static function autoload($class)
{
$_class = strtolower($class);
$file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
if (strpos($_class, 'smarty_internal_') === 0) {
if (strpos($_class, 'smarty_internal_compile_') === 0) {
if (is_file($file)) {
require $file;
}
return;
}
@include $file;
return;
}
if (preg_match('/^(smarty_(((template_(source|config|cache|compiled|resource_base))|((cached|compiled)?resource)|(variable|security)))|(smarty(bc)?)$)/',
$_class, $match)) {
if (!empty($match[3])) {
@include $file;
return;
} elseif (!empty($match[9]) && isset(self::$rootClasses[$_class])) {
$file = self::$rootClasses[$_class];
require $file;
return;
}
}
if (0 !== strpos($_class, 'smarty')) {
return;
}
if (is_file($file)) {
require $file;
return;
}
return;
} |
Anyone else find it overly complicated and in need of a drastic reduction? Like, 3 times some. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Feb 19, 2016 4:51 am Post subject: |
|
|
Code: | public static function autoload($class)
{
$_class = strtolower($class);
if (isset(self::$rootClasses[$_class])) {
$file = self::$SMARTY_DIR . "/" . self::$rootClasses[$_class];
}
elseif (strpos($_class, 'smarty_') === 0) {
$file = self::$SMARTY_SYSPLUGINS_DIR . "/{$_class}.php";
}
if (is_file($file)) {
return include_once $file;
}
} |
Something like this. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|