Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throw excpetion instead of terminating whole process #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Exceptions/NotProperlyConfiguredException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Kavenegar\Exceptions;

class NotProperlyConfiguredException extends BaseRuntimeException
{
public function getName()
{
return 'NotProperlyConfigured';
}
}

?>
13 changes: 6 additions & 7 deletions src/KavenegarApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down