1 | <?php declare(strict_types = 1); |
||
14 | abstract class AbstractAsynchronousMessageProducerFactory implements RequiresConfigId, ProvidesDefaultOptions |
||
15 | { |
||
16 | use ConfigurationTrait; |
||
17 | public const KEY_BRIDGE = 'bridge'; |
||
18 | public const KEY_ROUTES = 'routes'; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | private $configId; |
||
24 | |||
25 | 4 | public function __construct(string $configId) |
|
29 | |||
30 | /** |
||
31 | * Creates a new instance from a specified config, specifically meant to be used as static factory. |
||
32 | * @throws InvalidArgumentException |
||
33 | */ |
||
34 | 5 | public static function __callStatic(string $name, array $arguments): AsynchronousMessageProducer |
|
44 | |||
45 | 4 | public function __invoke(ContainerInterface $container): AsynchronousMessageProducer |
|
55 | |||
56 | 4 | public function dimensions(): iterable |
|
60 | |||
61 | 4 | public function defaultOptions(): iterable |
|
65 | |||
66 | 4 | private function getProducerconfg(ContainerInterface $container): array |
|
72 | |||
73 | 4 | private function createMessageProducer( |
|
82 | |||
83 | 4 | private function getProducerBridge( |
|
91 | |||
92 | 4 | private function getProducerBridgeServiceKey(array $producerConfig): string |
|
96 | |||
97 | 4 | private function getMessageConverter(ContainerInterface $container): MessageConverter |
|
101 | |||
102 | 4 | private function injectRoutesToProducer(array $producerConfig, AsynchronousMessageProducer $producer): void |
|
107 | } |
||
108 |
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.