suggested mod to resource plugin design in smarty
| From: | Lee Coltrane | Date: | Wed, 09 Oct 2002 22:17:10 +0000 |
| Subject: | suggested mod to resource plugin design in smarty | ||
| Groups: | php.smarty.dev | ||
| Request: | Send a blank email to php-smarty-dev+get-290@lists.php.net to get a copy of this message | ||
Hi-
I've been enjoying working with smarty. It seems to be pretty well
put together. I wanted to say "thanks".
I tried to send the following to monte@php.net - as suggested on the
smarty web site, but that address was bounced by "MAILER-DAEMON@php.net", so
I'm sending to the list instead...
I've made some modifications to smarty to support a more
full-featured resource plugin interface. The primary reason for these
changes was, initially, to allow the resource plugin to set the compile-id
*before* smarty went looking for the cache and the compiled file. This was
important in my application, because I wanted to write a resource that could
load templates using a hierarchy of template dirs that changed based on
application state. In my case, it was possible to have many different
templates, each called "widget.tpl", that lived in different directories,
and were rendered by different components at different times during the
request, all using the same smarty object.
To facilitate this I have made the following changes to smarty in my
installation:
**1) The resource plugin interface of smarty can now support an additional
design for resource plugins. The old (4 functions) way is still supported,
but I have upfit smarty to understand a new paradigm that uses a PHP class
for the plugin definition. This allows the plugin to maintain state, as
well as to be extended rather seamlessly.
**2) When smarty attempts to load a template (or a php file) through the new
resource loader, the resource plugin simply returns a resource_handle object
instance that is specific to the requested template name. This object
encapsulates all further interaction with the underlying template of that
name. This allows the resource plugin to delay loading the source for the
file, until it is really needed (without any confusing boolean flags to pass
around). It also allows the resource plugin to cache resource_handles if it
so desires, to further speed template retrieval.
**3) There were a number of places where smarty was making multiple queries
to the resource plugin for information about a single template, rather than
just asking once, and then reusing the data. The number of areas where this
happens has been reduced. This was accomplished by passing around the
resource_handle instead of passing around a template name string. Since the
resource_handle encapsulates the actual resource item, every function that
receives a resource_handle has easy, quick access to all the information
regarding the underlying item. This also resulted in a considerable amount
of coincidental code-cleanup in a couple of places.
**4) I think that all this was done without breaking any external interfaces
on the smarty object.
I can easily send any source (including the changed smarty source, example
of a "new-style" resource class, and/or example of a template that uses the
resource) if anyone is interested.
If you think this would be a useful mod to roll back into the smarty main
tree, I would be glad to do that in a couple of weeks when I get the time.
I just need who ever is in charge (Monte?) to give the go-ahead, and point
me at the right place to make the changes. There are a number of comments,
and a bit of documentation that I would need to write before I'd be ok
releasing it on any large scale to anyone other than myself. ;-)
thanks for your time,
-Lee Coltrane
lee@trifolium.com