Make feature defaults array private

[MAILPOET-2008]
This commit is contained in:
Jan Jakeš
2019-05-15 15:34:37 +02:00
committed by M. Shull
parent 9f194d8bc2
commit 5b4600193d
5 changed files with 71 additions and 63 deletions

View File

@ -12,7 +12,7 @@ class FeaturesController {
// Define feature defaults in the array below in the following form:
// self::FEATURE_NAME_OF_FEATURE => true,
public static $defaults = [
private $defaults = [
self::FEATURE_DISPLAY_WOOCOMMERCE_REVENUES => false,
];
@ -21,13 +21,23 @@ class FeaturesController {
/** @return bool */
function isSupported($feature) {
$this->ensureFlagsLoaded();
if (!array_key_exists($feature, $this->flags)) {
if (!$this->exists($feature)) {
throw new \RuntimeException("Unknown feature '$feature'");
}
$this->ensureFlagsLoaded();
return $this->flags[$feature];
}
/** @return bool */
function exists($feature) {
return array_key_exists($feature, $this->defaults);
}
/** @return array */
function getDefaults() {
return $this->defaults;
}
/** @return array */
function getAllFlags() {
$this->ensureFlagsLoaded();
@ -41,7 +51,7 @@ class FeaturesController {
$this->flags = [];
$flagsMap = $this->getValueMap();
foreach (self::$defaults as $name => $default) {
foreach ($this->defaults as $name => $default) {
$this->flags[$name] = isset($flagsMap[$name]) ? $flagsMap[$name] : $default;
}
}