Creates, modifies or switches to an existing environment configuration. To create a new
configuration, or to update an existing configuration, pass an environment name and an array
that defines its configuration:
{{{
Environment::set('test', array('foo' => 'bar'));
}}}
You can then add to an existing configuration by calling the `set()` method again with the
same environment name:
{{{
Environment::set('test', array('baz' => 'qux'));
}}}
The settings for the environment will then be the aggregate of all `set()` calls:
{{{
$settings = Environment::get('test'); // returns array('foo' => 'bar', 'baz' => 'qux')
}}}
The `set()` method can also be called to manually set which environment to operate in:
{{{
Environment::set('development');
}}}
Finally, `set()` can accept a `Request` object, or the `$_SERVER` or `$_ENV` superglobals, to
automatically detect the correct environment.
{{{
Environment::set($request);
$isProduction = Environment::is('production');
}}}
For more information on defining custom rules to automatically detect your application's
environment, see the documentation for `Environment::is()`.
Parameters
- mixed $env The name of the environment you wish to create, update or switch to (string), or a `Request` object or `$_SERVER` / `$_ENV` array used to detect (and switch to) the application's current environment.
- array $config If creating or updating a configuration, accepts an array of settings. If the environment name specified in `$env` already exists, the values in `$config` will be recursively merged with any pre-existing settings.
Returns
array If creating or updating a configuration, returns an array of the environment's settings. If updating an existing configuration, this will be the newly-applied configuration merged with the pre-existing values. If setting the environment itself (i.e. `$config` is unspecified), returns `null`.Source
public static function set($env, $config = null) {
if (is_null($config)) {
switch (true) {
case is_object($env) || is_array($env):
static::$_current = static::_detector()->__invoke($env);
break;
case isset(static::$_configurations[$env]):
static::$_current = $env;
break;
}
return;
}
$env = ($env === true) ? static::$_current : $env;
$base = isset(static::$_configurations[$env]) ? static::$_configurations[$env] : array();
return static::$_configurations[$env] = Set::merge($base, $config);
}