Uncategorized 28 Nov 2007 06:10 pm
Property Files, CakePHP, and Agile Development
I have a personal goal to make my current cakephp project as agile as possible. With multiple developers and different dev/qa/production environments there are some challenges, especially when you want to automate builds and have each developer in control of their environment. Properties seemed like the natural solution and would eliminate database.php copying or having to worry about email and other specific settings. My goals here were:
1. All environment specific settings in one file
2. Let ant handle the deployment to dev/qa/production
The ant part was easy but I struggled to find the proper way of using “properties” with cake. I settled on the following:
There is a new directory at the top level called properties with these files:
/properties.php.dev
/properties.php.qa
/properties.php.prod
/properties.php.sample
These files contain all the specific values for each environment. During a deploy ant copies the correct one to the name properties.php. On your local machine you just rename properties.php.sample to properties.php and put in the values for your environment and never commit this to subversion.
This file is included in app/config/bootstrap.php so its available everywhere.
In the property file..I define the properties as constants so the naming convention is as follows
define(’PROPERTY_DBNAME’,'adatabase’);
define(’PROPERTY_DBUSER,’auser’);
This makes it easy to tell where these values are coming from. So far works a treat!
on 04 Dec 2007 at 2:46 pm 1.John said …
Rails accomplishes this by just having different environments in the database.yml file. I assume since Cake is a PHP-version of rails it probably sets CAKE_ENV which you can use to load the right environment .. no?
Have you given any thought to just using rails?
on 05 Dec 2007 at 12:07 pm 2.ben said …
Yeah you can use something similar in the database.php file, but I also have environment specific settings for an email server and will probably have others.
If i used the above approach wouldn’t these items be scattered about?
on 06 Dec 2007 at 1:59 am 3.John said …
I’m not up on Cake, so I’ll just use Rails as an example. Aside from the database connection defs, there is one master environment file that includes files for each defined environment, includes the file for the current environment I should say. So you basically have config > environment.rb and config > environments > ENV.rb … You set common settings in the master file and environment sensitive settings in the environment files. A lot like what you’re doing, but on the fly instead of during a build. It’s way agile since you no longer need a build step.
All of these files are pumped through the ERB handler first, which is basically like PHP for Ruby so you can actually modify them dynamically if you want, either during a deploy phase or on t he fly.
You might also look into Capistrano for deployments. It is so freaky how easy it makes it to deploy to a clustered environment, and I think folks are using it with PHP apps too. It’s written in Ruby, but then you’re using Java already …