From 6350d734e8a85df8698ce94116ac3afd61bad121 Mon Sep 17 00:00:00 2001 From: Kristen Mollina Date: Wed, 5 Apr 2023 14:20:41 +0600 Subject: [PATCH] change psr-4 depen, codeformat, restructed and formatting --- composer.json | 6 ++-- readme.md | 4 +-- src/Config/Configuration.php | 4 +-- src/Handler/Formatter.php | 2 +- src/Handler/XenonException.php | 47 +++++++------------------------ src/Provider/AbstractProvider.php | 2 +- src/Provider/Alpha.php | 2 +- src/Provider/BDBulkSms.php | 6 ++-- src/Provider/BulkSmsBD.php | 6 ++-- src/Provider/DianaHost.php | 6 ++-- src/Provider/DnsBd.php | 2 +- src/Provider/GreenWeb.php | 6 ++-- src/Provider/MDL.php | 6 ++-- src/Provider/Mim.php | 7 +++-- src/Provider/Onnorokom.php | 6 ++-- src/Provider/ProviderRoadmap.php | 2 +- src/Provider/Sms4BD.php | 4 +-- src/Provider/Ssl.php | 6 ++-- src/Sender.php | 47 +++++++++++-------------------- 19 files changed, 66 insertions(+), 105 deletions(-) diff --git a/composer.json b/composer.json index 721b52c..4782489 100644 --- a/composer.json +++ b/composer.json @@ -11,11 +11,13 @@ ], "minimum-stability": "stable", "require": { - "guzzlehttp/guzzle": "^6.3" + "guzzlehttp/guzzle": "^6.3", + "ext-curl": "*", + "ext-mbstring": "*" }, "autoload": { "psr-4": { - "Xenon\\": "src/" + "Xenon\\Multisms\\": "src/" } }, "autoload-dev": { diff --git a/readme.md b/readme.md index e198520..b3629ed 100644 --- a/readme.md +++ b/readme.md @@ -10,8 +10,8 @@ composer require xenon/multisms ### Sample Code
-use Xenon\Provider\BulkSmsBD;
-use Xenon\Sender;
+use Xenon\Multisms\Provider\BulkSmsBD;
+use Xenon\Multisms\Sender;
 
 require 'vendor/autoload.php';
 
diff --git a/src/Config/Configuration.php b/src/Config/Configuration.php
index b4b04db..9f62742 100644
--- a/src/Config/Configuration.php
+++ b/src/Config/Configuration.php
@@ -1,10 +1,10 @@
  $this->getMessage(),
-            'used_file' => [
-                'file' => $bt[0]['file'] . ' at line: ' . $bt[0]['line'],
-                'class' => $bt[1]['class'],
-                'method' => $bt[1]['function'] . '()',
-                'called by' => $this->getCaller()
-            ]
-        ];
-        echo '
';
-        print_r($exception);
-        echo '
';
-        exit;
     }
 
     /**
-     * Gets the caller of the function where this function is called from
-     * @param string what to return? (Leave empty to get all, or specify: "class", "function", "line", "class", etc.) -
-     * options see: http://php.net/manual/en/function.debug-backtrace.php
-     * @return mixed
+     * Render the exception into an HTTP response.
+     *
+     * @param Request $request
+     * @return Response
      */
-    private function getCaller($what = NULL)
+    public function render(Request $request)
     {
-        $trace = debug_backtrace();
-        $previousCall = $trace[2]; // 0 is this call, 1 is call in previous function, 2 is caller of that function
 
-        if (isset($what)) {
-            return $previousCall[$what];
-        } else {
-            return $previousCall;
-        }
     }
 
 }
\ No newline at end of file
diff --git a/src/Provider/AbstractProvider.php b/src/Provider/AbstractProvider.php
index 016e3be..cfb3ece 100644
--- a/src/Provider/AbstractProvider.php
+++ b/src/Provider/AbstractProvider.php
@@ -1,7 +1,7 @@
 config = $config;
-        } catch (XenonException $e) {
-            $e->showException();
+        if (!is_array($config)) {
+            throw  new XenonException('config must be an array');
         }
 
+        $this->config = $config;
+
         return $this;
     }
 
 
     /**
      * Send Message Finally
+     * @throws XenonException
      */
     public function send()
     {
@@ -64,7 +62,7 @@ public function send()
             $this->provider->errorException();
             return $this->provider->sendRequest();
         } catch (XenonException $exception) {
-            $exception->showException();
+            throw new XenonException($exception->getMessage());
         }
     }
 
@@ -107,11 +105,17 @@ public function setMessage($message = ''): Sender
     /**
      * @param mixed $provider
      * @return Sender
+     * @throws XenonException
      */
     public function setProvider($provider): Sender
     {
-        $this->provider = $provider;
-        return self::getInstance();
+        if (!class_exists($provider)) {
+            throw new XenonException('Provider ' . $provider . ' not found');
+        }
+
+        $this->provider = new $provider($this);
+
+        return $this;
     }
 
 
@@ -123,23 +127,4 @@ public function getProvider()
         return $this->provider;
     }
 
-    /**
-     * Return this class object
-     * @param $ProviderClass
-     * @return Sender
-     */
-    public function selectProvider($ProviderClass): Sender
-    {
-        try {
-            if (!class_exists($ProviderClass)) {
-                throw new XenonException('Provider ' . $ProviderClass . ' not found');
-            }
-        } catch (XenonException $exception) {
-            $exception->showException($ProviderClass);
-        }
-
-        $this->provider = new $ProviderClass($this);
-        return $this;
-    }
-
 }
\ No newline at end of file