From 237a749bf78385b6baf11b134a1b743d98c31f6c Mon Sep 17 00:00:00 2001 From: Paul Rock Date: Tue, 23 Jul 2019 23:52:08 +0300 Subject: [PATCH] getConfig and setConfig removed from Client class --- src/Client.php | 45 ++++++++++++--------------------------------- tests/ClientTest.php | 11 ----------- 2 files changed, 12 insertions(+), 44 deletions(-) diff --git a/src/Client.php b/src/Client.php index df7c434..e03b719 100644 --- a/src/Client.php +++ b/src/Client.php @@ -54,7 +54,7 @@ class Client implements Interfaces\ClientInterface } // Save config if everything is okay - $this->setConfig($config); + $this->_config = $config; // Throw error if cannot to connect if (false === $this->connect()) { @@ -75,35 +75,13 @@ class Client implements Interfaces\ClientInterface } /** - * Return socket resource if is exist - * - * @return \RouterOS\Config - * @since 0.6 - */ - public function getConfig(): Config - { - return $this->_config; - } - - /** - * Set configuration of client - * - * @param \RouterOS\Config $config - * @since 0.7 - */ - public function setConfig(Config $config) - { - $this->_config = $config; - } - - /** * Send write query to RouterOS (with or without tag) * * @param string|array|\RouterOS\Query $query * @return \RouterOS\Interfaces\ClientInterface * @throws \RouterOS\Exceptions\QueryException */ - public function write($query): ClientInterface + public function write($query): self { if (\is_string($query)) { $query = new Query($query); @@ -196,7 +174,7 @@ class Client implements Interfaces\ClientInterface * Based on RouterOSResponseArray solution by @arily * * @link https://github.com/arily/RouterOSResponseArray - * @since 0.10 + * @since 1.0.0 */ private function rosario(array $raw): array { @@ -298,18 +276,19 @@ class Client implements Interfaces\ClientInterface // If legacy login scheme is enabled if ($this->config('legacy')) { // For the first we need get hash with salt - $query = new Query('/login'); - $response = $this->write($query)->read(); + $response = $this->write('/login')->read(); // Now need use this hash for authorization - $query = (new Query('/login')) - ->add('=name=' . $this->config('user')) - ->add('=response=00' . md5(\chr(0) . $this->config('pass') . pack('H*', $response['after']['ret']))); + $query = new Query('/login', [ + '=name=' . $this->config('user'), + '=response=00' . md5(\chr(0) . $this->config('pass') . pack('H*', $response['after']['ret'])) + ]); } else { // Just login with our credentials - $query = (new Query('/login')) - ->add('=name=' . $this->config('user')) - ->add('=password=' . $this->config('pass')); + $query = new Query('/login', [ + '=name=' . $this->config('user'), + '=password=' . $this->config('pass') + ]); // If we set modern auth scheme but router with legacy firmware then need to retry query, // but need to prevent endless loop diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 3203b23..f6551c3 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -197,15 +197,4 @@ class ClientTest extends TestCase $error = $obj->write($obj)->read(false); } - public function testGetConfig() - { - $obj = new Client([ - 'user' => getenv('ROS_USER'), - 'pass' => getenv('ROS_PASS'), - 'host' => getenv('ROS_HOST') - ]); - - $config = $obj->getConfig(); - $this->assertEquals('admin', $config->get('user')); - } }