Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

BUG? $resource_type = strtolower($resource_type);

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
innocenzo
Smarty n00b


Joined: 04 Mar 2010
Posts: 4

PostPosted: Thu Mar 04, 2010 1:22 pm    Post subject: BUG? $resource_type = strtolower($resource_type); Reply with quote

There seems to be a problem loading resources with uppercase characters in its name, for example 'mysqlDB'.

If you register the resource 'mysqlDB' it gets stored as $smarty->_plugins['resource']['mysqlDB'].

But in this function the name gets lowercased:

Code:

    private function getResourceTypeName ($template_resource, &$resource_type, &$resource_name)
    {
        if (strpos($template_resource, ':') === false) {
            // no resource given, use default
            $resource_type = $this->smarty->default_resource_type;
            $resource_name = $template_resource;
        } else {
            // get type and name from path
            list($resource_type, $resource_name) = explode(':', $template_resource, 2);
            if (strlen($resource_type) == 1) {
                // 1 char is not resource type, but part of filepath
                $resource_type = 'file';
                $resource_name = $template_resource;
            } else {
                $resource_type = strtolower($resource_type);
            }
        }
    }


Loading the handler fails because $resource_type is now lowercase. It now tries to load $smarty->_plugins['resource']['mysqldb'].

Code:

$resource_handler = $this->loadTemplateResourceHandler($resource_type);


Or is there a reason why it has to be lowercase?

Regards,

Inno
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7367
Location: Lincoln Nebraska, USA

PostPosted: Thu Mar 04, 2010 3:05 pm    Post subject: Reply with quote

I know the autoloader requires filenames to be lower case. The classname can be any case. Is your resource loaded from a plugin file?
Back to top
View user's profile Send private message Visit poster's website
innocenzo
Smarty n00b


Joined: 04 Mar 2010
Posts: 4

PostPosted: Thu Mar 04, 2010 3:20 pm    Post subject: Reply with quote

I use the Smarty2 $smarty->register_resource() function.

Code:

$smarty->register_resource('mysqlDB', array(
                                'db_get_template',
                                'db_get_timestamp',
                                'db_get_secure',
                                'db_get_trusted')
                                );


After the Smarty 3 object called the internal method getResourceTypeName() the variable $resource_type is set to lowercase. A few lines later the method loadTemplateResourceHandler() uses $resource_type to lookup the handler. He doesn't find it because array keys are case sensitive.

Inno
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7367
Location: Lincoln Nebraska, USA

PostPosted: Thu Mar 04, 2010 3:30 pm    Post subject: Reply with quote

ok looks like a bug. we'll take a look.
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Mar 04, 2010 3:48 pm    Post subject: Reply with quote

The fix is in the SVN now
Back to top
View user's profile Send private message
innocenzo
Smarty n00b


Joined: 04 Mar 2010
Posts: 4

PostPosted: Thu Mar 04, 2010 4:30 pm    Post subject: Reply with quote

Thanks!

Inno
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3 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