1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2014 Underground Elephant |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
* |
18
|
|
|
* @package qpush-bundle |
19
|
|
|
* @copyright Underground Elephant 2014 |
20
|
|
|
* @license Apache License, Version 2.0 |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace Uecode\Bundle\QPushBundle\Provider; |
24
|
|
|
|
25
|
|
|
use Doctrine\Common\Cache\Cache; |
26
|
|
|
use Monolog\Logger; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @author Keith Kirk <[email protected]> |
30
|
|
|
*/ |
31
|
|
|
class CustomProvider extends AbstractProvider |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @type ProviderInterface |
35
|
|
|
*/ |
36
|
|
|
private $client; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param string $name |
40
|
|
|
* @param array $options |
41
|
|
|
* @param mixed $client |
42
|
|
|
* @param Cache $cache |
43
|
|
|
* @param Logger $logger |
44
|
|
|
*/ |
45
|
6 |
View Code Duplication |
public function __construct($name, array $options, $client, Cache $cache, Logger $logger) |
|
|
|
|
46
|
|
|
{ |
47
|
6 |
|
$this->name = $name; |
48
|
6 |
|
$this->options = $options; |
49
|
6 |
|
$this->cache = $cache; |
50
|
6 |
|
$this->logger = $logger; |
51
|
|
|
|
52
|
6 |
|
$this->setClient($client); |
53
|
6 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param ProviderInterface $client |
57
|
|
|
* |
58
|
|
|
* @return CustomProvider |
59
|
|
|
*/ |
60
|
6 |
|
public function setClient(ProviderInterface $client) |
61
|
|
|
{ |
62
|
6 |
|
$this->client = $client; |
63
|
|
|
|
64
|
6 |
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
public function getProvider() |
68
|
|
|
{ |
69
|
1 |
|
return 'Custom'; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Builds the configured queues |
74
|
|
|
* |
75
|
|
|
* If a Queue name is passed and configured, this method will build only that |
76
|
|
|
* Queue. |
77
|
|
|
* |
78
|
|
|
* All Create methods are idempotent, if the resource exists, the current ARN |
79
|
|
|
* will be returned |
80
|
|
|
* |
81
|
|
|
*/ |
82
|
1 |
|
public function create() |
83
|
|
|
{ |
84
|
1 |
|
return $this->client->create(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return Boolean |
89
|
|
|
*/ |
90
|
1 |
|
public function destroy() |
91
|
|
|
{ |
92
|
1 |
|
return $this->client->destroy(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* {@inheritDoc} |
97
|
|
|
* |
98
|
|
|
* This method will either use a SNS Topic to publish a queued message or |
99
|
|
|
* straight to SQS depending on the application configuration. |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
1 |
|
public function publish(array $message, array $options = []) |
104
|
|
|
{ |
105
|
1 |
|
return $this->client->publish($message, $options); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritDoc} |
110
|
|
|
*/ |
111
|
1 |
|
public function receive(array $options = []) |
112
|
|
|
{ |
113
|
1 |
|
return $this->client->receive($options); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* {@inheritDoc} |
118
|
|
|
* |
119
|
|
|
* @return bool |
120
|
|
|
*/ |
121
|
1 |
|
public function delete($id) |
122
|
|
|
{ |
123
|
1 |
|
return $this->client->delete($id); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.