Skip to content

Commit

Permalink
Merge pull request #4 from sim8568X/master
Browse files Browse the repository at this point in the history
Major Change, PSR-4 Change and Others
  • Loading branch information
sim8568X authored Apr 5, 2023
2 parents cfb3e0f + df08a73 commit 2794866
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 105 deletions.
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ composer require xenon/multisms
### Sample Code

<pre>
use Xenon\Provider\BulkSmsBD;
use Xenon\Sender;
use Xenon\Multisms\Provider\BulkSmsBD;
use Xenon\Multisms\Sender;

require 'vendor/autoload.php';

Expand Down
4 changes: 2 additions & 2 deletions src/Config/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php


namespace Xenon\Config;
namespace Xenon\Multisms\Config;


class Configuration
{

//todo:: write something here
}
2 changes: 1 addition & 1 deletion src/Handler/Formatter.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php


namespace Xenon\Handler;
namespace Xenon\Multisms\Handler;


class Formatter
Expand Down
47 changes: 10 additions & 37 deletions src/Handler/XenonException.php
Original file line number Diff line number Diff line change
@@ -1,56 +1,29 @@
<?php


namespace Xenon\Handler;
namespace Xenon\Multisms\Handler;


class XenonException extends \Exception
{
protected $message;
protected $code;

public function __construct($message, $code = null)
{
parent::__construct($message, $code);
}

/**
* @return array
* Report the exception.
*
* @return void
*/
public function showException($object = null): array
public function report()
{
$bt = debug_backtrace();
$exception = [
'exception' => $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 '<pre>';
print_r($exception);
echo '<pre>';
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;
}
}

}
2 changes: 1 addition & 1 deletion src/Provider/AbstractProvider.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php


namespace Xenon\Provider;
namespace Xenon\Multisms\Provider;


abstract class AbstractProvider implements ProviderRoadmap
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/Alpha.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php


namespace Xenon\Provider;
namespace Xenon\Multisms\Provider;


class Alpha implements ProviderRoadmap
Expand Down
6 changes: 3 additions & 3 deletions src/Provider/BDBulkSms.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php


namespace Xenon\Provider;
namespace Xenon\Multisms\Provider;


use Xenon\Handler\XenonException;
use Xenon\Sender;
use Xenon\Multisms\Handler\XenonException;
use Xenon\Multisms\Sender;

class BDBulkSms extends AbstractProvider
{
Expand Down
6 changes: 3 additions & 3 deletions src/Provider/BulkSmsBD.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php


namespace Xenon\Provider;
namespace Xenon\Multisms\Provider;


use Xenon\Handler\XenonException;
use Xenon\Sender;
use Xenon\Multisms\Handler\XenonException;
use Xenon\Multisms\Sender;

class BulkSmsBD extends AbstractProvider
{
Expand Down
6 changes: 3 additions & 3 deletions src/Provider/DianaHost.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php


namespace Xenon\Provider;
namespace Xenon\Multisms\Provider;


use GuzzleHttp\Client;
use Illuminate\Support\Facades\Config;
use Xenon\Handler\XenonException;
use Xenon\Sender;
use Xenon\Multisms\Handler\XenonException;
use Xenon\Multisms\Sender;
use function Couchbase\defaultDecoder;

class DianaHost extends AbstractProvider
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/DnsBd.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php


namespace Xenon\Provider;
namespace Xenon\Multisms\Provider;


class DnsBd extends AbstractProvider
Expand Down
6 changes: 3 additions & 3 deletions src/Provider/GreenWeb.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php


namespace Xenon\Provider;
namespace Xenon\Multisms\Provider;


use Xenon\Handler\XenonException;
use Xenon\Sender;
use Xenon\Multisms\Handler\XenonException;
use Xenon\Multisms\Sender;

class GreenWeb extends AbstractProvider
{
Expand Down
6 changes: 3 additions & 3 deletions src/Provider/MDL.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php


namespace Xenon\Provider;
namespace Xenon\Multisms\Provider;


use Xenon\Handler\XenonException;
use Xenon\Sender;
use Xenon\Multisms\Handler\XenonException;
use Xenon\Multisms\Sender;

class MDL extends AbstractProvider
{
Expand Down
7 changes: 4 additions & 3 deletions src/Provider/Mim.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Xenon\Provider;
namespace Xenon\Multisms\Provider;


use Xenon\Handler\XenonException;
use Xenon\Sender;
use Xenon\Multisms\Handler\XenonException;
use Xenon\Multisms\Sender;

class Mim extends AbstractProvider
{
Expand All @@ -19,6 +19,7 @@ public function __construct(Sender $sender)

/**
* Send Request To Api and Send Message
* @throws XenonException
*/
public function sendRequest(): array
{
Expand Down
6 changes: 3 additions & 3 deletions src/Provider/Onnorokom.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php


namespace Xenon\Provider;
namespace Xenon\Multisms\Provider;


use SoapClient;
use Xenon\Handler\XenonException;
use Xenon\Sender;
use Xenon\Multisms\Handler\XenonException;
use Xenon\Multisms\Sender;

class Onnorokom extends AbstractProvider
{
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/ProviderRoadmap.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php


namespace Xenon\Provider;
namespace Xenon\Multisms\Provider;


interface ProviderRoadmap
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/Sms4BD.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php


namespace Xenon\Provider;
namespace Xenon\Multisms\Provider;


use Xenon\Sender;
use Xenon\Multisms\Sender;

class Sms4BD implements ProviderRoadmap
{
Expand Down
6 changes: 3 additions & 3 deletions src/Provider/Ssl.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php


namespace Xenon\Provider;
namespace Xenon\Multisms\Provider;


use Xenon\Handler\XenonException;
use Xenon\Sender;
use Xenon\Multisms\Handler\XenonException;
use Xenon\Multisms\Sender;

class Ssl extends AbstractProvider
{
Expand Down
47 changes: 16 additions & 31 deletions src/Sender.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php


namespace Xenon;
namespace Xenon\Multisms;


use Exception;
use Xenon\Handler\XenonException;
use Xenon\Multisms\Handler\XenonException;

class Sender
{
Expand Down Expand Up @@ -42,29 +42,27 @@ public function getConfig()
*/
public function setConfig($config): Sender
{
try {
if (!is_array($config)) {
throw new XenonException('config must be an array');
}
$this->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()
{
try {
$this->provider->errorException();
return $this->provider->sendRequest();
} catch (XenonException $exception) {
$exception->showException();
throw new XenonException($exception->getMessage());
}
}

Expand Down Expand Up @@ -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;
}


Expand All @@ -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;
}

}

0 comments on commit 2794866

Please sign in to comment.