|
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: Mon Jun 27, 2016 10:09 am Post subject: Simplify autoloading. |
|
|
1. Move smartycompilerexception.php and smartyexception.php up one level. Rename them properly.
2. Populate array of Smarty core classes like this:
Code: | private static $rootClasses = array(
'smarty' => 'Smarty.class.php',
'smartybc' => 'SmartyBC.class.php',
'smartyexception' => 'SmartyException.php',
'smartycompilerexception' => 'SmartyCompilerException.php',
); |
3. Then autoloader degrades to a straightforward:
Code: | /**
* Handles auto loading of classes.
*
* @param string $class A class name.
*/
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 (isset($file) && is_file($file)) {
return include_once $file;
}
} |
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Jun 28, 2016 1:17 am Post subject: |
|
|
submit a PR? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Jun 28, 2016 1:56 am Post subject: |
|
|
If you don't see obvious issues with my suggestion, I'll do that. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Jun 28, 2016 5:52 am Post subject: |
|
|
I wanted to avoid moving files, but it seems there's no way around it.
SMARTY_SYSPLUGINS_DIR could be redefined before autoloader is registered.
Which makes the process convoluted again, although in a different place. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Jun 28, 2016 12:05 pm Post subject: |
|
|
I'm not terribly concerned with the intricacies of the autoloader, as this is not something a developer has to see or directly deal with. What is important is that it works for all intents and purposes. However, if there is a straight-forward way to simplify core code, I'm not adverse to changing it. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Jun 28, 2016 2:45 pm Post subject: |
|
|
The point being, I've hit a situation, where it wanted to throw an exception, but didn't manage to find the class.
After a number of tries to convince the codebase to behave, I ended up rewriting the autoloader from scratch. And then backtracked the changes to the PR. |
|
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
|