2019-02-14 22:07:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\EnvironmentCheck\Checks;
|
|
|
|
|
|
|
|
use SilverStripe\Control\Director;
|
|
|
|
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether the environment setting is safe. Useful for live sites where a
|
|
|
|
* non "Live" setting might disclose sensitive information.
|
|
|
|
*
|
|
|
|
* @package environmentcheck
|
|
|
|
*/
|
|
|
|
class EnvTypeCheck implements EnvironmentCheck
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Check the environment setting.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2019-02-14 22:32:13 +01:00
|
|
|
public function check()
|
2019-02-14 22:07:05 +01:00
|
|
|
{
|
|
|
|
$envSetting = Director::get_environment_type();
|
|
|
|
switch ($envSetting) {
|
|
|
|
case 'live':
|
|
|
|
return [
|
|
|
|
EnvironmentCheck::OK,
|
|
|
|
"Env setting is 'live'",
|
|
|
|
];
|
|
|
|
// Fallthrough
|
|
|
|
default:
|
|
|
|
case 'dev':
|
|
|
|
case 'test':
|
|
|
|
return [
|
|
|
|
EnvironmentCheck::ERROR,
|
|
|
|
"Env setting is '{$envSetting}' and may disclose information",
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|