Exemplo n.º 1
0
 public function testWhichEnvironmentWithRegEx()
 {
     $locations = ['local' => '*.themosis.dev', 'production' => '*.aws.elastic456278s9d.com', 'staging' => 'xyz\\..+\\.net', 'custom' => 'my-hostname'];
     $env = new Thms\Config\Environment($locations);
     $this->assertEquals('local', $env->which('server001.themosis.dev'));
     $this->assertEquals('local', $env->which('abcserver3578sdd67.themosis.dev'));
     $this->assertEquals('production', $env->which('us2-467.aws.elastic456278s9d.com'));
     $this->assertEquals('staging', $env->which('xyz.some-name.net'));
     $this->assertEquals('staging', $env->which('xyz.another_name215658.net'));
     $this->assertEquals('custom', $env->which('my-hostname'));
     $locations = ['local' => ['host-one', '*.themosis.net', 'eu-2_3-xyz.aws.com']];
     $env = new Thms\Config\Environment($locations);
     $this->assertEquals('local', $env->which('host-one'));
     $this->assertEquals('local', $env->which('host-one.themosis.net'));
     $this->assertEquals('local', $env->which('eu-2_3-xyz.aws.com'));
 }
Exemplo n.º 2
0
if (file_exists($file = $root_path . DS . 'config' . DS . 'environment.php')) {
    $environments = (require_once $file);
}
// Check if there are environment values
if (empty($environments) || !is_array($environments) && !$environments instanceof \Closure) {
    printf('<h1>%s</h1>', 'Unable to load environment data. Please define your environments.');
}
/*----------------------------------------------------*/
// Set environment
/*----------------------------------------------------*/
// Define path and the environment locations.
$env = new Thms\Config\Environment($root_path . DS, $environments);
/*----------------------------------------------------*/
// Load .env file
/*----------------------------------------------------*/
$location = $env->which();
if (empty($location)) {
    printf('<h1>%s</h1>', 'Unable to define the environment.');
}
$loaded = $env->load($location);
if (empty($loaded)) {
    printf('<h1>%s</h1>', 'Unable to locate your environment configuration file.');
}
/*----------------------------------------------------*/
// Check required vars.
/*----------------------------------------------------*/
$check = $env->check(['DB_NAME', 'DB_USER', 'DB_PASSWORD', 'DB_HOST', 'WP_HOME', 'WP_SITEURL'], $loaded);
/*----------------------------------------------------*/
// Populate environment vars
/*----------------------------------------------------*/
if ($check) {
Exemplo n.º 3
0
if (file_exists($file = $root_path . DS . 'config' . DS . 'environment.php')) {
    $environments = (require_once $file);
}
// Check if there are environment values
if (empty($environments) || !is_array($environments) && !$environments instanceof \Closure) {
    printf('<h1>%s</h1>', 'Unable to load environment data. Please define your environments.');
}
/*----------------------------------------------------*/
// Set environment
/*----------------------------------------------------*/
// Define path and the environment locations.
$env = new Thms\Config\Environment($root_path . DS, $environments);
/*----------------------------------------------------*/
// Load .env file
/*----------------------------------------------------*/
define('ENVIRONMENT', $env->which());
if (!defined('ENVIRONMENT') || !ENVIRONMENT) {
    printf('<h1>%s</h1>', 'Unable to define the environment.');
}
$loaded = $env->load(ENVIRONMENT);
if (empty($loaded)) {
    printf('<h1>%s</h1>', 'Unable to locate your environment configuration file.');
}
/*----------------------------------------------------*/
// Check required vars.
/*----------------------------------------------------*/
$check = $env->check(array('DB_NAME', 'DB_USER', 'DB_PASSWORD', 'DB_HOST', 'WP_HOME', 'WP_SITEURL'), $loaded);
/*----------------------------------------------------*/
// Populate environment vars
/*----------------------------------------------------*/
if ($check) {