@@ 21-66 (lines=46) @@ | ||
18 | * |
|
19 | * @author Filippo Galante <[email protected]> |
|
20 | */ |
|
21 | class BuzzConnector implements ConnectorInterface |
|
22 | { |
|
23 | ||
24 | /** |
|
25 | * Establish an adapter connection. |
|
26 | * |
|
27 | * @param string[] $config |
|
28 | * |
|
29 | * @return \IlGala\SMSFactor\Adapters\BuzzAdapter |
|
30 | */ |
|
31 | public function connect(array $config) |
|
32 | { |
|
33 | $config = $this->getConfig($config); |
|
34 | return $this->getAdapter($config); |
|
35 | } |
|
36 | ||
37 | /** |
|
38 | * Get the configuration. |
|
39 | * |
|
40 | * @param string[] $config |
|
41 | * |
|
42 | * @throws \InvalidArgumentException |
|
43 | * |
|
44 | * @return string[] |
|
45 | */ |
|
46 | protected function getConfig(array $config) |
|
47 | { |
|
48 | if (!array_key_exists('username', $config) || !array_key_exists('password', $config) || !array_key_exists('accept', $config)) { |
|
49 | throw new InvalidArgumentException('The buzz connector requires configuration.'); |
|
50 | } |
|
51 | return array_only($config, ['username', 'password', 'accept']); |
|
52 | } |
|
53 | ||
54 | /** |
|
55 | * Get the buzz adapter. |
|
56 | * |
|
57 | * @param string[] $config |
|
58 | * |
|
59 | * @return \IlGala\SMSFactor\Adapters\BuzzAdapter |
|
60 | */ |
|
61 | protected function getAdapter(array $config) |
|
62 | { |
|
63 | return new BuzzAdapter($config['username'], $config['password'], $config['accept']); |
|
64 | } |
|
65 | ||
66 | } |
|
67 |
@@ 23-68 (lines=46) @@ | ||
20 | * |
|
21 | * @author Filippo Galante <[email protected]> |
|
22 | */ |
|
23 | class GuzzleConnector |
|
24 | { |
|
25 | ||
26 | /** |
|
27 | * Establish an adapter connection. |
|
28 | * |
|
29 | * @param string[] $config |
|
30 | * |
|
31 | * @return \IlGala\SMSFactor\Adapters\GuzzleAdapter |
|
32 | */ |
|
33 | public function connect(array $config) |
|
34 | { |
|
35 | $config = $this->getConfig($config); |
|
36 | return $this->getAdapter($config); |
|
37 | } |
|
38 | ||
39 | /** |
|
40 | * Get the configuration. |
|
41 | * |
|
42 | * @param string[] $config |
|
43 | * |
|
44 | * @throws \InvalidArgumentException |
|
45 | * |
|
46 | * @return string[] |
|
47 | */ |
|
48 | protected function getConfig(array $config) |
|
49 | { |
|
50 | if (!array_key_exists('username', $config) || !array_key_exists('password', $config) || !array_key_exists('accept', $config)) { |
|
51 | throw new InvalidArgumentException('The guzzle connector requires configuration.'); |
|
52 | } |
|
53 | return array_only($config, ['username', 'password', 'accept']); |
|
54 | } |
|
55 | ||
56 | /** |
|
57 | * Get the guzzle adapter. |
|
58 | * |
|
59 | * @param string[] $config |
|
60 | * |
|
61 | * @return \IlGala\SMSFactor\Adapters\GuzzleAdapter |
|
62 | */ |
|
63 | protected function getAdapter(array $config) |
|
64 | { |
|
65 | return new GuzzleAdapter($config['username'], $config['password'], $config['accept']); |
|
66 | } |
|
67 | ||
68 | } |
|
69 |
@@ 21-66 (lines=46) @@ | ||
18 | /** |
|
19 | * @author Filippo Galante <[email protected]> |
|
20 | */ |
|
21 | class GuzzleHttpConnector implements ConnectorInterface |
|
22 | { |
|
23 | ||
24 | /** |
|
25 | * Establish an adapter connection. |
|
26 | * |
|
27 | * @param string[] $config |
|
28 | * |
|
29 | * @return \IlGala\SMSFactor\Adapters\GuzzleHttpAdapter |
|
30 | */ |
|
31 | public function connect(array $config) |
|
32 | { |
|
33 | $config = $this->getConfig($config); |
|
34 | return $this->getAdapter($config); |
|
35 | } |
|
36 | ||
37 | /** |
|
38 | * Get the configuration. |
|
39 | * |
|
40 | * @param string[] $config |
|
41 | * |
|
42 | * @throws \InvalidArgumentException |
|
43 | * |
|
44 | * @return string[] |
|
45 | */ |
|
46 | protected function getConfig(array $config) |
|
47 | { |
|
48 | if (!array_key_exists('username', $config) || !array_key_exists('password', $config) || !array_key_exists('accept', $config)) { |
|
49 | throw new InvalidArgumentException('The guzzlehttp connector requires configuration.'); |
|
50 | } |
|
51 | return array_only($config, ['username', 'password', 'accept']); |
|
52 | } |
|
53 | ||
54 | /** |
|
55 | * Get the guzzlehttp adapter. |
|
56 | * |
|
57 | * @param string[] $config |
|
58 | * |
|
59 | * @return \IlGala\SMSFactor\Adapters\GuzzleHttpAdapter |
|
60 | */ |
|
61 | protected function getAdapter(array $config) |
|
62 | { |
|
63 | return new GuzzleHttpAdapter($config['username'], $config['password'], $config['accept']); |
|
64 | } |
|
65 | ||
66 | } |
|
67 |