lithium\core\Environment::set PHP Метод

set() публичный статический Метод

You can then add to an existing configuration by calling the set() method again with the same environment name: embed:lithium\tests\cases\core\EnvironmentTest::testModifyEnvironmentConfig(6-6) The settings for the environment will then be the aggregate of all set() calls: embed:lithium\tests\cases\core\EnvironmentTest::testModifyEnvironmentConfig(7-7) By passing an array to $env, you can assign the same configuration to multiple environments: embed:lithium\tests\cases\core\EnvironmentTest::testSetMultipleEnvironments(5-7) The set() method can also be called to manually set which environment to operate in: embed:lithium\tests\cases\core\EnvironmentTest::testSetAndGetCurrentEnvironment(5-5) Finally, set() can accept a Request object, to automatically detect the correct environment. embed:lithium\tests\cases\core\EnvironmentTest::testEnvironmentDetection(9-10) For more information on defining custom rules to automatically detect your application's environment, see the documentation for Environment::is().
См. также: lithium\action\Request
См. также: lithium\core\Environment::is()
public static set ( mixed $env, array $config = null ) : array
$env mixed The name(s) of the environment(s) you wish to create, update or switch to (string/array), or a `Request` object or `$_SERVER` / `$_ENV` array used to detect (and switch to) the application's current environment.
$config array 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.
Результат 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`.
    public static function set($env, $config = null)
    {
        if ($config === null) {
            if (is_object($env) || is_array($env)) {
                static::$_current = static::_detector()->__invoke($env);
            } elseif (isset(static::$_configurations[$env])) {
                static::$_current = $env;
            }
            return;
        }
        if (is_array($env)) {
            foreach ($env as $name) {
                static::set($name, $config);
            }
            return;
        }
        $env = $env === true ? static::$_current : $env;
        $base = isset(static::$_configurations[$env]) ? static::$_configurations[$env] : array();
        return static::$_configurations[$env] = Set::merge($base, $config);
    }

Usage Example

 public function testEnvironmentalDefaults()
 {
     $artist = Artists::create(['ja.name' => 'Richard Japper', 'ja.profile' => 'Dreaded Rasta Nihon', 'en.name' => 'Richard', 'en.profile' => 'Dreaded Rasta', 'something_else' => 'Something']);
     Environment::set('test', ['locales' => ['en' => 'English', 'es' => 'Espanol']]);
     $artist->_actsAs = ['Translatable' => ['default' => 'ja', 'fields' => ['name', 'profile']]];
     $this->assertTrue($artist->save());
     $artist = Artists::first();
 }
All Usage Examples Of lithium\core\Environment::set