Browse Source

small tunes of code, migration to php 7.2

tags/1.2.0
Paul Rock 6 years ago
parent
commit
e929d6d67a
  1. 37
      src/Config.php
  2. 14
      src/Interfaces/ClientInterface.php
  3. 21
      src/Interfaces/ConfigInterface.php
  4. 6
      src/Interfaces/QueryInterface.php
  5. 14
      src/Interfaces/StreamInterface.php
  6. 9
      src/Laravel/ClientFacade.php
  7. 4
      src/Laravel/ClientServiceProvide.php
  8. 2
      src/Laravel/ClientWrapper.php
  9. 3
      src/ResponseIterator.php

37
src/Config.php

@ -31,9 +31,10 @@ class Config implements ConfigInterface
/** /**
* Config constructor. * Config constructor.
* *
* @param array $parameters List of parameters which can be set on object creation stage
* @throws ConfigException
* @since 0.6
* @param array $parameters List of parameters which can be set on object creation stage
*
* @throws \RouterOS\Exceptions\ConfigException
* @since 0.6
*/ */
public function __construct(array $parameters = []) public function __construct(array $parameters = [])
{ {
@ -45,10 +46,11 @@ class Config implements ConfigInterface
/** /**
* Set parameter into array * Set parameter into array
* *
* @param string $name
* @param mixed $value
* @return \RouterOS\Config
* @throws ConfigException
* @param string $name
* @param mixed $value
*
* @return \RouterOS\Config
* @throws \RouterOS\Exceptions\ConfigException
*/ */
public function set(string $name, $value): Config public function set(string $name, $value): Config
{ {
@ -71,8 +73,9 @@ class Config implements ConfigInterface
/** /**
* Return port number (get from defaults if port is not set by user) * Return port number (get from defaults if port is not set by user)
* *
* @param string $parameter
* @return bool|int
* @param string $parameter
*
* @return bool|int
*/ */
private function getPort(string $parameter) private function getPort(string $parameter)
{ {
@ -89,9 +92,10 @@ class Config implements ConfigInterface
/** /**
* Remove parameter from array by name * Remove parameter from array by name
* *
* @param string $name
* @return \RouterOS\Config
* @throws \RouterOS\Exceptions\ConfigException
* @param string $name
*
* @return \RouterOS\Config
* @throws \RouterOS\Exceptions\ConfigException
*/ */
public function delete(string $name): Config public function delete(string $name): Config
{ {
@ -109,9 +113,10 @@ class Config implements ConfigInterface
/** /**
* Return parameter of current config by name * Return parameter of current config by name
* *
* @param string $name
* @return mixed
* @throws \RouterOS\Exceptions\ConfigException
* @param string $name
*
* @return mixed
* @throws \RouterOS\Exceptions\ConfigException
*/ */
public function get(string $name) public function get(string $name)
{ {
@ -126,7 +131,7 @@ class Config implements ConfigInterface
/** /**
* Return array with all parameters of configuration * Return array with all parameters of configuration
* *
* @return array
* @return array
*/ */
public function getParameters(): array public function getParameters(): array
{ {

14
src/Interfaces/ClientInterface.php

@ -16,37 +16,37 @@ interface ClientInterface
/** /**
* By default legacy login on RouterOS pre-6.43 is not supported * By default legacy login on RouterOS pre-6.43 is not supported
*/ */
const LEGACY = false;
public const LEGACY = false;
/** /**
* Default port number * Default port number
*/ */
const PORT = 8728;
public const PORT = 8728;
/** /**
* Default ssl port number * Default ssl port number
*/ */
const PORT_SSL = 8729;
public const PORT_SSL = 8729;
/** /**
* Do not use SSL by default * Do not use SSL by default
*/ */
const SSL = false;
public const SSL = false;
/** /**
* Max timeout for answer from router * Max timeout for answer from router
*/ */
const TIMEOUT = 10;
public const TIMEOUT = 10;
/** /**
* Count of reconnect attempts * Count of reconnect attempts
*/ */
const ATTEMPTS = 10;
public const ATTEMPTS = 10;
/** /**
* Delay between attempts in seconds * Delay between attempts in seconds
*/ */
const ATTEMPTS_DELAY = 1;
public const ATTEMPTS_DELAY = 1;
/** /**
* Return socket resource if is exist * Return socket resource if is exist

21
src/Interfaces/ConfigInterface.php

@ -15,7 +15,7 @@ interface ConfigInterface
/** /**
* List of allowed parameters of config * List of allowed parameters of config
*/ */
const ALLOWED = [
public const ALLOWED = [
// Address of Mikrotik RouterOS // Address of Mikrotik RouterOS
'host' => 'string', 'host' => 'string',
// Username // Username
@ -39,32 +39,35 @@ interface ConfigInterface
/** /**
* Set parameter into array * Set parameter into array
* *
* @param string $name
* @param mixed $value
* @return Config
* @param string $name
* @param mixed $value
*
* @return \RouterOS\Config
*/ */
public function set(string $name, $value): Config; public function set(string $name, $value): Config;
/** /**
* Remove parameter from array by name * Remove parameter from array by name
* *
* @param string $parameter
* @return Config
* @param string $parameter
*
* @return \RouterOS\Config
*/ */
public function delete(string $parameter): Config; public function delete(string $parameter): Config;
/** /**
* Return parameter of current config by name * Return parameter of current config by name
* *
* @param string $parameter
* @return mixed
* @param string $parameter
*
* @return mixed
*/ */
public function get(string $parameter); public function get(string $parameter);
/** /**
* Return array with all parameters of configuration * Return array with all parameters of configuration
* *
* @return array
* @return array
*/ */
public function getParameters(): array; public function getParameters(): array;
} }

6
src/Interfaces/QueryInterface.php

@ -18,6 +18,7 @@ interface QueryInterface
* @param string $key Key which need to find * @param string $key Key which need to find
* @param bool|string|int $value Value which need to check (by default true) * @param bool|string|int $value Value which need to check (by default true)
* @param bool|string|int $operator It may be one from list [-,=,>,<] * @param bool|string|int $operator It may be one from list [-,=,>,<]
*
* @return \RouterOS\Query * @return \RouterOS\Query
* @throws \RouterOS\Exceptions\ClientException * @throws \RouterOS\Exceptions\ClientException
* @since 1.0.0 * @since 1.0.0
@ -28,6 +29,7 @@ interface QueryInterface
* Append additional operations * Append additional operations
* *
* @param string $operations * @param string $operations
*
* @since 1.0.0 * @since 1.0.0
*/ */
public function operations(string $operations); public function operations(string $operations);
@ -36,6 +38,7 @@ interface QueryInterface
* Append tag to query (it should be at end) * Append tag to query (it should be at end)
* *
* @param string $name * @param string $name
*
* @since 1.0.0 * @since 1.0.0
*/ */
public function tag(string $name); public function tag(string $name);
@ -44,6 +47,7 @@ interface QueryInterface
* Append to array yet another attribute of query * Append to array yet another attribute of query
* *
* @param string $word * @param string $word
*
* @return \RouterOS\Query * @return \RouterOS\Query
*/ */
public function add(string $word): Query; public function add(string $word): Query;
@ -59,6 +63,7 @@ interface QueryInterface
* Set array of attributes * Set array of attributes
* *
* @param array $attributes * @param array $attributes
*
* @return \RouterOS\Query * @return \RouterOS\Query
* @since 0.7 * @since 0.7
*/ */
@ -75,6 +80,7 @@ interface QueryInterface
* Set endpoint of query * Set endpoint of query
* *
* @param string $endpoint * @param string $endpoint
*
* @return \RouterOS\Query * @return \RouterOS\Query
* @since 0.7 * @since 0.7
*/ */

14
src/Interfaces/StreamInterface.php

@ -18,8 +18,9 @@ interface StreamInterface
* Reads $length bytes from the stream, returns the bytes into a string * Reads $length bytes from the stream, returns the bytes into a string
* Must be binary safe (as fread). * Must be binary safe (as fread).
* *
* @param int $length the numer of bytes to read
* @return string a binary string containing the readed byes
* @param int $length the number of bytes to read
*
* @return string a binary string containing the readed byes
*/ */
public function read(int $length): string; public function read(int $length): string;
@ -31,9 +32,10 @@ interface StreamInterface
* if $length is greater than string length, write all string and return number of writen bytes * if $length is greater than string length, write all string and return number of writen bytes
* if $length os smaller than string length, remaining bytes are losts. * if $length os smaller than string length, remaining bytes are losts.
* *
* @param string $string
* @param int $length the number of bytes to read
* @return int return number of written bytes
* @param string $string
* @param int $length the number of bytes to read
*
* @return int return number of written bytes
*/ */
public function write(string $string, int $length = -1): int; public function write(string $string, int $length = -1): int;
@ -42,5 +44,5 @@ interface StreamInterface
* *
* @return void * @return void
*/ */
public function close();
public function close(): void;
} }

9
src/Laravel/ClientFacade.php

@ -6,8 +6,13 @@ use Illuminate\Support\Facades\Facade;
class ClientFacade extends Facade class ClientFacade extends Facade
{ {
protected static function getFacadeAccessor()
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor(): string
{ {
return ClientWrapper::class; return ClientWrapper::class;
} }
}
}

4
src/Laravel/ClientServiceProvide.php

@ -11,7 +11,7 @@ class ClientServiceProvide extends BaseServiceProvider
* *
* @return void * @return void
*/ */
public function boot()
public function boot(): void
{ {
$this->publishes([ $this->publishes([
__DIR__ . '/../../configs/routeros-api.php' => config_path('routeros-api.php'), __DIR__ . '/../../configs/routeros-api.php' => config_path('routeros-api.php'),
@ -23,7 +23,7 @@ class ClientServiceProvide extends BaseServiceProvider
* *
* @return void * @return void
*/ */
public function register()
public function register(): void
{ {
$this->mergeConfigFrom( $this->mergeConfigFrom(
__DIR__ . '/../../configs/routeros-api.php', 'routeros-api' __DIR__ . '/../../configs/routeros-api.php', 'routeros-api'

2
src/Laravel/ClientWrapper.php

@ -21,4 +21,4 @@ class ClientWrapper
return new Client($configs); return new Client($configs);
} }
}
}

3
src/ResponseIterator.php

@ -12,6 +12,7 @@ use \Iterator,
* from RouterOS to readable array in safe way. * from RouterOS to readable array in safe way.
* *
* @param array $raw Array RAW response from server * @param array $raw Array RAW response from server
*
* @return mixed * @return mixed
* *
* Based on RouterOSResponseArray solution by @arily * Based on RouterOSResponseArray solution by @arily
@ -188,6 +189,7 @@ class ResponseIterator implements Iterator, ArrayAccess, Countable, Serializable
* Whether a offset exists * Whether a offset exists
* *
* @param mixed $offset * @param mixed $offset
*
* @return bool * @return bool
*/ */
public function offsetExists($offset): bool public function offsetExists($offset): bool
@ -209,6 +211,7 @@ class ResponseIterator implements Iterator, ArrayAccess, Countable, Serializable
* Offset to retrieve * Offset to retrieve
* *
* @param mixed $offset * @param mixed $offset
*
* @return bool|mixed * @return bool|mixed
*/ */
public function offsetGet($offset) public function offsetGet($offset)

Loading…
Cancel
Save