[PHPTAL] PHPTAL tales syntax.
William Bailey
wb at pro-net.co.uk
Wed Apr 26 10:48:44 CEST 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160
Morning All,
I was just wondering if there was a specified restriction on the
tales syntax used in TAL. At the moment the tales syntax must match the
following regex:
/^([a-z][-._a-z]*[a-z]):(.*?)$/i
This is quite restrictive when you compare it with the rules
implemented by PHP for function, class and method names. Like not having
the ability to have numbers in your function, class and method names for
one.
If there is not specified restriction on tales syntax then i think
that it would be a good idea to allow users of PHPTAL to be able to
specify tales functions with the same flexibility allowed in PHP itself
with the exception of also allowing the '-' character and replacing it
with the '_' character as per the current implementation.
Attached is a patch that will implement the changes if its deemed
suitable.
As always comments/suggestions welcome. :)
- --
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
iD8DBQFETzPszSfrYDJMXmERA4NgAJ9W97I3/K5jdnbhie2z/pl4wlw29ACgxv20
LlxvLSfmDrMO93hnehLaggs=
=z0sj
-----END PGP SIGNATURE-----
-------------- next part --------------
Index: PHPTAL/classes/PHPTAL/Php/Tales.php
===================================================================
--- PHPTAL/classes/PHPTAL/Php/Tales.php (revision 286)
+++ PHPTAL/classes/PHPTAL/Php/Tales.php (working copy)
@@ -55,8 +55,10 @@
// Look for tales modifier (string:, exists:, etc...)
//if (preg_match('/^([-a-z]+):(.*?)$/', $expression, $m)) {
- if (preg_match('/^([a-z][-.a-z]*[a-z]):(.*?)$/i', $expression, $m)) {
- list(,$typePrefix,$expression) = $m;
+ //if (preg_match('/^([a-z][-._a-z]*[a-z]):(.*?)$/i', $expression, $m)) {
+ // list(,$typePrefix,$expression) = $m;
+ if (preg_match('/^([-a-zA-Z_\x7f-\xff][-a-zA-Z0-9_\x7f-\xff]*(\.[-a-zA-Z_\\x7f-\\xff][-a-zA-Z0-9_\\x7f-\\xff]*)?):(.*?)$/', $expression, $m)) {
+ list(,$typePrefix,,$expression) = $m;
}
// may be a 'string'
else if (preg_match('/^\'(.*?)\'$/', $expression, $m)) {
@@ -70,7 +72,7 @@
// class method
if (strpos($typePrefix, '.')){
- $classCallback = explode('.', $typePrefix, 2);
+ $classCallback = explode('.', str_replace('-','_',$typePrefix), 2);
$callbackName = NULL;
if(!is_callable($classCallback, FALSE, $callbackName)) {
$err = 'Unknown phptal modifier %s function %s does not exists or is not statically callable.';
More information about the PHPTAL
mailing list