diff --git a/src/Config.php b/src/Config.php index 9e4cc74..bf2a666 100644 --- a/src/Config.php +++ b/src/Config.php @@ -46,24 +46,19 @@ class Config implements ConfigInterface * @param string $name * @param mixed $value * @return ConfigInterface + * @throws Exception */ public function set(string $name, $value): ConfigInterface { - try { - - // Check of key in array - $this->keyAllowed($name, self::ALLOWED); - - $whatType = \gettype($value); - $isType = self::ALLOWED[$name]; + // Check of key in array + $this->keyAllowed($name, self::ALLOWED); - // Check what type has this value - if ($whatType !== $isType) { - throw new Exception("Parameter '$name' has wrong type '$whatType'' but should be '$isType''"); - } + $whatType = \gettype($value); + $isType = self::ALLOWED[$name]; - } catch (Exception $e) { - // __construct + // Check what type has this value + if ($whatType !== $isType) { + throw new Exception("Parameter '$name' has wrong type '$whatType'' but should be '$isType''"); } // Save value to array @@ -91,20 +86,34 @@ class Config implements ConfigInterface } /** + * Remove parameter from array by name + * + * @param string $parameter + * @return ConfigInterface + * @throws Exception + */ + public function delete(string $parameter): ConfigInterface + { + // Check of key in array + $this->keyAllowed($parameter, self::ALLOWED); + + // Save value to array + unset($this->_parameters[$parameter]); + + return $this; + } + + /** * Return parameter of current config by name * * @param string $parameter * @return mixed + * @throws Exception */ public function get(string $parameter) { - try { - // Check of key in array - $this->keyAllowed($parameter, self::ALLOWED); - - } catch (Exception $e) { - // __construct - } + // Check of key in array + $this->keyAllowed($parameter, self::ALLOWED); return $this->getPort($parameter) ?? $this->_parameters[$parameter]; } diff --git a/src/Interfaces/ConfigInterface.php b/src/Interfaces/ConfigInterface.php index fdd6d37..84515af 100644 --- a/src/Interfaces/ConfigInterface.php +++ b/src/Interfaces/ConfigInterface.php @@ -20,17 +20,17 @@ interface ConfigInterface // Password 'pass' => 'string', // RouterOS API port number for access (if not set use default or default with SSL if SSL enabled) - 'port' => 'int', + 'port' => 'integer', // Enable ssl support (if port is not set this parameter must change default port to ssl port) - 'ssl' => 'bool', + 'ssl' => 'boolean', // Support of legacy login scheme (true - pre 6.43, false - post 6.43) - 'legacy' => 'bool', + 'legacy' => 'boolean', // Max timeout for answer from RouterOS - 'timeout' => 'int', + 'timeout' => 'integer', // Count of attempts to establish TCP session - 'attempts' => 'int', + 'attempts' => 'integer', // Delay between attempts in seconds - 'delay' => 'int', + 'delay' => 'integer', ]; /** @@ -43,6 +43,14 @@ interface ConfigInterface public function set(string $name, $value): ConfigInterface; /** + * Remove parameter from array by name + * + * @param string $parameter + * @return ConfigInterface + */ + public function delete(string $parameter): ConfigInterface; + + /** * Return parameter of current config by name * * @param string $parameter