Definitely interesting.  We probably would want to make it flexible
enough to handle any number constants on the same line.  (your code
makes us *more* flexible than we are, but that next step would "finish
out" the problem).  Feel free to modify it as necessary, or I'll take
a look when I get a free second and propose the solution to the list.

Thanks!
--Bob

On 9/2/05, Johan Mjönes <[EMAIL PROTECTED]> wrote:
> Hello!
> 
> While we're using agavi, we'd like to autoload certain of our own
> classes which will reside outside any of the lib directories normally
> used by the webbapps. Since we'd like to autoload classes (persistance
> classes mostly), we'd very much like to use constants (set up in
> config.php) pointing to the base directory of our libs.
> 
> However, the replaceConstants() method in the ConfigHandler class
> contains an array of constants to be replaced, which does not allow us
> to use our own specified constants.
> 
> I have alterted the replaceConstants method to replace every constant
> (as defined by %CONSTANT_NAME%) if the constant is defined, otherwise it
> will be left as it was.
> 
> Is this interesting to the Agavi community?
> 
> This is my replaceConstants():
> 
>     public static function & replaceConstants ($value)
>     {
> 
>         $value = preg_replace_callback(
>             '/\%(\w+?)\%/',
>             create_function(
>                 '$match',
>                 '$constant = $match[1]; ' .
>                 'return (defined($match[1]) ? constant($constant) :
> "%".$constant."%");'),
>                 $value,
>                 1);
> 
>         return $value;
>     }
> 
> Please note that it limits the number of constants to one per line
> (iterating the preg_replace_callback(...) can be done if multiple
> constants are used in the same value).
> 
> Best Regards,
> 
> Johan Mjönes
> 
> --
> Johan Mjönes
> Programmer
> Phone: +46 8 789 12 00
> Fax: +46 8 789 12 12
> Cell: +46 7 052 838 55
> E-mail: [EMAIL PROTECTED]
> Internet: www.ongame.com
> 
> 
> This e-mail (including attachments) is strictly confidential and intended 
> solely for designated recipient(s). It contains privileged and confidential 
> information. If you have received this e-mail in error, you must not 
> disseminate, copy, distribute or take any action in reliance on it. Please 
> notify us immediately and delete this e-mail and any attachments. Thank you.
> 
> _______________________________________________
> agavi-dev mailing list
> [email protected]
> http://labworkz.com/cgi-bin/mailman/listinfo/agavi-dev
>
_______________________________________________
agavi-dev mailing list
[email protected]
http://labworkz.com/cgi-bin/mailman/listinfo/agavi-dev

Reply via email to