Re: Error reporting info in compiled templates
boots <[email protected]>
| Newsgroups | gmane.comp.php.smarty.devel |
|---|---|
| Message-ID | <[email protected]> |
This seems like an interesting idea to me. Of course, it all depends on how it actually works out in the implementation but on the face of it, I can see its uses. I would expect that these operations would be optional, perhaps controlled via a class-member switch to minimize impact on production environments. Realistically, I'm not convinced that hooks like this are the best way to build debug symbol tables, but given the current options, it does seem like a reasonable approach especially since no one seems to have a better solution available atm. Aside: Something that may be worth considering is that this idea using hooks could possibly be generalized into an event model where Smarty defines certain events (compile_start, compile_end, etc) and users can register appropriate callbacks to handle these events much like the plugin system. FWIW, I'm tentatively +1 on this one xo boots --- Daniel BODEA <[email protected]> wrote: > Monte I already explained the basics. I'd have to provide the code to > clear things up completely but I'm trying to find out if the concept > is worth spending the time on code. > > I'll try to explain though in a couple of words one variant of the > code that could make this thing happen. > > Suppose the Smarty object defines two more variables in its class: > $running_template_stack and $running_plugin. The two are arrays. > > The template stack is used at the beginning and at the end of every > compiled template. At the beginning you push the template name onto > the stack and at the end you pop it out. The PHP code for this is > generated by the compiler upon compilation. > > The running plugin is used for generating the code of custom tags (at > first at least). You'd put a chunk of code similar to this one: > > echo '$this->running_plugin = array('.$this->_current_line_no.', > '.$tag_command.');'; > > in the compiler function for custom tags. The code gets tacked on to > every call for custom plugins. > > With this feature in place, one can create custom plugins that do > application specific things, and provided they need to report an > error to the designer that uses them, they can tell him exactly the > template, plugin call and line number where the error occurred in his > templates. With medium-to-highly complex templates, believe me it's > more than useful. > > Only the code is clearer than this I think so if it's still not clear > enough, I guess I'll have to code something up for my next message > but I hope to get some proof of interest before getting on to it. > > Daniel -- Smarty Development Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php