Hello,
 
Being unexpectedly struck by influenza with high temperature (40C) I remained at home and wrote the very first scratches of PHP tag libraries. It is strange that such an issue had not been discussed here in the past (or maybe I have missed the mails as I don't follow very regularly the list).
 
Below is a short example how it looks from the user's perspective (my explanations are unnecessary as the sample is quite self-explanatory):
 
test_newtag.php:
-----------------------
<?phptaglib location="newtag.ptd" ?>
 
<body>
<newtag></newtag>
</body>
-----------------------
newtag.ptd:
-----------------------
<?xml version="1.0" encoding="ISO-8859-1" ?>
 
<!DOCTYPE phptaglib SYSTEM "phptaglibrary.1.0.0.dtd">
 
<phptaglib>
    <lib location="newtag.php" />
    <phptag>
        <name>newtag</name>
        <class>NewTag</class>
    </phptag>
</phptaglib>
-----------------------
newtag.php:
-----------------------
<?php
class NewTag
{
    function doStartTag()
    {
        print("New Tag: start<br />\n");
    }
 
    function doEndTag()
    {
        print("New Tag: end<br />\n");
    }
}
?>
-----------------------
phptaglibrary.1.0.0.dtd (not really necessary here):
-----------------------
<!ELEMENT phptaglib (lib+, phptag+)>
<!ELEMENT lib EMPTY>
<!ATTLIST lib
          location CDATA #REQUIRED>
<!ELEMENT phptag (name, class)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT class (#PCDATA)>
-----------------------
output:
-----------------------
<body>
New Tag: start<br />
New Tag: end<br />
</body>
-----------------------
 
The implementation is quite straightforward - I have added new tokens and parser rule for the taglib declaration. Then the xml taglib description is parsed with expat and stored in hash together with the compiled PHP bytecode of the taglib includes. Finally the output is hooked, once again via the XML parser to substitute the custom tags with the output of the corresponding methods.
 
I have a lot of things to do (at least one week) before I will be able to post here fully working patches, however I want to hear what do you think.
 
Custom tag libraries are cool today and should be supported wherever is possible...
 
Best regards:
 
-- Alex

Reply via email to