[Phpmyadmin-devel] PHP3: $function()?

Robin Johnson robbat2 at orbis-terrarum.net
Tue Feb 4 22:50:03 CET 2003


On Wed, Feb 05, 2003 at 04:10:00AM +0100, Garvin Hicking wrote:
> I today finished the JavaScript popup SQL query window (nice term ;-)  
> which works quite nicely. Think you will pretty much like it. :)
Great, post up the patch for us to play with please!

> Is variable function calling possible in this version? Something like  
> $queryfunction($string)?
I'm fairly certain that $func() works, based on the fact we use it in
libraries/common.lib.php3. Look for '$connect_func'.

> It's because I'm implementing something like a transformation-plugin  
> directory. Every php file is a transformation on its own with a specific  
> filename. Inside the file the function should be called like the filename,  
> so I would like to do the following:
> 
> 1. Find out the mimetype and transformation for a field
> 2. Search for the php-file which contains the transformation
> 3. Include that file
> 4. Because multiple plugins can be called on a single page, a single  
> function name is not possible. So I now want to call the included function  
> with $transformation($buffer, $options).
Some hints/suggestions...

Lets think about this, firstly, based on the mime-type definition...

Valid mimetype strings are in the form of:
(RFCs 2045, 2046, 2047, 2048, and 2077)
content := "Content-Type" ":" type "/" subtype *(";" parameter)
        ; case-insensitive matching of type and subtype
type := "application" / "audio"
        / "image" / "message"
        / "multipart" / "text"
        / "video" / extension-token
        ; All values case-insensitive
extension-token :=  x-token / iana-token
iana-token := <a publicly-defined extension token, registered with IANA, as
               specified in Appendix E>
x-token := <The two characters "X-" or "x-" followed, with no intervening white
            space, by any token>
subtype := token ; case-insensitive
parameter := attribute "=" value
attribute := token   ; case-insensitive
value := token / quoted-string
token  :=  1*<any (ASCII) CHAR except SPACE, CTLs,
              or tspecials>
tspecials :=  "(" / ")" / "<" / ">" / "@"
           /  "," / ";" / ":" / "\" / <">
           /  "/" / "[" / "]" / "?" / "="
          ; Must be in quoted-string,
          ; to use within parameter values

We should EXPECT that some users will (ab)use the defintion of mime-types to the fullest extent possible
and so we should be ready to handle all options, like:
application/octet-stream
text/plain; charset=us-ascii
application/beep+xml
text/plain; charset="us-ascii"
application/vnd.pwg-xhtml-print+xml
model/mesh; dimension="4"; state="static"

In the above, note the exclusion of '_'. AFAIK, there exists NO mimetype with that in it.
I propose that you have a PMA_transform function as follows (using the last example):
Firstly:
$mimearray = array( '_type' => 'model', '_subtype' => 'mesh', 'dimension' => '4', 'state' => 'static');
Note that the type/subtype have got seperate items, and then each MIME
parameter is included in an exact name-value mapping.
$outputdata = PMA_transform($mimearray, $parameters, $input);
$parameter is the additional parameters from the column comments table.

Now in your code that actually handles the transformation:
function PMA_transform($mimearray, $parameters, $input) {
...
include($dir.'/'.$mimearray['_type'].'.inc.php3');
include($dir.'/'.$mimearray['_type'].'_'.$mimearray['_subype'].'.inc.php3');
...
}

Each of those files defines a single function as you suggested
in the name form of:
PMA_transform_$mimearray['_type']_$mimearray['_subtype']($mimeparameters,$funcparameters,$inputdata);
To get around the problem of '+' existing in type names, replace any
non-acceptable characters with '_'.  There will be _very_ little namespace
collision caused by that replacement.

Each of the files should have our if(!defined(...)) { /* contents */ } type blocks
for speed reasons and avoiding errors.

-- 
Robin Hugh Johnson
E-Mail     : robbat2 at orbis-terrarum.net
Home Page  : http://www.orbis-terrarum.net/?l=people.robbat2
ICQ#       : 30269588 or 41961639
GnuPG FP   : 11AC BA4F 4778 E3F6 E4ED  F38E B27B 944E 3488 4E85
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: <http://lists.phpmyadmin.net/pipermail/developers/attachments/20030204/94fad8b4/attachment.sig>


More information about the Developers mailing list