// Import SPL stuff
use \InvalidArgumentException;
+use \UnexpectedValueException;
/**
* A class for the configuration stuff implemented in a singleton design pattern
//* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
}
+ /**
+ * Checks if a configuration entry is_*_enabled set to 'Y'
+ *
+ * @param $keyPart Configuration to expand with is_$keyPart_enabled
+ * @return $enabled Whether it has been set to Y or N
+ * @throws InvalidArgumentException If a parameter is invalid
+ * @throws UnexpectedValueException If a returned value is of an unexpected type or value
+ */
+ public function isEnabled (string $keyPart) {
+ // Validate parameters
+ //* NOISY-DEBUG: */ printf('[%s:%d]: keyPart=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $keyPart);
+ if (empty($keyPart)) {
+ // Entry is empty
+ throw new InvalidArgumentException('Parameter "keyPart" is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
+ }
+
+ // Construct final config key
+ $configKey = sprintf('is_%s_enabled', $keyPart);
+
+ // Get value from it
+ //* NOISY-DEBUG: */ printf('[%s:%d]: configKey=%s' . PHP_EOL, __METHOD__, __LINE__, $configKey);
+ $isEnabled = $this->getConfigEntry($configKey);
+
+ // Is it Y/N?
+ //* NOISY-DEBUG: */ printf('[%s:%d]: isEnabled[]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype($isEnabled));
+ if (!is_bool($isEnabled)) {
+ // Throw exception
+ throw new UnexpectedValueException(sprintf('isEnabled[]=%s is unexpected', gettype($isEnabled)));
+ }
+
+ // Return it
+ //* NOISY-DEBUG: */ printf('[%s:%d]: isEnabled=%d - EXIT!' . PHP_EOL, __METHOD__, __LINE__, intval($isEnabled));
+ return $isEnabled;
+ }
+
/**
* Generates a code for hashes from this class
*