Hi,

back in 01/2007 I requested a feature[1][2] for an addExtensions callback for 
the Template engine. :-)

The actual addExtension method provides informations, which are necessary AT 
COMPILE TIME, as there are:

$class $method $hasCloseTag $startExpressionName $optionalParameters 
$requiredParameters $isStatic

After the template is compiled, the custom function ends up as an ordinary PHP 
function call. The template component does not use any of the informations 
provided by addExtension to execute the compiled template.

So we could add an option "addExtensionsCallback", which contains a callback 
to ONE function. This callback function is only called once during a 
template->process call and does not have any parameters. It should add all 
extensions to the template engine, which are known in my application.

Since the callback is only executed, when a template needs to be compiled, 
which is rare, the callback is free to take a long time. So I could search in 
all my eZP extension dirs for extensions and add them.

If I'd use the template component as it is know to include it in eZP, then I'd 
need to register a large amount of extensions for every PHP request.

An experimental implementation is attached as diff. The called function gets 
the configuration object to call the addExtension method on it. The idea is 
in fact similiar to the lazy initialization.

[1] http://lists.ez.no/pipermail/components/2007-January/002182.html
[2] http://issues.ez.no/IssueView.php?Id=10117&ProjectId=1
-- 
Thomas Koch, Software Developer
http://www.koch.ro

Young Media Concepts GmbH
Sonnenstr. 4
CH-8280 Kreuzlingen
Switzerland

Tel    +41 (0)71 / 508 24 86
Fax    +41 (0)71 / 560 53 89
Mobile +49 (0)170 / 753 89 16
Web    www.ymc.ch
Index: template.php
===================================================================
--- template.php	(Revision 8369)
+++ template.php	(Arbeitskopie)
@@ -110,6 +110,7 @@
                                  'astTree' =>  false,
                                  'stream'  => false,
                                  'streamStack' => false,
+                                 'addExtensionsCallback' => null,
                                  'output' => "",
                                );
 
@@ -133,6 +134,7 @@
             case 'streamStack':
             case 'compiledTemplatePath':
             case 'usedConfiguration':
+            case 'addExtensionsCallback':
 
             case 'output':
                 return $this->properties[$name];
@@ -174,6 +176,7 @@
             case 'astTree':
             case 'stream':
             case 'streamStack':
+            case 'addExtensionsCallback':
             case 'output':
                 return isset( $this->properties[$name] );
             default:
@@ -211,6 +214,10 @@
                 $this->properties[$name] = $value;
                 break;
 
+            case 'addExtensionsCallback':
+                $this->properties[$name] = $value;
+                break;
+
             case 'tstTree':
             case 'astTree':
             case 'compiledTemplatePath':
@@ -324,6 +331,12 @@
                 }
             }
 
+            if( 1 === $counter )
+            {
+                call_user_func( $this->properties['addExtensionsCallback'],
+                                $config );
+            }
+
             $this->createDirectory( dirname( $compiled->path ) );
 
             // get the compiled path.
-- 
Components mailing list
Components@lists.ez.no
http://lists.ez.no/mailman/listinfo/components

Reply via email to