Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 17be4d3

Browse files
author
fd6130
committed
Merge branch 'master' of github.com:fd6130/exabytes-sms-bundle
2 parents db697d9 + 2774fdb commit 17be4d3

File tree

7 files changed

+124
-16
lines changed

7 files changed

+124
-16
lines changed

README.md

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,54 @@
1-
# exabytes-sms-bundle
2-
Send sms using exabytes api
1+
exabytes-sms-bundle
2+
===================
3+
4+
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).
5+
6+
Requirement
7+
===========
8+
* PHP 7.2+
9+
* Symfony 4.4+ and 5+
10+
11+
Installation
12+
============
13+
14+
`composer require fd6130/exabytes-sms-bundle`
15+
16+
> If you are using flex, it will automatic add this bundle to `bundles.php`.
17+
18+
Configuration
19+
=============
20+
21+
Update your .env to include this two variable:
22+
23+
```
24+
# .env
25+
EXABYTES_USERNAME=
26+
EXABYTES_PASSWORD=
27+
```
28+
29+
And then create the config file `/config/fd_exabytes.yaml` and put the following content:
30+
31+
```yaml
32+
fd_exabytes:
33+
username: '%env(EXABYTES_USERNAME)%'
34+
password: '%env(EXABYTES_PASSWORD)%'
35+
```
36+
37+
Inject `ExabytesInterface` and start sending sms:
38+
39+
```php
40+
private $exabytes;
41+
42+
public function __construct(ExabytesInterface $exabytes)
43+
{
44+
$this->exabytes = $exabytes;
45+
}
46+
47+
public function sendSMS()
48+
{
49+
$this->exabytes->send('mobile number', 'message', ExabytesInterface::ASCII);
50+
51+
//...
52+
}
53+
54+
```

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fd6130/exabytes-sms-bundle",
3-
"description": "This bundle provide sms service using exabytes api.",
3+
"description": "This bundle provide sms service using exabytes malaysia api.",
44
"keywords": ["Symfony", "symfony", "bundle", "sms", "exabytes"],
55
"type": "symfony-bundle",
66
"license": "MIT",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Fd\ExabytesBundle\DependencyInjection;
4+
5+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6+
use Symfony\Component\Config\Definition\ConfigurationInterface;
7+
8+
class Configuration implements ConfigurationInterface
9+
{
10+
public function getConfigTreeBuilder(): TreeBuilder
11+
{
12+
$treeBuilder = new TreeBuilder('fd_exabytes');
13+
$rootNode = $treeBuilder->getRootNode();
14+
15+
$rootNode
16+
->children()
17+
->scalarNode('username')->isRequired()->cannotBeEmpty()->end()
18+
->scalarNode('password')->isRequired()->cannotBeEmpty()->end()
19+
->end()
20+
;
21+
22+
return $treeBuilder;
23+
}
24+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Fd\ExabytesBundle\DependencyInjection;
4+
5+
use Symfony\Component\Config\FileLocator;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
8+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
9+
10+
class FdExabytesExtension extends Extension
11+
{
12+
public function load(array $configs, ContainerBuilder $container): void
13+
{
14+
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
15+
$loader->load('services.yaml');
16+
17+
$configuration = $this->getConfiguration($configs, $container);
18+
$config = $this->processConfiguration($configuration, $configs);
19+
20+
$definition = $container->getDefinition('fd.exabytes.exabytes');
21+
$definition->setArgument(0, $config);
22+
}
23+
}

src/Resources/config/services.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
fd.exabytes.exabytes:
3+
class: Fd\ExabytesBundle\Service\Exabytes
4+
arguments:
5+
$client: "@http_client"
6+
Fd\ExabytesBundle\Service\Exabytes:
7+
arguments:
8+
$client: "@http_client"
9+
Fd\ExabytesBundle\Service\ExabytesInterface: "@fd.exabytes.exabytes"

src/Service/Exabytes.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,28 @@
33

44
namespace Fd\ExabytesBundle\Service;
55

6-
use Fd\Exabytes\Exception\ExabytesException;
6+
use Fd\ExabytesBundle\Exception\ExabytesException;
77
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
88
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
99
use Symfony\Contracts\HttpClient\HttpClientInterface;
1010

11-
/**
12-
* @author fd6130
13-
*/
1411
class Exabytes implements ExabytesInterface
1512
{
1613
private $client;
17-
private $params;
18-
private $messageType = 1;
14+
private $config;
1915

20-
public function __construct(string $username, string $password, int $messageType, HttpClientInterface $client)
16+
public function __construct(array $config, HttpClientInterface $client)
2117
{
22-
$this->messageType = $messageType;
18+
$this->config = $config;
2319
$this->client = $client;
2420
}
2521

2622
public function send(string $mobile, string $message, int $messageType)
2723
{
28-
$username = $this->params->get('exabytes.username');
29-
$password = $this->params->get('exabytes.password');
30-
3124
$endpoint = sprintf(
3225
'https://smsportal.exabytes.my/isms_send.php?un=%s&pwd=%s&dstno=%s&msg=%s&type=%s&agreedterm=YES',
33-
urlencode($username),
34-
urlencode($password),
26+
urlencode($this->config['username']),
27+
urlencode($this->config['password']),
3528
urlencode($mobile),
3629
urlencode($message),
3730
$messageType

src/Service/ExabytesInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22

33
namespace Fd\ExabytesBundle\Service;
44

5+
use Fd\ExabytesBundle\Exception\ExabytesException;
6+
57
interface ExabytesInterface
68
{
9+
const ASCII = 1;
10+
const UNICODE = 2;
11+
712
/**
813
* @param string $mobile Mobile number
914
* @param string $message Message
1015
* @param int $messageType Message Type (1 - ASCII, 2 - Unicode)
16+
*
17+
* @throws ExabytesException
1118
*/
1219
public function send(string $mobile, string $message, int $messageType);
1320
}

0 commit comments

Comments
 (0)