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

Extending Smarty_Internal_Resource_File with my own behavior

 
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 -> General
View previous topic :: View next topic  
Author Message
scuzzy
Smarty Regular


Joined: 31 Aug 2003
Posts: 84

PostPosted: Thu May 10, 2018 1:06 am    Post subject: Extending Smarty_Internal_Resource_File with my own behavior Reply with quote

I know extending an "internal" class like "Smarty_Internal_Resource_File" is not ideal when "Smarty_Resource_Custom" exists.

However, I want to use 99% of the aspects of this class and change one minor thing by wrapping the parent method.

Code:
class MyFileResource extends Smarty_Internal_Resource_File
{
  // literally nothing but the extends
}
$smarty->registerResource( 'myfile', new MyFileResource() );
$smarty->default_resource_type = 'myfile';


Now my problem is, if I try to have a relative template {include file="../foo.tpl"} I will get an error in the following code...

Code:
            if ($_template->parent->source->type !== 'file' && $_template->parent->source->type !== 'extends' &&
                !isset($_template->parent->_cache[ 'allow_relative_path' ])
            ) {
                throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'");
            }


as $_template->parent->source->type is now "myfile" and not "file" even though my class extends Smarty_Internal_Resource_File

Anyone have suggestions on how to set allow_relative_path to be true without needing to duplicate function buildFilepath()?

Thank you.


Last edited by scuzzy on Thu May 10, 2018 1:18 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
scuzzy
Smarty Regular


Joined: 31 Aug 2003
Posts: 84

PostPosted: Thu May 10, 2018 1:12 am    Post subject: Reply with quote

I have noticed that in an older version of smarty "allow_relative_path" is referenced multiple times, but now it only appears once?

Using: 3.1.32, Compared it to 3.1.27 (3.1.28 removed two of three references)
Back to top
View user's profile Send private message Visit poster's website
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri May 11, 2018 12:35 pm    Post subject: Reply with quote

This is why you do not extend internal classes.
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 -> General 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