Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Why Smarty_Autoloader::autoload() is so overcomplicated?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Feb 17, 2016 9:53 pm    Post subject: Why Smarty_Autoloader::autoload() is so overcomplicated? Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Feb 19, 2016 4:51 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP