How can you get access to ant build properties in a PHP-based project?
I'm us开发者_如何学JAVAing ant to copy files and download libraries to package our release for deployment. I was wondering if there was a way I could use build properties to generate maybe some config.php files to be used by the system. Any thoughts on how this can be done with ant?
You could write a script that generates the config.php and use ant to execute the script
I haven't actually done something like that before but it sounds interesting. I'd suggest maybe using some sort of template (could be a php file itself, or an ini file).
Could this be done better with an ini file? I believe they would be easier to generate, and php can read them fairly easily.
Read using http://it.php.net/manual/en/function.parse-ini-file.php and if you look in the comments there are some examples of writing ini file.
So your script could read the ini file for the template, then make changes according to arguments passed to the script, and save the config.ini where necessary (or config.php if you want to take the generating php file path).
Ant task something like below (forgive me its badly written, I'm not an ant expert)
<target name="generateConfig">
<exec executable="php">
<arg value="generateConfig.php" />
</exec>
</target>
I suggest you use a template configuration file, and use the Replace Ant Task:
<replace file="${src}/path/to/config.php">
<replacefilter token="%db_host%" value="my_db_host"/>
<replacefilter token="%db_user%" value="some_user"/>
</replace>
精彩评论