namespace Org\Mxchange\CoreFramework\Configuration;
// Import framework stuff
+use Org\Mxchange\CoreFramework\Configuration\NoConfigEntryException;
use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
-use Org\Mxchange\CoreFramework\Generic\NullPointerException;
use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
use Org\Mxchange\CoreFramework\Registry\Registerable;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
// Import SPL stuff
use \InvalidArgumentException;
* @see ClassLoader
* @author Roland Haeder <webmaster@shipsimu.org>
* @version 1.0.1
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.shipsimu.org
*
* hard-coded configuration data and might be overwritten/extended by
* config data from the database.
*/
- private static $config = array();
+ private static $config = [];
/**
* Call-back instance (unused)
*
* @param $configKey The configuration key we shall check
* @return $isset Whether the given configuration key is set
- * @throws NullPointerException If $configKey is NULL
* @throws InvalidArgumentException If $configKey is empty
*/
- public function isConfigurationEntrySet ($configKey) {
+ public function isConfigurationEntrySet (string $configKey) {
// Is it null?
- if (is_null($configKey)) {
- // Throw NPE
- throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER);
- } elseif (!is_string($configKey)) {
- // Is not a string
- throw new InvalidArgumentException(sprintf('configKey[]=%s is not a string', gettype($configKey)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
- } elseif ((is_string($configKey)) && (empty($configKey))) {
+ if (empty($configKey)) {
// Entry is empty
throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
}
*
* @param $configKey The configuration element
* @return $configValue The fetched configuration value
- * @throws NullPointerException If $configKey is NULL
* @throws InvalidArgumentException If $configKey is empty
* @throws NoConfigEntryException If a configuration element was not found
*/
- public function getConfigEntry ($configKey) {
+ public function getConfigEntry (string $configKey) {
// Is it null?
- if (is_null($configKey)) {
- // Throw NPE
- throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER);
- } elseif (!is_string($configKey)) {
- // Is not a string
- throw new InvalidArgumentException(sprintf('configKey[]=%s is not a string', gettype($configKey)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
- } elseif ((is_string($configKey)) && (empty($configKey))) {
+ if (empty($configKey)) {
// Entry is empty
throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
}
// Convert dashes to underscore
- $configKey = BaseFrameworkSystem::convertDashesToUnderscores($configKey);
+ $configKey = StringUtils::convertDashesToUnderscores($configKey);
// Is a valid configuration key provided?
if (!$this->isConfigurationEntrySet($configKey)) {
// Entry was not found!
throw new NoConfigEntryException(array(__CLASS__, $configKey), self::EXCEPTION_CONFIG_KEY_WAS_NOT_FOUND);
- } // END - if
+ }
// Return the requested value
return self::$config[$configKey];
* @param $configKey The configuration key we want to add/change
* @param $configValue The configuration value we want to set
* @return void
- * @throws NullPointerException If $configKey is NULL
* @throws InvalidArgumentException If $configKey is empty
* @throws InvalidArgumentException If $configValue has an unsupported variable type
*/
- public final function setConfigEntry ($configKey, $configValue) {
+ public final function setConfigEntry (string $configKey, $configValue) {
// Is a valid configuration key key provided?
- if (is_null($configKey)) {
- // Configuration key is null
- throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER);
- } elseif (!is_string($configKey)) {
- // Is not a string
- throw new InvalidArgumentException(sprintf('configKey[]=%s is not a string', gettype($configKey)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
- } elseif ((is_string($configKey)) && (empty($configKey))) {
+ if (empty($configKey)) {
// Entry is empty
throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
} elseif ((is_array($configValue)) || (is_object($configValue)) || (is_resource($configValue))) {
}
// Cast to string
- $configKey = BaseFrameworkSystem::convertDashesToUnderscores($configKey);
+ $configKey = StringUtils::convertDashesToUnderscores($configKey);
// Set the configuration value
//* NOISY-DEBUG: */ print(__METHOD__ . ':configEntry=' . $configKey . ',configValue[' . gettype($configValue) . ']=' . $configValue . PHP_EOL);
*
* @param $configKey Configuration key to unset
* @return void
- * @throws NullPointerException If $configKey is NULL
* @throws InvalidArgumentException If $configKey is empty
* @throws NoConfigEntryException If a configuration element was not found
*/
- public final function unsetConfigEntry ($configKey) {
+ public final function unsetConfigEntry (string $configKey) {
// Validate parameters
- if (is_null($configKey)) {
- // Configuration key is null
- throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER);
- } elseif (!is_string($configKey)) {
- // Entry is empty
- throw new InvalidArgumentException(sprintf('configKey[]=%s is not a string', gettype($configKey)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
- } elseif ((is_string($configKey)) && (empty($configKey))) {
+ if (empty($configKey)) {
// Entry is empty
throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
}
// Convert dashes to underscore
- $configKey = BaseFrameworkSystem::convertDashesToUnderscores($configKey);
+ $configKey = StringUtils::convertDashesToUnderscores($configKey);
// Is the configuration key there?
if (!$this->isConfigurationEntrySet($configKey)) {
// Entry was not found!
throw new NoConfigEntryException(array(__CLASS__, $configKey), self::EXCEPTION_CONFIG_KEY_WAS_NOT_FOUND);
- } // END - if
+ }
// Unset it
unset(self::$config[$configKey]);
}
- /**
- * Getter for field name
- *
- * @param $fieldName Field name which we shall get
- * @return $fieldValue Field value from the user
- * @throws NullPointerException If the result instance is null
- */
- public final function getField ($fieldName) {
- // The super interface "FrameworkInterface" requires this
- throw new UnsupportedOperationException(array($this, __FUNCTION__), BaseFrameworkSystem::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Checks if given field is set
- *
- * @param $fieldName Field name to check
- * @return $isSet Whether the given field name is set
- * @throws NullPointerException If the result instance is null
- */
- public function isFieldSet ($fieldName) {
- // The super interface "FrameworkInterface" requires this
- throw new UnsupportedOperationException(array($this, __FUNCTION__), BaseFrameworkSystem::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
/**
* Generates a code for hashes from this class
*
$this->callbackInstance = $callbackInstance;
}
+ /**
+ * Getter for field name
+ *
+ * @param $fieldName Field name which we shall get
+ * @return $fieldValue Field value from the user
+ * @throws NullPointerException If the result instance is null
+ */
+ public final function getField (string $fieldName) {
+ // The super interface "FrameworkInterface" requires this
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), BaseFrameworkSystem::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Checks if given field is set
+ *
+ * @param $fieldName Field name to check
+ * @return $isSet Whether the given field name is set
+ * @throws NullPointerException If the result instance is null
+ */
+ public function isFieldSet (string $fieldName) {
+ // The super interface "FrameworkInterface" requires this
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), BaseFrameworkSystem::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
}