While those three environments are the most common, you can create any arbitrary environment
with any set of configuration, for example:
{{{
Environment::set('production', array('foo' => 'bar'));
Environment::set('staging', array('foo' => 'baz'));
Environment::set('development', array('foo' => 'dib'));
}}}
You can then retrieve the configurations using the key name. The correct configuration is
returned, automatically accounting for the current environment:
{{{
$foo = Environment::get('foo'); // returns 'dib', since the current env. is 'development'
}}}
`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](http://memcached.org/) 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()`.