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. 7
      src/Laravel/ClientFacade.php
  7. 4
      src/Laravel/ClientServiceProvide.php
  8. 3
      src/ResponseIterator.php

37
src/Config.php

@ -31,9 +31,10 @@ class Config implements ConfigInterface
/**
* 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 = [])
{
@ -45,10 +46,11 @@ class Config implements ConfigInterface
/**
* 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
{
@ -71,8 +73,9 @@ class Config implements ConfigInterface
/**
* 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)
{
@ -89,9 +92,10 @@ class Config implements ConfigInterface
/**
* 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
{
@ -109,9 +113,10 @@ class Config implements ConfigInterface
/**
* 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)
{
@ -126,7 +131,7 @@ class Config implements ConfigInterface
/**
* Return array with all parameters of configuration
*
* @return array
* @return 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
*/
const LEGACY = false;
public const LEGACY = false;
/**
* Default port number
*/
const PORT = 8728;
public const PORT = 8728;
/**
* Default ssl port number
*/
const PORT_SSL = 8729;
public const PORT_SSL = 8729;
/**
* Do not use SSL by default
*/
const SSL = false;
public const SSL = false;
/**
* Max timeout for answer from router
*/
const TIMEOUT = 10;
public const TIMEOUT = 10;
/**
* Count of reconnect attempts
*/
const ATTEMPTS = 10;
public const ATTEMPTS = 10;
/**
* Delay between attempts in seconds
*/
const ATTEMPTS_DELAY = 1;
public const ATTEMPTS_DELAY = 1;
/**
* Return socket resource if is exist

21
src/Interfaces/ConfigInterface.php

@ -15,7 +15,7 @@ interface ConfigInterface
/**
* List of allowed parameters of config
*/
const ALLOWED = [
public const ALLOWED = [
// Address of Mikrotik RouterOS
'host' => 'string',
// Username
@ -39,32 +39,35 @@ interface ConfigInterface
/**
* 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;
/**
* Remove parameter from array by name
*
* @param string $parameter
* @return Config
* @param string $parameter
*
* @return \RouterOS\Config
*/
public function delete(string $parameter): Config;
/**
* Return parameter of current config by name
*
* @param string $parameter
* @return mixed
* @param string $parameter
*
* @return mixed
*/
public function get(string $parameter);
/**
* Return array with all parameters of configuration
*
* @return array
* @return 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 bool|string|int $value Value which need to check (by default true)
* @param bool|string|int $operator It may be one from list [-,=,>,<]
*
* @return \RouterOS\Query
* @throws \RouterOS\Exceptions\ClientException
* @since 1.0.0
@ -28,6 +29,7 @@ interface QueryInterface
* Append additional operations
*
* @param string $operations
*
* @since 1.0.0
*/
public function operations(string $operations);
@ -36,6 +38,7 @@ interface QueryInterface
* Append tag to query (it should be at end)
*
* @param string $name
*
* @since 1.0.0
*/
public function tag(string $name);
@ -44,6 +47,7 @@ interface QueryInterface
* Append to array yet another attribute of query
*
* @param string $word
*
* @return \RouterOS\Query
*/
public function add(string $word): Query;
@ -59,6 +63,7 @@ interface QueryInterface
* Set array of attributes
*
* @param array $attributes
*
* @return \RouterOS\Query
* @since 0.7
*/
@ -75,6 +80,7 @@ interface QueryInterface
* Set endpoint of query
*
* @param string $endpoint
*
* @return \RouterOS\Query
* @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
* 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;
@ -31,9 +32,10 @@ interface StreamInterface
* 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.
*
* @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;
@ -42,5 +44,5 @@ interface StreamInterface
*
* @return void
*/
public function close();
public function close(): void;
}

7
src/Laravel/ClientFacade.php

@ -6,7 +6,12 @@ use Illuminate\Support\Facades\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;
}

4
src/Laravel/ClientServiceProvide.php

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

3
src/ResponseIterator.php

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

Loading…
Cancel
Save