From 559485cb65b1a6001d05d4a3bc471109215cf7bd Mon Sep 17 00:00:00 2001 From: Paul Rock Date: Sun, 5 Jan 2020 04:42:40 +0300 Subject: [PATCH] laravel support added --- composer.json | 22 ++++++++++++++++++---- configs/routeros-api.php | 13 +++++++++++++ src/Config.php | 2 +- src/Laravel/ClientFacade.php | 13 +++++++++++++ src/Laravel/ClientServiceProvide.php | 34 ++++++++++++++++++++++++++++++++++ src/Laravel/ClientWrapper.php | 24 ++++++++++++++++++++++++ 6 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 configs/routeros-api.php create mode 100644 src/Laravel/ClientFacade.php create mode 100644 src/Laravel/ClientServiceProvide.php create mode 100644 src/Laravel/ClientWrapper.php diff --git a/composer.json b/composer.json index 5bba74e..a019b08 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,15 @@ { "name": "evilfreelancer/routeros-api-php", "type": "library", - "description": "Modern Mikrotik RouterOS API PHP7 client for your applications", + "description": "Modern Mikrotik RouterOS API PHP client for your applications (with Laravel support)", "keywords": [ "socket-client", "psr-4", "routeros", - "mikrotik" + "mikrotik", + "laravel", + "plugin", + "facade" ], "license": "MIT", "autoload": { @@ -25,11 +28,22 @@ "role": "Developer" } ], + "extra": { + "laravel": { + "providers": [ + "RouterOS\\Laravel\\ClientServiceProvide" + ], + "aliases": { + "RouterOS": "RouterOS\\Laravel\\ClientFacade" + } + } + }, "require": { - "php": "^7.1", + "php": "^7.2", "ext-sockets": "*" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^7.0", + "orchestra/testbench": "^3.0" } } diff --git a/configs/routeros-api.php b/configs/routeros-api.php new file mode 100644 index 0000000..91a3359 --- /dev/null +++ b/configs/routeros-api.php @@ -0,0 +1,13 @@ + null, + // 'user' => null, + // 'pass' => null, + // 'port' => null, + 'ssl' => false, + 'legacy' => false, + 'timeout' => 10, + 'attempts' => 10, + 'delay' => 1, +]; diff --git a/src/Config.php b/src/Config.php index edf8d37..78ef0cc 100644 --- a/src/Config.php +++ b/src/Config.php @@ -77,7 +77,7 @@ class Config implements ConfigInterface private function getPort(string $parameter) { // If client need port number and port is not set - if ($parameter === 'port' && !isset($this->_parameters['port'])) { + 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 diff --git a/src/Laravel/ClientFacade.php b/src/Laravel/ClientFacade.php new file mode 100644 index 0000000..952650a --- /dev/null +++ b/src/Laravel/ClientFacade.php @@ -0,0 +1,13 @@ +publishes([ + __DIR__ . '/../configs/routeros-api.php' => config_path('routeros-api.php'), + ]); + } + + /** + * Register any application services. + * + * @return void + */ + public function register() + { + $this->mergeConfigFrom( + __DIR__ . '/../configs/routeros-api.php', 'routeros-api' + ); + + $this->app->bind(ClientWrapper::class); + } +} diff --git a/src/Laravel/ClientWrapper.php b/src/Laravel/ClientWrapper.php new file mode 100644 index 0000000..ed8792f --- /dev/null +++ b/src/Laravel/ClientWrapper.php @@ -0,0 +1,24 @@ +