12-24-2019, 02:16 PM
Hello guys,
I was thinking of a simple way to change between supported framework environments, so i made this.
Step 1: we need to configure environment via \Config\App at App/Config/App.php file:
Step 2: we should add default supported environments list in system\CodeIgniter.php file:
Step 3: we have to edit some codes to make it work as expected, search for detectEnvironment() function in system\CodeIgniter.php file:
Thats all for me, I'm new in php world so I don't know what are the consequences.
I was thinking of a simple way to change between supported framework environments, so i made this.
Step 1: we need to configure environment via \Config\App at App/Config/App.php file:
PHP Code:
<?php namespace Config;
use CodeIgniter\Config\BaseConfig;
class App extends BaseConfig
{
/**
| You can load different configurations depending on your
| current environment. Setting the environment also influences
| things like logging and error reporting.
|
| This can be set to anything, but supported usage are:
|
| development
| testing
| production
*/
public $environment = 'development';
Step 2: we should add default supported environments list in system\CodeIgniter.php file:
PHP Code:
<?php namespace CodeIgniter;
class CodeIgniter
{
protected $environment = [
'development',
'testing',
'production'
];
Step 3: we have to edit some codes to make it work as expected, search for detectEnvironment() function in system\CodeIgniter.php file:
PHP Code:
protected function detectEnvironment()
{
// Make sure ENVIRONMENT isn't already set by other means.
if (! defined('ENVIRONMENT'))
{
// running under Continuous Integration server?
if (getenv('CI') !== false)
{
define('ENVIRONMENT', 'testing');
}
else
{
$config = new \Config\App;
if (! in_array($config->environment, $this->environment))
{
die("The application environment <span style='color:red'>{$config->environment}</span> is not supported, currently supported enviroments are: " . implode(", ",$this->environment) . '.');
}
define('ENVIRONMENT', $_SERVER['ENVIRONMENT'] ?? $config->environment);
}
}
}
Thats all for me, I'm new in php world so I don't know what are the consequences.