From 853b1f647dcae613e803b003399473969a20223c Mon Sep 17 00:00:00 2001 From: Shahin Sorkh Date: Wed, 17 Aug 2022 06:08:24 +0000 Subject: [PATCH] throw excpetion instead of terminating whole process --- src/Exceptions/NotProperlyConfiguredException.php | 13 +++++++++++++ src/KavenegarApi.php | 13 ++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 src/Exceptions/NotProperlyConfiguredException.php diff --git a/src/Exceptions/NotProperlyConfiguredException.php b/src/Exceptions/NotProperlyConfiguredException.php new file mode 100644 index 0000000..81d2171 --- /dev/null +++ b/src/Exceptions/NotProperlyConfiguredException.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/src/KavenegarApi.php b/src/KavenegarApi.php index ff0e946..351e65a 100644 --- a/src/KavenegarApi.php +++ b/src/KavenegarApi.php @@ -5,27 +5,26 @@ use Kavenegar\Exceptions\ApiException; use Kavenegar\Exceptions\HttpException; use Kavenegar\Exceptions\RuntimeException; -use Kavenegar\Enums\ApiLogs ; +use Kavenegar\Exceptions\NotProperlyConfiguredException; +use Kavenegar\Enums\ApiLogs; use Kavenegar\Enums\General; class KavenegarApi { const APIPATH = "%s://api.kavenegar.com/v1/%s/%s/%s.json/"; const VERSION = "1.2.2"; - public function __construct($apiKey,$insecure=false) + public function __construct($apiKey, $insecure=false) { if (!extension_loaded('curl')) { - die('cURL library is not loaded'); - exit; + throw new NotProperlyConfiguredException('cURL library is not loaded'); } if (is_null($apiKey)) { - die('apiKey is empty'); - exit; + throw new NotProperlyConfiguredException('apiKey is empty'); } $this->apiKey = trim($apiKey); $this->insecure = $insecure; } - + protected function get_path($method, $base = 'sms') { return sprintf(self::APIPATH,$this->insecure==true ? "http": "https", $this->apiKey, $base, $method);