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

Commit d57522a

Browse files
author
fd6130
committed
update bundle configuration and class
1 parent 16e29e3 commit d57522a

File tree

5 files changed

+69
-13
lines changed

5 files changed

+69
-13
lines changed
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+
$paginatorDefinition = $container->getDefinition('fd.exabytes.exabytes');
21+
$paginatorDefinition->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)