<?php
// Own namespace
-
namespace CoreFramework\Configuration;
// Import framework stuff
use CoreFramework\Generic\FrameworkInterface;
use CoreFramework\Generic\NullPointerException;
use CoreFramework\Generic\UnsupportedOperationException;
+use CoreFramework\Object\BaseFrameworkSystem;
use CoreFramework\Registry\Registerable;
// Import SPL stuff
const EXCEPTION_CONFIG_VALUE_TYPE_UNSUPPORTED = 0x132;
/**
- * Protected constructor
+ * Private constructor
*
* @return void
*/
- protected function __construct () {
+ private function __construct () {
// Empty for now
}
// Is it null?
if (is_null($str)) {
// Throw NPE
- throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+ throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER);
} elseif (empty($str)) {
// Entry is empty
throw new InvalidArgumentException('str is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
/**
* Setter for default time zone (must be correct!)
*
- * @param $zone The time-zone string (e.g. Europe/Berlin)
- * @return void
- * @throws NullPointerException If $zone is NULL
- * @throws InvalidArgumentException If $zone is empty
+ * @param $timezone The timezone string (e.g. Europe/Berlin)
+ * @return $success If timezone was accepted
+ * @throws NullPointerException If $timezone is NULL
+ * @throws InvalidArgumentException If $timezone is empty
*/
- public final function setDefaultTimezone ($zone) {
+ public final function setDefaultTimezone ($timezone) {
// Is it null?
- if (is_null($zone)) {
+ if (is_null($timezone)) {
// Throw NPE
- throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } elseif (empty($zone)) {
+ throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER);
+ } elseif (!is_string($timezone)) {
+ // Is not a string
+ throw new InvalidArgumentException(sprintf('timezone[]=%s is not a string', gettype($timezone)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
+ } elseif (empty($timezone)) {
// Entry is empty
- throw new InvalidArgumentException('zone is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
+ throw new InvalidArgumentException('timezone is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
}
- // Is PHP version 5.1.0 or higher? Older versions are being ignored
- if (version_compare(phpversion(), '5.1.0', '>=')) {
- /*
- * Set desired time zone to prevent date() and related functions to
- * issue a E_WARNING.
- */
- date_default_timezone_set($zone);
- } // END - if
+ // Default success
+ $success = FALSE;
+
+ /*
+ * Set desired time zone to prevent date() and related functions to
+ * issue an E_WARNING.
+ */
+ $success = date_default_timezone_set($timezone);
+
+ // Return status
+ return $success;
}
/**
// Is it null?
if (is_null($configKey)) {
// Throw NPE
- throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+ 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 (empty($configKey)) {
// Entry is empty
throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
}
// Is it set?
- $isset = isset($this->config[$configKey]);
+ $isset = ((isset($this->config[$configKey])) || (array_key_exists($configKey, $this->config)));
// Return the result
return $isset;
// Is it null?
if (is_null($configKey)) {
// Throw NPE
- throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+ 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 (empty($configKey)) {
// Entry is empty
throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
* @return void
* @throws NullPointerException If $configKey is NULL
* @throws InvalidArgumentException If $configKey is empty
- * @throws ConfigValueTypeUnsupportedException If $configValue has an unsupported variable type
+ * @throws InvalidArgumentException If $configValue has an unsupported variable type
*/
public final function setConfigEntry ($configKey, $configValue) {
// Is a valid configuration key key provided?
if (is_null($configKey)) {
// Configuration key is null
- throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } elseif ((empty($configKey)) || (!is_string($configKey))) {
+ 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 (empty($configKey)) {
// Entry is empty
throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
- } elseif ((is_null($configValue)) || (is_array($configValue)) || (is_object($configValue)) || (is_resource($configValue))) {
+ } elseif ((is_array($configValue)) || (is_object($configValue)) || (is_resource($configValue))) {
// These cannot be set as this is not intended for configuration values, please use FrameworkArrayObject instead.
- throw new ConfigValueTypeUnsupportedException(array($this, $configKey, $configValue), self::EXCEPTION_CONFIG_VALUE_TYPE_UNSUPPORTED);
+ throw new InvalidArgumentException(sprintf('configValue[]=%s for configKey=%s is not supported.', gettype($configValue), $configKey), self::EXCEPTION_CONFIG_VALUE_TYPE_UNSUPPORTED);
}
// Cast to string
* @throws NoConfigEntryException If a configuration element was not found
*/
public final function unsetConfigEntry ($configKey) {
+ // Validate parameters
if (is_null($configKey)) {
// Configuration key is null
- throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } elseif ((empty($configKey)) || (!is_string($configKey))) {
+ 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 (empty($configKey)) {
// Entry is empty
throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
}
* @return void
*/
public function setServerAddress ($serverAddress) {
+ // Is a valid configuration key key provided?
+ if (is_null($serverAddress)) {
+ // Configuration key is null
+ throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER);
+ } elseif (!is_string($serverAddress)) {
+ // Is not a string
+ throw new InvalidArgumentException(sprintf('serverAddress[]=%s is not a string', gettype($serverAddress)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
+ } elseif (empty($serverAddress)) {
+ // Entry is empty
+ throw new InvalidArgumentException('serverAddress is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
+ }
+
+ // Set it, please don't do it yourself here
$this->setConfigEntry('server_addr', (string) $serverAddress);
}