Environments
The support of environments helps FuelPHP and your app to make decisions based on the environment setting. FuelPHP itself uses the environment setting to load/overwrite additional config setting based on which environment is currently active.
Environments list
FuelPHP has four predefined environments.
-
\Fuel::DEVELOPMENT
The development environment. -
\Fuel::TEST
The test environment. -
\Fuel::STAGE
The staging environment. -
\Fuel::PRODUCTION
The production environment.
Set Your Environment
Setting your environment is done by setting the FUEL_ENV server var or manually changing the setting in fuel/app/bootstrap.php.
// Inside app/bootstrap.php
/**
* Your environment. Can be set to any of the following:
*
* Fuel::DEVELOPMENT
* Fuel::TEST
* Fuel::STAGE
* Fuel::PRODUCTION
*/
Fuel::$env = (isset($_SERVER['FUEL_ENV']) ? $_SERVER['FUEL_ENV'] : Fuel::DEVELOPMENT);
Environments and Config
Based on the environment the app is set to, the Config class looks for environment-specific config files. The config class will look for the same config file name in a directory that's named after the current environment. Here is an example to illustrate this:
app/
config/
stuff.php
development/
stuff.php
production/
stuff.php
When your environment is set to \Fuel::DEVELOPMENT, the settings from stuff.php are merged with development/stuff.php. If the environment setting is set to any other than \Fuel::DEVELOPMENT, the extra config file is not loaded. The same goes for any other environment setting you might use.
A real-life example for this is the database configuration. There are no default configuration settings (this is possibly very dangerous). There are only environment-specific config settings.