From 16e29e3ad4f8cfe22a1ec46b1fa6fa00df0ad719 Mon Sep 17 00:00:00 2001 From: fd6130 Date: Thu, 23 Sep 2021 00:08:05 +0800 Subject: [PATCH 1/4] update README --- README.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 84a0feb..2d04f4c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,54 @@ -# exabytes-sms-bundle -Send sms using exabytes api +exabytes-sms-bundle +=================== + +Send sms using exabytes malaysia api. For more detail regarding the api, please read [documentation](https://support.exabytes.com.my/en/support/solutions/articles/14000110847-bulk-sms-api-integration). + +Requirement +=========== +* PHP 7.2+ +* Symfony 4.4+ and 5+ + +Installation +============ + +`composer require fd6130/exabytes-sms-bundle` + +> If you are using flex, it will automatic add this bundle to `bundles.php`. + +Configuration +============= + +Update your .env to include this two variable: + +``` +# .env +EXABYTES_USERNAME= +EXABYTES_PASSWORD= +``` + +And then create the config file `/config/fd_exabytes.yaml` and put the following content: + +```yaml +fd_exabytes: + username: '%env(EXABYTES_USERNAME)%' + password: '%env(EXABYTES_PASSWORD)%' +``` + +Inject `ExabytesInterface` and start sending sms: + +```php +private $exabytes; + +public function __construct(ExabytesInterface $exabytes) +{ + $this->exabytes = $exabytes; +} + +public function sendSMS() +{ + $this->exabytes->send('mobile number', 'message', ExabytesInterface::ASCII); + + //... +} + +``` \ No newline at end of file From d57522acf7eb3a9df395e5c0997883b10d586d25 Mon Sep 17 00:00:00 2001 From: fd6130 Date: Thu, 23 Sep 2021 00:08:25 +0800 Subject: [PATCH 2/4] update bundle configuration and class --- src/DependencyInjection/Configuration.php | 24 +++++++++++++++++++ .../FdExabytesExtension.php | 23 ++++++++++++++++++ src/Resources/config/services.yaml | 9 +++++++ src/Service/Exabytes.php | 19 +++++---------- src/Service/ExabytesInterface.php | 7 ++++++ 5 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 src/DependencyInjection/Configuration.php create mode 100644 src/DependencyInjection/FdExabytesExtension.php create mode 100644 src/Resources/config/services.yaml diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php new file mode 100644 index 0000000..9732fc1 --- /dev/null +++ b/src/DependencyInjection/Configuration.php @@ -0,0 +1,24 @@ +getRootNode(); + + $rootNode + ->children() + ->scalarNode('username')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('password')->isRequired()->cannotBeEmpty()->end() + ->end() + ; + + return $treeBuilder; + } +} \ No newline at end of file diff --git a/src/DependencyInjection/FdExabytesExtension.php b/src/DependencyInjection/FdExabytesExtension.php new file mode 100644 index 0000000..6790a61 --- /dev/null +++ b/src/DependencyInjection/FdExabytesExtension.php @@ -0,0 +1,23 @@ +load('services.yaml'); + + $configuration = $this->getConfiguration($configs, $container); + $config = $this->processConfiguration($configuration, $configs); + + $paginatorDefinition = $container->getDefinition('fd.exabytes.exabytes'); + $paginatorDefinition->setArgument(0, $config); + } +} \ No newline at end of file diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml new file mode 100644 index 0000000..c378505 --- /dev/null +++ b/src/Resources/config/services.yaml @@ -0,0 +1,9 @@ +services: + fd.exabytes.exabytes: + class: Fd\ExabytesBundle\Service\Exabytes + arguments: + $client: "@http_client" + Fd\ExabytesBundle\Service\Exabytes: + arguments: + $client: "@http_client" + Fd\ExabytesBundle\Service\ExabytesInterface: "@fd.exabytes.exabytes" \ No newline at end of file diff --git a/src/Service/Exabytes.php b/src/Service/Exabytes.php index b05baa9..48d53d3 100644 --- a/src/Service/Exabytes.php +++ b/src/Service/Exabytes.php @@ -3,35 +3,28 @@ namespace Fd\ExabytesBundle\Service; -use Fd\Exabytes\Exception\ExabytesException; +use Fd\ExabytesBundle\Exception\ExabytesException; use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; -/** - * @author fd6130 - */ class Exabytes implements ExabytesInterface { private $client; - private $params; - private $messageType = 1; + private $config; - public function __construct(string $username, string $password, int $messageType, HttpClientInterface $client) + public function __construct(array $config, HttpClientInterface $client) { - $this->messageType = $messageType; + $this->config = $config; $this->client = $client; } public function send(string $mobile, string $message, int $messageType) { - $username = $this->params->get('exabytes.username'); - $password = $this->params->get('exabytes.password'); - $endpoint = sprintf( 'https://smsportal.exabytes.my/isms_send.php?un=%s&pwd=%s&dstno=%s&msg=%s&type=%s&agreedterm=YES', - urlencode($username), - urlencode($password), + urlencode($this->config['username']), + urlencode($this->config['password']), urlencode($mobile), urlencode($message), $messageType diff --git a/src/Service/ExabytesInterface.php b/src/Service/ExabytesInterface.php index 005be3b..1582bef 100644 --- a/src/Service/ExabytesInterface.php +++ b/src/Service/ExabytesInterface.php @@ -2,12 +2,19 @@ namespace Fd\ExabytesBundle\Service; +use Fd\ExabytesBundle\Exception\ExabytesException; + interface ExabytesInterface { + const ASCII = 1; + const UNICODE = 2; + /** * @param string $mobile Mobile number * @param string $message Message * @param int $messageType Message Type (1 - ASCII, 2 - Unicode) + * + * @throws ExabytesException */ public function send(string $mobile, string $message, int $messageType); } \ No newline at end of file From d56b5ff8080001ab57db306f8dc43c82b1753852 Mon Sep 17 00:00:00 2001 From: fd6130 Date: Thu, 23 Sep 2021 00:09:48 +0800 Subject: [PATCH 3/4] update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c872acc..2e44405 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "fd6130/exabytes-sms-bundle", - "description": "This bundle provide sms service using exabytes api.", + "description": "This bundle provide sms service using exabytes malaysia api.", "keywords": ["Symfony", "symfony", "bundle", "sms", "exabytes"], "type": "symfony-bundle", "license": "MIT", From 2774fdb9edbf5d290a63a0571d57a9334de2011f Mon Sep 17 00:00:00 2001 From: fd6130 Date: Tue, 5 Oct 2021 00:44:01 +0800 Subject: [PATCH 4/4] fix typo --- src/DependencyInjection/FdExabytesExtension.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DependencyInjection/FdExabytesExtension.php b/src/DependencyInjection/FdExabytesExtension.php index 6790a61..8d75008 100644 --- a/src/DependencyInjection/FdExabytesExtension.php +++ b/src/DependencyInjection/FdExabytesExtension.php @@ -17,7 +17,7 @@ public function load(array $configs, ContainerBuilder $container): void $configuration = $this->getConfiguration($configs, $container); $config = $this->processConfiguration($configuration, $configs); - $paginatorDefinition = $container->getDefinition('fd.exabytes.exabytes'); - $paginatorDefinition->setArgument(0, $config); + $definition = $container->getDefinition('fd.exabytes.exabytes'); + $definition->setArgument(0, $config); } } \ No newline at end of file