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