appConstants Mach-II plugin
This plugin allows you to have a different set of application constants for each server running your Mach-II application. This is really useful if you are using version control and each developer is running the application on their local machine.
If you’re looking for a PHP version of this plugin, you can get one from Dave Spurr’s blog.
Note: this plugin requires version 1.0.10 of the Mach-II core files (although it can be modified to work with 1.0.9).
Place appConstants.cfc in the MachII plugins folder. Place this in the Mach-II configuration file:
<plugin name="appConstants" type="MachII.plugins.appConstants" />
or
<plugin name="appConstants" type="MachII.plugins.appConstants">
<parameters>
<parameter name="constantsFile" value="path_to_constants_file" />
</parameters>
</plugin>
The constantsFile optional parameter should be a path to your constants XML file relative to your application root (set in the properties section of your configuration file). It defaults to “/config/constants.xml”.
The constants XML file should follow the following format:
<?xml version="1.0" encoding="utf-8"?>
<constants>
<common>
<constant name="constant_name_1" value="constant_value_1" />
<constant name="constant_name_2" value="constant_value_2" />
...
<property name="property_name_1" value="property_value_1" />
...
</common>
<server name="your_dev_server_name">
<constant name="constant_name_1" value="constant_value_1" />
<constant name="constant_name_2" value="constant_value_2" />
...
<property name="property_name_1" value="property_value_1" />
...
</server>
<server name="your_testing_server_name">
<constant name="constant_name_1" value="constant_value_1" />
<constant name="constant_name_2" value="constant_value_2" />
...
<property name="property_name_1" value="property_value_1" />
...
</server>
<server name="your_live_server_name">
<constant name="constant_name_1" value="constant_value_1" />
<constant name="constant_name_2" value="constant_value_2" />
...
<property name="property_name_1" value="property_value_1" />
...
</server>
</constants>
You will have access to the constants set up in the server section of the constants file that corresponds to the server currently running your application as well as all constants in the common block (common constant values are overwritten by server block values).
You can also specify a comma separated list of server names for a single server section (useful if several domains point to the same application).
All constants are placed in a structure named appConstants that you can access as a Mach-II property.
You can also set Mach-II properties with the property tag. These properties will overwrite any existing Mach-II properties.
Note: You can use this plugin for a single server setup. Place all your constants in the common block and don’t bother with any server blocks.
October 11th, 2006 at 4:22 pm
Martin,
thanks for the quick reply. My flex application is mostly framwork agnostic, so it doesn’t invoke Mach-ii unless I run it through a Gateway that does extend the listener. Hence the constant problem of getting global variables exposed.
I’ll play around with it some more and if I find a way I will post it here.. thanks again for this very useful plugin.
Kai