1 | <?php |
||
34 | class SimpleMessageBusBuilder |
||
35 | { |
||
36 | const DEFAULT_NAME = 'message-bus'; |
||
37 | |||
38 | /** |
||
39 | * @var AnnotatedMessageHandlerDescriptorFactory |
||
40 | */ |
||
41 | private static $defaultHandlerDescFactory; |
||
42 | |||
43 | /** |
||
44 | * @var NullSubscriberExceptionHandler |
||
45 | */ |
||
46 | private static $defaultExceptionHandler; |
||
47 | |||
48 | /** |
||
49 | * @var string |
||
50 | */ |
||
51 | private $identifier; |
||
52 | |||
53 | /** |
||
54 | * @var DispatchInterceptor[] |
||
55 | */ |
||
56 | private $interceptors = []; |
||
57 | |||
58 | /** |
||
59 | * @var SubscriberExceptionHandler |
||
60 | */ |
||
61 | private $exceptionHandler; |
||
62 | |||
63 | /** |
||
64 | * @var MessageHandlerDescriptorFactory |
||
65 | */ |
||
66 | private $handlerDescriptorFactory; |
||
67 | |||
68 | public function __construct() |
||
74 | |||
75 | /** |
||
76 | * Should not be called! |
||
77 | */ |
||
78 | public static function init() |
||
85 | |||
86 | /** |
||
87 | * Override if the default name should be modified. |
||
88 | * |
||
89 | * @return string |
||
90 | */ |
||
91 | protected static function defaultName() |
||
95 | |||
96 | /** |
||
97 | * Override if the default factory should be modified. |
||
98 | * |
||
99 | * @return AnnotatedMessageHandlerDescriptorFactory |
||
100 | */ |
||
101 | protected static function defaultHandlerDescFactory() |
||
105 | |||
106 | /** |
||
107 | * Override if the default exception handler should be modified. |
||
108 | * |
||
109 | * @return NullSubscriberExceptionHandler |
||
110 | */ |
||
111 | protected static function defaultExceptionHandler() |
||
115 | |||
116 | /** |
||
117 | * @return SimpleMessageBus |
||
118 | */ |
||
119 | public function build() |
||
123 | |||
124 | /** |
||
125 | * @param $identifier |
||
126 | * @return $this |
||
127 | */ |
||
128 | public function withIdentifier($identifier) |
||
133 | |||
134 | /** |
||
135 | * @param DispatchInterceptor[] $interceptors |
||
136 | * @return $this |
||
137 | */ |
||
138 | public function withInterceptors(array $interceptors) |
||
143 | |||
144 | /** |
||
145 | * @param SubscriberExceptionHandler $exceptionHandler |
||
146 | * @return $this |
||
147 | */ |
||
148 | public function withExceptionHandler(SubscriberExceptionHandler $exceptionHandler) |
||
153 | |||
154 | /** |
||
155 | * @param MessageHandlerDescriptorFactory $descriptorFactory |
||
156 | * @return $this |
||
157 | */ |
||
158 | public function withHandlerDescriptorFactory(MessageHandlerDescriptorFactory $descriptorFactory) |
||
163 | |||
164 | /** |
||
165 | * @return SubscriberExceptionHandler |
||
166 | */ |
||
167 | public function getExceptionHandler() |
||
171 | |||
172 | /** |
||
173 | * @return MessageHandlerDescriptorFactory |
||
174 | */ |
||
175 | public function getHandlerDescriptorFactory() |
||
179 | |||
180 | /** |
||
181 | * @return string |
||
182 | */ |
||
183 | public function getIdentifier() |
||
187 | |||
188 | /** |
||
189 | * @return DispatchInterceptor[] |
||
190 | */ |
||
191 | public function getInterceptors() |
||
195 | } |
||
196 | SimpleMessageBusBuilder::init(); |
||
197 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.