Browse Source

Responses/parameters of some methods in Client class changed from other classes to interfaces, consts moved from ClientInterface to Config class

pull/40/head
Paul Rock 6 years ago
parent
commit
75a201e0f2
  1. 18
      src/Client.php
  2. 56
      src/Config.php
  3. 57
      src/Interfaces/ClientInterface.php
  4. 2
      src/Interfaces/QueryInterface.php

18
src/Client.php

@ -6,6 +6,7 @@ use DivineOmega\SSHConnection\SSHConnection;
use RouterOS\Exceptions\ClientException;
use RouterOS\Exceptions\ConfigException;
use RouterOS\Exceptions\QueryException;
use RouterOS\Interfaces\ClientInterface;
use RouterOS\Interfaces\QueryInterface;
use RouterOS\Helpers\ArrayHelper;
use function array_keys;
@ -97,13 +98,13 @@ class Client implements Interfaces\ClientInterface
/**
* Send write query to RouterOS
*
* @param string|array|\RouterOS\Query $query
* @param string|array|\RouterOS\Interfaces\QueryInterface $query
*
* @return \RouterOS\Client
* @return \RouterOS\Interfaces\ClientInterface
* @throws \RouterOS\Exceptions\QueryException
* @deprecated
*/
public function write($query): Client
public function write($query): ClientInterface
{
if (is_string($query)) {
$query = new Query($query);
@ -133,7 +134,7 @@ class Client implements Interfaces\ClientInterface
* @throws \RouterOS\Exceptions\ClientException
* @since 1.0.0
*/
public function query($endpoint, array $where = null, string $operations = null, string $tag = null): Client
public function query($endpoint, array $where = null, string $operations = null, string $tag = null): ClientInterface
{
// If endpoint is string then build Query object
$query = ($endpoint instanceof Query)
@ -175,8 +176,8 @@ class Client implements Interfaces\ClientInterface
* @param \RouterOS\Interfaces\QueryInterface $query
*
* @return \RouterOS\Query
* @throws \RouterOS\Exceptions\ClientException
* @throws \RouterOS\Exceptions\QueryException
* @throws \RouterOS\Exceptions\ClientException
*/
private function preQuery(array $item, QueryInterface $query): QueryInterface
{
@ -197,6 +198,7 @@ class Client implements Interfaces\ClientInterface
break;
default:
throw new ClientException('From 1 to 3 parameters of "where" condition is allowed');
break;
}
return $query->where($key, $operator, $value);
@ -205,13 +207,13 @@ class Client implements Interfaces\ClientInterface
/**
* Send write query object to RouterOS
*
* @param \RouterOS\Query $query
* @param \RouterOS\Interfaces\QueryInterface $query
*
* @return \RouterOS\Client
* @return \RouterOS\Interfaces\ClientInterface
* @throws \RouterOS\Exceptions\QueryException
* @since 1.0.0
*/
private function writeRAW(Query $query): Client
private function writeRAW(QueryInterface $query): ClientInterface
{
// Send commands via loop to router
foreach ($query->getQuery() as $command) {

56
src/Config.php

@ -17,6 +17,46 @@ use function gettype;
class Config implements ConfigInterface
{
/**
* By default legacy login on RouterOS pre-6.43 is not supported
*/
public const LEGACY = false;
/**
* Default port number
*/
public const PORT = 8728;
/**
* Default ssl port number
*/
public const PORT_SSL = 8729;
/**
* Do not use SSL by default
*/
public const SSL = false;
/**
* Max timeout for answer from router
*/
public const TIMEOUT = 10;
/**
* Count of reconnect attempts
*/
public const ATTEMPTS = 10;
/**
* Delay between attempts in seconds
*/
public const ATTEMPTS_DELAY = 1;
/**
* Delay between attempts in seconds
*/
public const SSH_PORT = 22;
/**
* List of allowed parameters of config
*/
public const ALLOWED = [
@ -48,12 +88,12 @@ class Config implements ConfigInterface
* @var array
*/
private $_parameters = [
'legacy' => Client::LEGACY,
'ssl' => Client::SSL,
'timeout' => Client::TIMEOUT,
'attempts' => Client::ATTEMPTS,
'delay' => Client::ATTEMPTS_DELAY,
'ssh_port' => Client::SSH_PORT,
'legacy' => self::LEGACY,
'ssl' => self::SSL,
'timeout' => self::TIMEOUT,
'attempts' => self::ATTEMPTS,
'delay' => self::ATTEMPTS_DELAY,
'ssh_port' => self::SSH_PORT,
];
/**
@ -111,8 +151,8 @@ class Config implements ConfigInterface
if ($parameter === 'port' && (!isset($this->_parameters['port']) || null === $this->_parameters['port'])) {
// then use default with or without ssl encryption
return (isset($this->_parameters['ssl']) && $this->_parameters['ssl'])
? Client::PORT_SSL
: Client::PORT;
? self::PORT_SSL
: self::PORT;
}
return null;
}

57
src/Interfaces/ClientInterface.php

@ -2,9 +2,6 @@
namespace RouterOS\Interfaces;
use RouterOS\Client;
use RouterOS\Query;
/**
* Interface ClientInterface
*
@ -14,46 +11,6 @@ use RouterOS\Query;
interface ClientInterface
{
/**
* By default legacy login on RouterOS pre-6.43 is not supported
*/
public const LEGACY = false;
/**
* Default port number
*/
public const PORT = 8728;
/**
* Default ssl port number
*/
public const PORT_SSL = 8729;
/**
* Do not use SSL by default
*/
public const SSL = false;
/**
* Max timeout for answer from router
*/
public const TIMEOUT = 10;
/**
* Count of reconnect attempts
*/
public const ATTEMPTS = 10;
/**
* Delay between attempts in seconds
*/
public const ATTEMPTS_DELAY = 1;
/**
* Delay between attempts in seconds
*/
public const SSH_PORT = 22;
/**
* Return socket resource if is exist
*
* @return resource
@ -78,21 +35,21 @@ interface ClientInterface
/**
* Send write query to RouterOS
*
* @param string|array|\RouterOS\Query $query
* @param string|array|\RouterOS\Interfaces\QueryInterface $query
*
* @return \RouterOS\Client
* @return \RouterOS\Interfaces\ClientInterface
* @throws \RouterOS\Exceptions\QueryException
* @deprecated
*/
public function write($query): Client;
public function write($query): ClientInterface;
/**
* Send write query to RouterOS (modern version of write)
*
* @param string|Query $endpoint Path of API query or Query object
* @param array|null $where List of where filters
* @param string|null $operations Some operations which need make on response
* @param string|null $tag Mark query with tag
* @param string|\RouterOS\Interfaces\QueryInterface $endpoint Path of API query or Query object
* @param array|null $where List of where filters
* @param string|null $operations Some operations which need make on response
* @param string|null $tag Mark query with tag
*
* @return \RouterOS\Interfaces\ClientInterface
* @throws \RouterOS\Exceptions\QueryException

2
src/Interfaces/QueryInterface.php

@ -18,7 +18,7 @@ interface QueryInterface
* @param bool|string|int $operator It may be one from list [-,=,>,<]
*
* @return \RouterOS\Interfaces\QueryInterface
* @throws \RouterOS\Exceptions\ClientException
* @throws \RouterOS\Exceptions\QueryException
* @since 1.0.0
*/
public function where(string $key, $operator = '=', $value = null): QueryInterface;

Loading…
Cancel
Save