mirror of
https://github.com/silverstripe/silverstripe-environmentcheck
synced 2024-10-22 17:05:40 +02:00
NEW: Environment type check.
This commit is contained in:
parent
f6652c2b37
commit
1771a6ef11
40
src/Checks/EnvTypeCheck.php
Normal file
40
src/Checks/EnvTypeCheck.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?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
|
||||
*/
|
||||
public function check() : array
|
||||
{
|
||||
$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",
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user