1 | <?php |
||
28 | class AMQPBackend implements BackendInterface |
||
29 | { |
||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $exchange; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $queue; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $key; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $recover; |
||
49 | |||
50 | /** |
||
51 | * @var null|string |
||
52 | */ |
||
53 | protected $deadLetterExchange; |
||
54 | |||
55 | /** |
||
56 | * @var AMQPBackendDispatcher |
||
57 | */ |
||
58 | protected $dispatcher = null; |
||
59 | |||
60 | /** |
||
61 | * @param string $exchange |
||
62 | * @param string $queue |
||
63 | * @param string $recover |
||
64 | * @param string $key |
||
65 | * @param string $deadLetterExchange |
||
66 | */ |
||
67 | public function __construct($exchange, $queue, $recover, $key, $deadLetterExchange = null) |
||
79 | |||
80 | /** |
||
81 | * @param AMQPBackendDispatcher $dispatcher |
||
82 | */ |
||
83 | public function setDispatcher(AMQPBackendDispatcher $dispatcher) |
||
84 | { |
||
85 | $this->dispatcher = $dispatcher; |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * {@inheritdoc} |
||
90 | */ |
||
91 | public function initialize() |
||
121 | |||
122 | /** |
||
123 | * {@inheritdoc} |
||
124 | */ |
||
125 | public function publish(MessageInterface $message) |
||
141 | |||
142 | /** |
||
143 | * {@inheritdoc} |
||
144 | */ |
||
145 | public function create($type, array $body) |
||
154 | |||
155 | /** |
||
156 | * {@inheritdoc} |
||
157 | */ |
||
158 | public function createAndPublish($type, array $body) |
||
159 | { |
||
160 | $this->publish($this->create($type, $body)); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * {@inheritdoc} |
||
165 | */ |
||
166 | public function getIterator() |
||
167 | { |
||
168 | return new AMQPMessageIterator($this->getChannel(), $this->queue); |
||
|
|||
169 | } |
||
170 | |||
171 | /** |
||
172 | * {@inheritdoc} |
||
173 | */ |
||
174 | public function handle(MessageInterface $message, EventDispatcherInterface $dispatcher) |
||
205 | |||
206 | /** |
||
207 | * {@inheritdoc} |
||
208 | */ |
||
209 | public function getStatus() |
||
219 | |||
220 | /** |
||
221 | * {@inheritdoc} |
||
222 | */ |
||
223 | public function cleanup() |
||
227 | |||
228 | /** |
||
229 | * @return AMQPChannel |
||
230 | */ |
||
231 | protected function getChannel() |
||
239 | } |
||
240 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.