While those three environments are the most common, you can create any arbitrary environment
with any set of configuration, for example:
embed:lithium\tests\cases\core\EnvironmentTest::testSetAndGetCurrentEnvironment(1-3)
You can then retrieve the configurations using the key name. The correct configuration is
returned, automatically accounting for the current environment:
embed:lithium\tests\cases\core\EnvironmentTest::testSetAndGetCurrentEnvironment(15-15)
Environment also works with subclasses of Adaptable, allowing you to maintain separate
configurations for database servers, cache adapters, and other environment-specific classes, for
example:
Connections::add('default', array(
'production' => array(
'type' => 'database',
'adapter' => 'MySql',
'host' => 'db1.application.local',
'login' => 'secure',
'password' => 'secret',
'database' => 'app-production'
),
'development' => array(
'type' => 'database',
'adapter' => 'MySql',
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'app'
)
));
This allows the database connection named 'default' to be connected to a local database in
development, and a production database in production. You can define environment-specific
configurations for caching, logging, even session storage, i.e.:
Cache::config(array(
'userData' => array(
'development' => array('adapter' => 'File'),
'production' => array('adapter' => 'Memcache')
)
));
When the cache configuration is accessed in the application's code, the correct configuration is
automatically used:
$user = User::find($request->id);
Cache::write('userData', "User.{$request->id}", $user->data(), '+5 days');
In this configuration, the above example will automatically send cache writes to the file
system during local development, and to a memcache server in production.
When writing classes that connect to other external resources, you can automatically take
advantage of environment-specific configurations by extending Adaptable and implementing
your resource-handling functionality in adapter classes.
In addition to managing your environment-specific configurations, Environment will also help
you by automatically detecting which environment your application is running in. For additional
information, see the documentation for Environment::is().