Chris wrote:
Bruce Cowin wrote:
I'm curious as to how everyone organises and includes their classes in
PHP5. Let's take a simple example that has 3 classes: customer, order,
and database. The database class has a base sql db class (I know there
is PDO and other things but this class is already written and working)
and classes that inherit from the base class for dev, test, and prod,
passing the associated logins. The customer and order will both use the
appropriate database class depending on which environment its in (e.g.,
SalesDevDB, SalesTestDB, SalesProdDB).
I don't want to have to go into the customer and order class code and
change which db class it uses when I move it from dev to test and from
test to prod. What's the proper way to handle this? Or am I way off
base?
Could you just have 3 config files and use the appropriate one in each
environment?
The settings are in 'config.php'. When it's in dev:
cp dev.php config.php
when it's in test:
cp test.php config.php
I use a slightly different approach to prevent the need to mess about
with files when moving to production. At the end on config.php I have
this...
if (file_exists('config_dev.php'))
require 'config_dev.php';
In config_dev.php I override anything defined in config.php that needs
to be different on the current server. The config_dev.php file is *not*
in source control so it doesn't exist in production but each development
and test environment has a version that modifies the production environment.
There is a hit involved in the call to file_exists, but PHP caches it so
the effect is minimal.
-Stut
--
http://stut.net/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php