Browse Source

pull/14/head
arily 6 years ago
committed by GitHub
parent
commit
ba6dd11697
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      src/Client.php

36
src/Client.php

@ -14,7 +14,8 @@ use RouterOS\Interfaces\ClientInterface;
* @package RouterOS * @package RouterOS
* @since 0.1 * @since 0.1
*/ */
class Client implements Interfaces\ClientInterface {
class Client implements Interfaces\ClientInterface
{
use SocketTrait, ShortsTrait; use SocketTrait, ShortsTrait;
/** /**
@ -40,7 +41,8 @@ class Client implements Interfaces\ClientInterface {
* @throws \RouterOS\Exceptions\ConfigException * @throws \RouterOS\Exceptions\ConfigException
* @throws \RouterOS\Exceptions\QueryException * @throws \RouterOS\Exceptions\QueryException
*/ */
public function __construct($config) {
public function __construct($config)
{
// If array then need create object // If array then need create object
if (\is_array($config)) { if (\is_array($config)) {
$config = new Config($config); $config = new Config($config);
@ -67,7 +69,8 @@ class Client implements Interfaces\ClientInterface {
* @return mixed * @return mixed
* @throws \RouterOS\Exceptions\ConfigException * @throws \RouterOS\Exceptions\ConfigException
*/ */
private function config(string $parameter) {
private function config(string $parameter)
{
return $this->_config->get($parameter); return $this->_config->get($parameter);
} }
@ -77,7 +80,8 @@ class Client implements Interfaces\ClientInterface {
* @return \RouterOS\Config * @return \RouterOS\Config
* @since 0.6 * @since 0.6
*/ */
public function getConfig(): Config {
public function getConfig(): Config
{
return $this->_config; return $this->_config;
} }
@ -87,7 +91,8 @@ class Client implements Interfaces\ClientInterface {
* @param \RouterOS\Config $config * @param \RouterOS\Config $config
* @since 0.7 * @since 0.7
*/ */
public function setConfig(Config $config) {
public function setConfig(Config $config)
{
$this->_config = $config; $this->_config = $config;
} }
@ -98,7 +103,8 @@ class Client implements Interfaces\ClientInterface {
* @return \RouterOS\Interfaces\ClientInterface * @return \RouterOS\Interfaces\ClientInterface
* @throws \RouterOS\Exceptions\QueryException * @throws \RouterOS\Exceptions\QueryException
*/ */
public function write($query): ClientInterface {
public function write($query): ClientInterface
{
if (\is_string($query)) { if (\is_string($query)) {
$query = new Query($query); $query = new Query($query);
} elseif (\is_array($query)) { } elseif (\is_array($query)) {
@ -133,7 +139,8 @@ class Client implements Interfaces\ClientInterface {
* @param bool $parse * @param bool $parse
* @return mixed * @return mixed
*/ */
public function read(bool $parse = true) {
public function read(bool $parse = true)
{
// By default response is empty // By default response is empty
$response = []; $response = [];
// We have to wait a !done or !fatal // We have to wait a !done or !fatal
@ -174,7 +181,8 @@ class Client implements Interfaces\ClientInterface {
* *
* @return Iterators\ResponseIterator * @return Iterators\ResponseIterator
*/ */
public function readAsIterator() {
public function readAsIterator()
{
return new Iterators\ResponseIterator($this->read(false)); return new Iterators\ResponseIterator($this->read(false));
} }
@ -271,7 +279,8 @@ class Client implements Interfaces\ClientInterface {
* @param string $value * @param string $value
* @param array $matches * @param array $matches
*/ */
private function pregResponse(string $value, &$matches) {
private function pregResponse(string $value, &$matches)
{
preg_match_all('/^[=|\.](.*)=(.*)/', $value, $matches); preg_match_all('/^[=|\.](.*)=(.*)/', $value, $matches);
} }
@ -284,7 +293,8 @@ class Client implements Interfaces\ClientInterface {
* @throws \RouterOS\Exceptions\ConfigException * @throws \RouterOS\Exceptions\ConfigException
* @throws \RouterOS\Exceptions\QueryException * @throws \RouterOS\Exceptions\QueryException
*/ */
private function login(bool $legacyRetry = false): bool {
private function login(bool $legacyRetry = false): bool
{
// If legacy login scheme is enabled // If legacy login scheme is enabled
if ($this->config('legacy')) { if ($this->config('legacy')) {
// For the first we need get hash with salt // For the first we need get hash with salt
@ -330,7 +340,8 @@ class Client implements Interfaces\ClientInterface {
* @return bool * @return bool
* @throws ConfigException * @throws ConfigException
*/ */
private function isLegacy(array &$response): bool {
private function isLegacy(array &$response): bool
{
return \count($response) > 1 && $response[0] === '!done' && !$this->config('legacy'); return \count($response) > 1 && $response[0] === '!done' && !$this->config('legacy');
} }
@ -342,7 +353,8 @@ class Client implements Interfaces\ClientInterface {
* @throws \RouterOS\Exceptions\ConfigException * @throws \RouterOS\Exceptions\ConfigException
* @throws \RouterOS\Exceptions\QueryException * @throws \RouterOS\Exceptions\QueryException
*/ */
private function connect(): bool{
private function connect(): bool
{
// By default we not connected // By default we not connected
$connected = false; $connected = false;

Loading…
Cancel
Save