Browse Source

delete method added to config class

tags/0.4
Paul Rock 7 years ago
parent
commit
d875e318c1
  1. 31
      src/Config.php
  2. 20
      src/Interfaces/ConfigInterface.php

31
src/Config.php

@ -46,11 +46,10 @@ 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);
@ -62,10 +61,6 @@ class Config implements ConfigInterface
throw new Exception("Parameter '$name' has wrong type '$whatType'' but should be '$isType''");
}
} catch (Exception $e) {
// __construct
}
// Save value to array
$this->_parameters[$name] = $value;
@ -91,21 +86,35 @@ 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
}
return $this->getPort($parameter) ?? $this->_parameters[$parameter];
}

20
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

Loading…
Cancel
Save