@@ -42,7 +42,7 @@ |
||
42 | 42 | |
43 | 43 | /** |
44 | 44 | * @access public |
45 | - * @param $eventName |
|
45 | + * @param string $eventName |
|
46 | 46 | * @return |
47 | 47 | */ |
48 | 48 | public function setEventName($eventName){ |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | * @param $inputChannel |
32 | 32 | * @return |
33 | 33 | */ |
34 | - public function setInputChannel(\PEIP\INF\Channel\Channel $inputChannel){ |
|
35 | - if(isset($this->eventName)){ |
|
34 | + public function setInputChannel(\PEIP\INF\Channel\Channel $inputChannel) { |
|
35 | + if (isset($this->eventName)) { |
|
36 | 36 | $this->connectChannel($inputChannel); |
37 | - }else{ |
|
37 | + }else { |
|
38 | 38 | $this->inputChannel = $inputChannel; |
39 | 39 | } |
40 | 40 | } |
@@ -45,10 +45,10 @@ discard block |
||
45 | 45 | * @param $eventName |
46 | 46 | * @return |
47 | 47 | */ |
48 | - public function setEventName($eventName){ |
|
49 | - if(!isset($this->eventName)){ |
|
48 | + public function setEventName($eventName) { |
|
49 | + if (!isset($this->eventName)) { |
|
50 | 50 | $this->eventName = $eventName; |
51 | - if($this->inputChannel){ |
|
51 | + if ($this->inputChannel) { |
|
52 | 52 | $this->inputChannel->connect($this->eventName, $this); |
53 | 53 | } |
54 | 54 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | protected function getMessage($object){ |
18 | 18 | if($this->channel instanceof \PEIP\INF\Channel\SubscribableChannel){ |
19 | 19 | return $object; |
20 | - }else{ |
|
20 | + } else{ |
|
21 | 21 | return $object->getContent()->receive(); |
22 | 22 | } |
23 | 23 | } |
@@ -24,8 +24,8 @@ |
||
24 | 24 | */ |
25 | 25 | |
26 | 26 | |
27 | -use PEIP\Dispatcher\Dispatcher; |
|
28 | -use PEIP\Event\Event; |
|
27 | +use PEIP\Dispatcher\Dispatcher; |
|
28 | +use PEIP\Event\Event; |
|
29 | 29 | use PEIP\Util\Test; |
30 | 30 | |
31 | 31 | class Pipe |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @param $name |
64 | 64 | * @return |
65 | 65 | */ |
66 | - public function setName($name){ |
|
66 | + public function setName($name) { |
|
67 | 67 | $this->name = $name; |
68 | 68 | } |
69 | 69 | |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * @access public |
73 | 73 | * @return |
74 | 74 | */ |
75 | - public function getName(){ |
|
75 | + public function getName() { |
|
76 | 76 | return $this->name; |
77 | 77 | } |
78 | 78 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * @param $timeout |
84 | 84 | * @return |
85 | 85 | */ |
86 | - public function send(\PEIP\INF\Message\Message $message, $timeout = -1){ |
|
86 | + public function send(\PEIP\INF\Message\Message $message, $timeout = -1) { |
|
87 | 87 | return $this->handle($message); |
88 | 88 | } |
89 | 89 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param $message |
94 | 94 | * @return |
95 | 95 | */ |
96 | - protected function doSend(\PEIP\INF\Message\Message $message){ |
|
96 | + protected function doSend(\PEIP\INF\Message\Message $message) { |
|
97 | 97 | $this->doFireEvent(self::EVENT_PRE_PUBLISH, array(self::HEADER_MESSAGE=>$message)); |
98 | 98 | $this->getMessageDispatcher()->notify($message); |
99 | 99 | $this->doFireEvent(self::EVENT_POST_PUBLISH, array(self::HEADER_MESSAGE=>$message)); |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | * @param $content |
107 | 107 | * @return |
108 | 108 | */ |
109 | - protected function replyMessage($message){ |
|
110 | - if(\PEIP\Util\Test::assertMessage($message)){ |
|
111 | - if($this->getOutputChannel()){ |
|
109 | + protected function replyMessage($message) { |
|
110 | + if (\PEIP\Util\Test::assertMessage($message)) { |
|
111 | + if ($this->getOutputChannel()) { |
|
112 | 112 | $this->getOutputChannel()->send($message); |
113 | - }else{ |
|
113 | + }else { |
|
114 | 114 | $this->doSend($message); |
115 | 115 | } |
116 | 116 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * @param $message |
123 | 123 | * @return |
124 | 124 | */ |
125 | - protected function doReply(\PEIP\INF\Message\Message $message){ |
|
125 | + protected function doReply(\PEIP\INF\Message\Message $message) { |
|
126 | 126 | $this->replyMessage($message); |
127 | 127 | } |
128 | 128 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * @param $handler |
133 | 133 | * @return |
134 | 134 | */ |
135 | - public function subscribe($handler){ |
|
135 | + public function subscribe($handler) { |
|
136 | 136 | Test::ensureHandler($handler); |
137 | 137 | $this->getMessageDispatcher()->connect($handler); |
138 | 138 | $this->doFireEvent(self::EVENT_SUBSCRIBE, array(self::HEADER_SUBSCRIBER=>$handler)); |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @param $handler e |
145 | 145 | * @return |
146 | 146 | */ |
147 | - public function unsubscribe($handler){ |
|
147 | + public function unsubscribe($handler) { |
|
148 | 148 | Test::ensureHandler($handler); |
149 | 149 | $this->getMessageDispatcher()->disconnect($handler); |
150 | 150 | $this->doFireEvent( |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | * @param $transferListeners |
163 | 163 | * @return |
164 | 164 | */ |
165 | - public function setMessageDispatcher(\PEIP\INF\Dispatcher\Dispatcher $dispatcher, $transferListeners = true){ |
|
166 | - if(isset($this->dispatcher) && $transferListeners){ |
|
167 | - foreach($this->dispatcher->getListeners() as $listener){ |
|
165 | + public function setMessageDispatcher(\PEIP\INF\Dispatcher\Dispatcher $dispatcher, $transferListeners = true) { |
|
166 | + if (isset($this->dispatcher) && $transferListeners) { |
|
167 | + foreach ($this->dispatcher->getListeners() as $listener) { |
|
168 | 168 | $dispatcher->connect($listener); |
169 | 169 | $this->dispatcher->disconnect($listener); |
170 | 170 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @access public |
179 | 179 | * @return |
180 | 180 | */ |
181 | - public function getMessageDispatcher(){ |
|
181 | + public function getMessageDispatcher() { |
|
182 | 182 | $defaultDispatcher = self::DEFAULT_CLASS_MESSAGE_DISPATCHER; |
183 | 183 | return isset($this->dispatcher) ? $this->dispatcher : $this->dispatcher = new $defaultDispatcher; |
184 | 184 | } |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * @param $callable |
191 | 191 | * @return |
192 | 192 | */ |
193 | - protected function registerCommand($commandName, $callable){ |
|
193 | + protected function registerCommand($commandName, $callable) { |
|
194 | 194 | $this->commands[$commandName] = $callable; |
195 | 195 | } |
196 | 196 | |
@@ -200,10 +200,10 @@ discard block |
||
200 | 200 | * @param $cmdMessage |
201 | 201 | * @return |
202 | 202 | */ |
203 | - public function command(\PEIP\INF\Message\Message $cmdMessage){ |
|
203 | + public function command(\PEIP\INF\Message\Message $cmdMessage) { |
|
204 | 204 | $this->doFireEvent(self::EVENT_PRE_COMMAND, array(self::HEADER_MESSAGE=>$cmdMessage)); |
205 | 205 | $commandName = trim((string)$cmdMessage->getHeader('COMMAND')); |
206 | - if($commandName != '' && array_key_exists($commandName, $this->commands)){ |
|
206 | + if ($commandName != '' && array_key_exists($commandName, $this->commands)) { |
|
207 | 207 | call_user_func($this->commands[$commandName], $cmdMessage->getContent()); |
208 | 208 | } |
209 | 209 | $this->doFireEvent(self::EVENT_POST_COMMAND, array(self::HEADER_MESSAGE=>$cmdMessage)); |
@@ -54,7 +54,7 @@ |
||
54 | 54 | $store = $this->factory->build(); |
55 | 55 | if($store instanceof \PEIP\INF\Data\Store){ |
56 | 56 | $this->setPrivateValue($namespace, $store); |
57 | - }else{ |
|
57 | + } else{ |
|
58 | 58 | throw new \Exception('Could not build Instance of \PEIP\INF\Data\Store from factory.'); |
59 | 59 | } |
60 | 60 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * |
218 | 218 | * @access protected |
219 | 219 | * @param object $config configuration object to create arguments from. |
220 | - * @return mixed build arguments |
|
220 | + * @return \PEIP\INF\Channel\Channel[] build arguments |
|
221 | 221 | */ |
222 | 222 | protected function getReplyHandlerArguments($config){ |
223 | 223 | $args = array( |
@@ -262,7 +262,8 @@ discard block |
||
262 | 262 | * |
263 | 263 | * @access protected |
264 | 264 | * @param string the configuration type ofthe channel (e.g.: 'reply', 'request') |
265 | - * @param object $config configuration object to return channel from. |
|
265 | + * @param object $config configuration object to return channel from. |
|
266 | + * @param string $type |
|
266 | 267 | * @return \PEIP\INF\Channel\Channel reply-channel |
267 | 268 | */ |
268 | 269 | public function doGetChannel($type, $config){ |
@@ -11,11 +11,11 @@ |
||
11 | 11 | * |
12 | 12 | * @author timo |
13 | 13 | */ |
14 | -use PEIP\Context\XMLContext; |
|
15 | -use PEIP\Channel\PollableChannel; |
|
16 | -use PEIP\Channel\PublishSubscribeChannel; |
|
17 | -use PEIP\Gateway\SimpleMessagingGateway; |
|
18 | -use PEIP\Listener\Wiretap; |
|
14 | +use PEIP\Context\XMLContext; |
|
15 | +use PEIP\Channel\PollableChannel; |
|
16 | +use PEIP\Channel\PublishSubscribeChannel; |
|
17 | +use PEIP\Gateway\SimpleMessagingGateway; |
|
18 | +use PEIP\Listener\Wiretap; |
|
19 | 19 | use PEIP\Service\ServiceActivator; |
20 | 20 | |
21 | 21 | class BasePlugin extends \PEIP\ABS\Context\ContextPlugin { |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @param object $config configuration object for the pollable channel. |
47 | 47 | * @return \PEIP\INF\Channel\Channel the created pollable channel instance |
48 | 48 | */ |
49 | - public function createChannel($config){ |
|
49 | + public function createChannel($config) { |
|
50 | 50 | return $this->doCreateChannel($config, 'PollableChannel'); |
51 | 51 | } |
52 | 52 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @param object $config configuration object for the subscribable channel. |
59 | 59 | * @return \PEIP\INF\Channel\Channel the created subscribable channel instance |
60 | 60 | */ |
61 | - public function createSubscribableChannel($config){ |
|
61 | + public function createSubscribableChannel($config) { |
|
62 | 62 | return $this->doCreateChannel($config, 'PublishSubscribeChannel'); |
63 | 63 | } |
64 | 64 | |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | * @param $additionalArguments additional arguments for the channel constructor (without first arg = id) |
72 | 72 | * @return \PEIP\INF\Channel\Channel the created channel instance |
73 | 73 | */ |
74 | - public function doCreateChannel($config, $defaultChannelClass, array $additionalArguments = array()){ |
|
74 | + public function doCreateChannel($config, $defaultChannelClass, array $additionalArguments = array()) { |
|
75 | 75 | $id = (string)$config['id']; |
76 | - if($id != ''){ |
|
76 | + if ($id != '') { |
|
77 | 77 | array_unshift($additionalArguments, $id); |
78 | 78 | $channel = $this->buildAndModify($config, $additionalArguments, $defaultChannelClass); |
79 | 79 | //$this->channelRegistry->register($channel); |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @param string $defaultClass the class to use if none is set in config. |
92 | 92 | * @return object the gateway instance |
93 | 93 | */ |
94 | - public function createGateway($config, $defaultClass = false){ |
|
94 | + public function createGateway($config, $defaultClass = false) { |
|
95 | 95 | $args = array( |
96 | 96 | $this->getRequestChannel($config), |
97 | 97 | $this->getReplyChannel($config) |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @param string $defaultClass the class to use if none is set in config. |
116 | 116 | * @return object the router instance |
117 | 117 | */ |
118 | - public function createRouter($config, $defaultClass = false){ |
|
118 | + public function createRouter($config, $defaultClass = false) { |
|
119 | 119 | $resolver = $config['channel_resolver'] ? (string)$config['channel_resolver'] : $this->channelRegistry; |
120 | 120 | return $this->buildAndModify($config, array( |
121 | 121 | $resolver, |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * @param object $config configuration object for the splitter. |
133 | 133 | * @return object the splitter instance |
134 | 134 | */ |
135 | - public function createSplitter($config){ |
|
135 | + public function createSplitter($config) { |
|
136 | 136 | return $this->createReplyMessageHandler($config); |
137 | 137 | } |
138 | 138 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @param object $config configuration object for the transformer. |
146 | 146 | * @return object the transformer instance |
147 | 147 | */ |
148 | - public function createTransformer($config){ |
|
148 | + public function createTransformer($config) { |
|
149 | 149 | return $this->createReplyMessageHandler($config); |
150 | 150 | } |
151 | 151 | |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @param object $config configuration object for the aggregator. |
159 | 159 | * @return object the aggregator instance |
160 | 160 | */ |
161 | - public function createAggregator($config){ |
|
161 | + public function createAggregator($config) { |
|
162 | 162 | return $this->createReplyMessageHandler($config); |
163 | 163 | } |
164 | 164 | |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * @param object $config configuration object for the wiretap. |
172 | 172 | * @return object the wiretap instance |
173 | 173 | */ |
174 | - public function createWiretap($config){ |
|
174 | + public function createWiretap($config) { |
|
175 | 175 | return $this->createReplyMessageHandler($config, 'Wiretap'); |
176 | 176 | } |
177 | 177 | |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * @param string $defaultClass the class to use if none is set in config. |
185 | 185 | * @return object the reply-message-handler instance |
186 | 186 | */ |
187 | - public function createReplyMessageHandler($config, $defaultClass = false){ |
|
187 | + public function createReplyMessageHandler($config, $defaultClass = false) { |
|
188 | 188 | return $this->buildAndModify($config, $this->getReplyHandlerArguments($config), $defaultClass); |
189 | 189 | } |
190 | 190 | |
@@ -197,12 +197,12 @@ discard block |
||
197 | 197 | * @param string $defaultClass the class to use if none is set in config. |
198 | 198 | * @return object the service-activator instance |
199 | 199 | */ |
200 | - public function createServiceActivator($config, $defaultClass = false){ |
|
200 | + public function createServiceActivator($config, $defaultClass = false) { |
|
201 | 201 | $method = (string)$config['method']; |
202 | 202 | $service = $this->context->getServiceProvider()->provideService((string)$config['ref']); |
203 | - if($method && $service){ |
|
203 | + if ($method && $service) { |
|
204 | 204 | $args = $this->getReplyHandlerArguments($config); |
205 | - array_unshift($args,array( |
|
205 | + array_unshift($args, array( |
|
206 | 206 | $service, |
207 | 207 | $method |
208 | 208 | )); |
@@ -219,12 +219,12 @@ discard block |
||
219 | 219 | * @param object $config configuration object to create arguments from. |
220 | 220 | * @return mixed build arguments |
221 | 221 | */ |
222 | - protected function getReplyHandlerArguments($config){ |
|
222 | + protected function getReplyHandlerArguments($config) { |
|
223 | 223 | $args = array( |
224 | 224 | $this->doGetChannel('input', $config), |
225 | 225 | $this->doGetChannel('output', $config) |
226 | 226 | ); |
227 | - if($args[0] == NULL){ |
|
227 | + if ($args[0] == NULL) { |
|
228 | 228 | throw new \RuntimeException('Could not receive input channel.'); |
229 | 229 | } |
230 | 230 | return $args; |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * @param object $config configuration object to return request-channel from. |
240 | 240 | * @return \PEIP\INF\Channel\Channel request-channel |
241 | 241 | */ |
242 | - protected function getRequestChannel($config){ |
|
242 | + protected function getRequestChannel($config) { |
|
243 | 243 | return $this->doGetChannel('request', $config); |
244 | 244 | } |
245 | 245 | |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * @param object $config configuration object to return reply-channel from. |
253 | 253 | * @return \PEIP\INF\Channel\Channel reply-channel |
254 | 254 | */ |
255 | - protected function getReplyChannel($config){ |
|
255 | + protected function getReplyChannel($config) { |
|
256 | 256 | return $this->doGetChannel('reply', $config); |
257 | 257 | } |
258 | 258 | |
@@ -265,15 +265,15 @@ discard block |
||
265 | 265 | * @param object $config configuration object to return channel from. |
266 | 266 | * @return \PEIP\INF\Channel\Channel reply-channel |
267 | 267 | */ |
268 | - public function doGetChannel($type, $config){ |
|
268 | + public function doGetChannel($type, $config) { |
|
269 | 269 | $channelName = $config[$type."_channel"] |
270 | 270 | ? $config[$type."_channel"] |
271 | 271 | : $config["default_".$type."_channel"]; |
272 | 272 | return $this->context->getServiceProvider()->provideService(trim((string)$channelName)); |
273 | - $channel = $this->services[trim((string)$channelName)]; |
|
274 | - if($channel instanceof \PEIP\INF\Channel\Channel){ |
|
273 | + $channel = $this->services[trim((string)$channelName)]; |
|
274 | + if ($channel instanceof \PEIP\INF\Channel\Channel) { |
|
275 | 275 | return $channel; |
276 | - }else{ |
|
276 | + }else { |
|
277 | 277 | return NULL; |
278 | 278 | } |
279 | 279 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | protected function getMessage($object){ |
18 | 18 | if($this->channel instanceof \PEIP\INF\Channel\SubscribableChannel){ |
19 | 19 | return $object; |
20 | - }else{ |
|
20 | + } else{ |
|
21 | 21 | return $object->getContent()->receive(); |
22 | 22 | } |
23 | 23 | } |
@@ -112,6 +112,9 @@ |
||
112 | 112 | ); |
113 | 113 | } |
114 | 114 | |
115 | + /** |
|
116 | + * @param string $key |
|
117 | + */ |
|
115 | 118 | public function provideService($key){ |
116 | 119 | $this->doFireEvent(self::EVENT_BEFORE_PROVIDE_SERVICE, array( |
117 | 120 | self::HEADER_KEY=>$key) |
@@ -11,7 +11,7 @@ |
||
11 | 11 | * |
12 | 12 | * @author timo |
13 | 13 | */ |
14 | -use PEIP\Context\XMLContext; |
|
14 | +use PEIP\Context\XMLContext; |
|
15 | 15 | use PEIP\Plugins\BasePlugin; |
16 | 16 | |
17 | 17 | class ServiceProvider extends \PEIP\Service\ServiceContainer { |
@@ -63,17 +63,17 @@ discard block |
||
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
66 | - * Registers a callable as builder for given node-name |
|
67 | - * |
|
68 | - * @implements \PEIP\INF\Context\Context |
|
69 | - * @access public |
|
70 | - * @param string $nodeName the name of the node |
|
71 | - * @param callable $callable a callable which creates instances for node-name |
|
72 | - */ |
|
66 | + * Registers a callable as builder for given node-name |
|
67 | + * |
|
68 | + * @implements \PEIP\INF\Context\Context |
|
69 | + * @access public |
|
70 | + * @param string $nodeName the name of the node |
|
71 | + * @param callable $callable a callable which creates instances for node-name |
|
72 | + */ |
|
73 | 73 | public function registerNodeBuilder($nodeName, $callable){ |
74 | 74 | $this->nodeBuilders[$nodeName] = $callable; |
75 | 75 | } |
76 | - /** |
|
76 | + /** |
|
77 | 77 | * Registers the build-methods for the main-components with this context. |
78 | 78 | * Note: This method and subsequent registered methods of this class are |
79 | 79 | * candidates for refactoring. Because this class has grown much to large |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | ); |
90 | 90 | $plugin = new BasePlugin(); |
91 | 91 | foreach($builders as $nodeName => $method){ |
92 | - $this->registerNodeBuilder($nodeName, array($this, $method)); |
|
92 | + $this->registerNodeBuilder($nodeName, array($this, $method)); |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | use PEIP\Context\XMLContext; |
15 | 15 | use PEIP\Plugins\BasePlugin; |
16 | 16 | |
17 | -class ServiceProvider extends \PEIP\Service\ServiceContainer { |
|
17 | +class ServiceProvider extends \PEIP\Service\ServiceContainer { |
|
18 | 18 | |
19 | 19 | const |
20 | 20 | /* Headers */ |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | public function __construct(array $config = array(), $idAttribute = 'id') { |
48 | 48 | $this->idAttribute = $idAttribute; |
49 | 49 | $this->initNodeBuilders(); |
50 | - foreach($config as $serviceConfig){ |
|
50 | + foreach ($config as $serviceConfig) { |
|
51 | 51 | $this->addConfig($serviceConfig); |
52 | 52 | } |
53 | 53 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @access public |
59 | 59 | * @return array registered services |
60 | 60 | */ |
61 | - public function getServices(){ |
|
61 | + public function getServices() { |
|
62 | 62 | return $this->services; |
63 | 63 | } |
64 | 64 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @param string $nodeName the name of the node |
71 | 71 | * @param callable $callable a callable which creates instances for node-name |
72 | 72 | */ |
73 | - public function registerNodeBuilder($nodeName, $callable){ |
|
73 | + public function registerNodeBuilder($nodeName, $callable) { |
|
74 | 74 | $this->nodeBuilders[$nodeName] = $callable; |
75 | 75 | } |
76 | 76 | /** |
@@ -83,17 +83,17 @@ discard block |
||
83 | 83 | * @see XMLContext::includeContext |
84 | 84 | * @access protected |
85 | 85 | */ |
86 | - protected function initNodeBuilders(){ return; |
|
86 | + protected function initNodeBuilders() { return; |
|
87 | 87 | $builders = array( |
88 | 88 | 'service' => 'initService' |
89 | 89 | ); |
90 | 90 | $plugin = new BasePlugin(); |
91 | - foreach($builders as $nodeName => $method){ |
|
91 | + foreach ($builders as $nodeName => $method) { |
|
92 | 92 | $this->registerNodeBuilder($nodeName, array($this, $method)); |
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
96 | - public function addConfig($config){ |
|
96 | + public function addConfig($config) { |
|
97 | 97 | $this->doFireEvent( |
98 | 98 | self::EVENT_BEFORE_ADD_CONFIG, |
99 | 99 | array( |
@@ -112,15 +112,15 @@ discard block |
||
112 | 112 | ); |
113 | 113 | } |
114 | 114 | |
115 | - public function provideService($key){ |
|
115 | + public function provideService($key) { |
|
116 | 116 | $this->doFireEvent(self::EVENT_BEFORE_PROVIDE_SERVICE, array( |
117 | 117 | self::HEADER_KEY=>$key) |
118 | 118 | ); |
119 | 119 | |
120 | - if($this->hasService($key)){ |
|
121 | - $service = $this->getService($key); |
|
122 | - }else{ |
|
123 | - $service = $this->createService($key); |
|
120 | + if ($this->hasService($key)) { |
|
121 | + $service = $this->getService($key); |
|
122 | + }else { |
|
123 | + $service = $this->createService($key); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | $this->doFireEvent(self::EVENT_AFTER_PROVIDE_SERVICE, array( |
@@ -131,16 +131,16 @@ discard block |
||
131 | 131 | return $service; |
132 | 132 | } |
133 | 133 | |
134 | - protected function createService($key){ |
|
134 | + protected function createService($key) { |
|
135 | 135 | $this->doFireEvent(self::EVENT_BEFORE_CREATE_SERVICE, array( |
136 | 136 | self::HEADER_KEY=>$key) |
137 | 137 | ); |
138 | 138 | $errorMessage = ''; |
139 | 139 | $config = $this->getServiceConfig($key); |
140 | 140 | |
141 | - if($config){ |
|
141 | + if ($config) { |
|
142 | 142 | $node = $this->buildNode($config); |
143 | - if($node){ |
|
143 | + if ($node) { |
|
144 | 144 | $this->setService( |
145 | 145 | $key, |
146 | 146 | $node |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | )); |
152 | 152 | |
153 | 153 | return $node; |
154 | - }else{ |
|
154 | + }else { |
|
155 | 155 | $errorMessage = 'COULD NOT BUILD NODE FOR KEY: '.$key; |
156 | 156 | } |
157 | 157 | |
158 | - }else{ |
|
158 | + }else { |
|
159 | 159 | $errorMessage = 'NO CONFIG FOR KEY: '.$key; |
160 | 160 | } |
161 | 161 | $this->doFireEvent(self::EVENT_CREATE_SERVICE_ERROR, array( |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | return NULL; |
166 | 166 | } |
167 | 167 | |
168 | - public function getServiceConfig($key){ |
|
169 | - if(!isset($this->ids[$key])){ |
|
168 | + public function getServiceConfig($key) { |
|
169 | + if (!isset($this->ids[$key])) { |
|
170 | 170 | return false; |
171 | 171 | } |
172 | 172 | return $this->config[$this->ids[$key]]; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @param object $config configuration-node |
182 | 182 | * @return void |
183 | 183 | */ |
184 | - protected function buildNode($config){ |
|
184 | + protected function buildNode($config) { |
|
185 | 185 | $nodeName = (string)$config['type']; |
186 | 186 | |
187 | 187 | $this->doFireEvent(self::EVENT_BEFORE_BUILD_NODE, array( |
@@ -189,20 +189,20 @@ discard block |
||
189 | 189 | self::HEADER_NODE_NAME=> $nodeName |
190 | 190 | )); |
191 | 191 | // call the builder method registered for the node. |
192 | - if(array_key_exists($nodeName, $this->nodeBuilders)){ |
|
192 | + if (array_key_exists($nodeName, $this->nodeBuilders)) { |
|
193 | 193 | |
194 | 194 | $nodeInstance = call_user_func($this->nodeBuilders[$nodeName], $config); |
195 | - if(is_object($nodeInstance)){ |
|
195 | + if (is_object($nodeInstance)) { |
|
196 | 196 | $this->doFireEvent(self::EVENT_BUILD_NODE_SUCCESS, array( |
197 | 197 | self::HEADER_NODE_CONFIG=>$config, |
198 | 198 | self::HEADER_NODE_NAME=> $nodeName, |
199 | 199 | self::HEADER_NODE => $nodeInstance |
200 | 200 | )); |
201 | 201 | return $nodeInstance; |
202 | - }else{ |
|
202 | + }else { |
|
203 | 203 | $errorMessage = 'BUILDER RETURNED NO OBJECT FOR NODE-TYPE: '.$nodeName; |
204 | 204 | } |
205 | - }else{ |
|
205 | + }else { |
|
206 | 206 | $errorMessage = 'NO BUILDER FOUND FOR NODE-TYPE: '.$nodeName; |
207 | 207 | } |
208 | 208 | |
@@ -213,27 +213,27 @@ discard block |
||
213 | 213 | )); |
214 | 214 | } |
215 | 215 | |
216 | - protected function getIdFromConfig($config){ |
|
216 | + protected function getIdFromConfig($config) { |
|
217 | 217 | $id = ''; |
218 | - if(isset($config[$this->idAttribute])){ |
|
218 | + if (isset($config[$this->idAttribute])) { |
|
219 | 219 | $id = trim((string)($config[$this->idAttribute])); |
220 | 220 | } |
221 | 221 | return $id; |
222 | 222 | } |
223 | 223 | |
224 | - protected function getCountConfig(){ |
|
224 | + protected function getCountConfig() { |
|
225 | 225 | return count($this->config); |
226 | 226 | } |
227 | 227 | |
228 | - protected function doAddConfig($config){ |
|
228 | + protected function doAddConfig($config) { |
|
229 | 229 | $countConfig = $this->getCountConfig(); |
230 | 230 | $this->config[$countConfig] = $config; |
231 | 231 | return $countConfig; |
232 | 232 | } |
233 | 233 | |
234 | - protected function doRegisterConfig($config){ |
|
235 | - $id = $this->getIdFromConfig($config); |
|
236 | - if($id != ''){ |
|
234 | + protected function doRegisterConfig($config) { |
|
235 | + $id = $this->getIdFromConfig($config); |
|
236 | + if ($id != '') { |
|
237 | 237 | $this->ids[$id] = $this->getCountConfig() - 1; |
238 | 238 | } |
239 | 239 | return $id; |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | |
120 | 120 | if($this->hasService($key)){ |
121 | 121 | $service = $this->getService($key); |
122 | - }else{ |
|
122 | + } else{ |
|
123 | 123 | $service = $this->createService($key); |
124 | 124 | } |
125 | 125 | |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | )); |
152 | 152 | |
153 | 153 | return $node; |
154 | - }else{ |
|
154 | + } else{ |
|
155 | 155 | $errorMessage = 'COULD NOT BUILD NODE FOR KEY: '.$key; |
156 | 156 | } |
157 | 157 | |
158 | - }else{ |
|
158 | + } else{ |
|
159 | 159 | $errorMessage = 'NO CONFIG FOR KEY: '.$key; |
160 | 160 | } |
161 | 161 | $this->doFireEvent(self::EVENT_CREATE_SERVICE_ERROR, array( |
@@ -199,10 +199,10 @@ discard block |
||
199 | 199 | self::HEADER_NODE => $nodeInstance |
200 | 200 | )); |
201 | 201 | return $nodeInstance; |
202 | - }else{ |
|
202 | + } else{ |
|
203 | 203 | $errorMessage = 'BUILDER RETURNED NO OBJECT FOR NODE-TYPE: '.$nodeName; |
204 | 204 | } |
205 | - }else{ |
|
205 | + } else{ |
|
206 | 206 | $errorMessage = 'NO BUILDER FOUND FOR NODE-TYPE: '.$nodeName; |
207 | 207 | } |
208 | 208 |
@@ -1,14 +1,14 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class DrinkRouter |
4 | - extends PEIP_ABS_Router { |
|
4 | + extends PEIP_ABS_Router { |
|
5 | 5 | |
6 | - protected function selectChannels(PEIP_INF_Message $message){ |
|
7 | - $order = $message->getContent(); |
|
8 | - $channelName = $order['iced'] ? 'coldDrinks' : 'hotDrinks'; |
|
9 | - echo PEIP_LINE_SEPARATOR."DrinkRouter: routed to channel: $channelName"; |
|
10 | - return $channelName; |
|
11 | - } |
|
6 | + protected function selectChannels(PEIP_INF_Message $message){ |
|
7 | + $order = $message->getContent(); |
|
8 | + $channelName = $order['iced'] ? 'coldDrinks' : 'hotDrinks'; |
|
9 | + echo PEIP_LINE_SEPARATOR."DrinkRouter: routed to channel: $channelName"; |
|
10 | + return $channelName; |
|
11 | + } |
|
12 | 12 | |
13 | 13 | |
14 | 14 | } |
@@ -3,9 +3,9 @@ |
||
3 | 3 | class DrinkRouter |
4 | 4 | extends PEIP_ABS_Router { |
5 | 5 | |
6 | - protected function selectChannels(PEIP_INF_Message $message){ |
|
6 | + protected function selectChannels(PEIP_INF_Message $message) { |
|
7 | 7 | $order = $message->getContent(); |
8 | - $channelName = $order['iced'] ? 'coldDrinks' : 'hotDrinks'; |
|
8 | + $channelName = $order['iced'] ? 'coldDrinks' : 'hotDrinks'; |
|
9 | 9 | echo PEIP_LINE_SEPARATOR."DrinkRouter: routed to channel: $channelName"; |
10 | 10 | return $channelName; |
11 | 11 | } |
@@ -1,38 +1,38 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class DrinkAggregator |
4 | - extends PEIP_Pipe { |
|
4 | + extends PEIP_Pipe { |
|
5 | 5 | |
6 | - protected $orders = array(); |
|
7 | - protected $preparedDrinks = array(); |
|
6 | + protected $orders = array(); |
|
7 | + protected $preparedDrinks = array(); |
|
8 | 8 | |
9 | - public function __construct(PEIP_INF_Channel $inputChannel, PEIP_INF_Channel $outputChannel = NULL){ |
|
10 | - $this->setInputChannel($inputChannel); |
|
11 | - if(is_object($outputChannel)){ |
|
12 | - $this->setOutputChannel($outputChannel); |
|
13 | - } |
|
14 | - $this->registerCommand('ADD_ORDER', array($this, 'receiveOrder')); |
|
15 | - } |
|
9 | + public function __construct(PEIP_INF_Channel $inputChannel, PEIP_INF_Channel $outputChannel = NULL){ |
|
10 | + $this->setInputChannel($inputChannel); |
|
11 | + if(is_object($outputChannel)){ |
|
12 | + $this->setOutputChannel($outputChannel); |
|
13 | + } |
|
14 | + $this->registerCommand('ADD_ORDER', array($this, 'receiveOrder')); |
|
15 | + } |
|
16 | 16 | |
17 | - protected function doReply(PEIP_INF_Message $message){ |
|
18 | - $drink = $message->getContent(); |
|
19 | - $nr = $drink->getOrderNumber(); |
|
20 | - if(!isset($this->preparedDrinks[$nr])){ |
|
21 | - $this->preparedDrinks[$nr] = array(); |
|
22 | - } |
|
23 | - $this->preparedDrinks[$drink->getOrderNumber()][] = $drink; |
|
24 | - if(isset($this->orders[$nr]) |
|
25 | - && $this->orders[$nr]->getTotalCount() == count($this->preparedDrinks[$nr])){ |
|
26 | - $this->replyMessage($this->preparedDrinks[$nr]); |
|
27 | - unset($this->preparedDrinks[$nr]); |
|
28 | - echo PEIP_LINE_SEPARATOR.'DrinkAggregator : reply #'.$nr; |
|
29 | - } |
|
30 | - } |
|
17 | + protected function doReply(PEIP_INF_Message $message){ |
|
18 | + $drink = $message->getContent(); |
|
19 | + $nr = $drink->getOrderNumber(); |
|
20 | + if(!isset($this->preparedDrinks[$nr])){ |
|
21 | + $this->preparedDrinks[$nr] = array(); |
|
22 | + } |
|
23 | + $this->preparedDrinks[$drink->getOrderNumber()][] = $drink; |
|
24 | + if(isset($this->orders[$nr]) |
|
25 | + && $this->orders[$nr]->getTotalCount() == count($this->preparedDrinks[$nr])){ |
|
26 | + $this->replyMessage($this->preparedDrinks[$nr]); |
|
27 | + unset($this->preparedDrinks[$nr]); |
|
28 | + echo PEIP_LINE_SEPARATOR.'DrinkAggregator : reply #'.$nr; |
|
29 | + } |
|
30 | + } |
|
31 | 31 | |
32 | - public function receiveOrder(Order $order){ |
|
33 | - echo PEIP_LINE_SEPARATOR.'DrinkAggregator: received Order'; |
|
34 | - $this->orders[$order->getOrderNumber()] = $order; |
|
35 | - } |
|
32 | + public function receiveOrder(Order $order){ |
|
33 | + echo PEIP_LINE_SEPARATOR.'DrinkAggregator: received Order'; |
|
34 | + $this->orders[$order->getOrderNumber()] = $order; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | 38 | } |
@@ -6,30 +6,30 @@ |
||
6 | 6 | protected $orders = array(); |
7 | 7 | protected $preparedDrinks = array(); |
8 | 8 | |
9 | - public function __construct(PEIP_INF_Channel $inputChannel, PEIP_INF_Channel $outputChannel = NULL){ |
|
9 | + public function __construct(PEIP_INF_Channel $inputChannel, PEIP_INF_Channel $outputChannel = NULL) { |
|
10 | 10 | $this->setInputChannel($inputChannel); |
11 | - if(is_object($outputChannel)){ |
|
11 | + if (is_object($outputChannel)) { |
|
12 | 12 | $this->setOutputChannel($outputChannel); |
13 | 13 | } |
14 | 14 | $this->registerCommand('ADD_ORDER', array($this, 'receiveOrder')); |
15 | 15 | } |
16 | 16 | |
17 | - protected function doReply(PEIP_INF_Message $message){ |
|
17 | + protected function doReply(PEIP_INF_Message $message) { |
|
18 | 18 | $drink = $message->getContent(); |
19 | 19 | $nr = $drink->getOrderNumber(); |
20 | - if(!isset($this->preparedDrinks[$nr])){ |
|
20 | + if (!isset($this->preparedDrinks[$nr])) { |
|
21 | 21 | $this->preparedDrinks[$nr] = array(); |
22 | 22 | } |
23 | 23 | $this->preparedDrinks[$drink->getOrderNumber()][] = $drink; |
24 | - if(isset($this->orders[$nr]) |
|
25 | - && $this->orders[$nr]->getTotalCount() == count($this->preparedDrinks[$nr])){ |
|
24 | + if (isset($this->orders[$nr]) |
|
25 | + && $this->orders[$nr]->getTotalCount() == count($this->preparedDrinks[$nr])) { |
|
26 | 26 | $this->replyMessage($this->preparedDrinks[$nr]); |
27 | 27 | unset($this->preparedDrinks[$nr]); |
28 | 28 | echo PEIP_LINE_SEPARATOR.'DrinkAggregator : reply #'.$nr; |
29 | 29 | } |
30 | 30 | } |
31 | 31 | |
32 | - public function receiveOrder(Order $order){ |
|
32 | + public function receiveOrder(Order $order) { |
|
33 | 33 | echo PEIP_LINE_SEPARATOR.'DrinkAggregator: received Order'; |
34 | 34 | $this->orders[$order->getOrderNumber()] = $order; |
35 | 35 | } |
@@ -2,13 +2,13 @@ |
||
2 | 2 | |
3 | 3 | class CafeGateway extends PEIP_Simple_Messaging_Gateway { |
4 | 4 | |
5 | - public function placeOrder(Order $order){ |
|
6 | - echo "\nCafe: place order #".$order->getOrderNumber(); |
|
7 | - $this->send($order); |
|
8 | - } |
|
5 | + public function placeOrder(Order $order){ |
|
6 | + echo "\nCafe: place order #".$order->getOrderNumber(); |
|
7 | + $this->send($order); |
|
8 | + } |
|
9 | 9 | |
10 | - public function receiveDelivery(){ |
|
11 | - return $this->receive(); |
|
12 | - } |
|
10 | + public function receiveDelivery(){ |
|
11 | + return $this->receive(); |
|
12 | + } |
|
13 | 13 | |
14 | 14 | } |
@@ -2,12 +2,12 @@ |
||
2 | 2 | |
3 | 3 | class CafeGateway extends PEIP_Simple_Messaging_Gateway { |
4 | 4 | |
5 | - public function placeOrder(Order $order){ |
|
5 | + public function placeOrder(Order $order) { |
|
6 | 6 | echo "\nCafe: place order #".$order->getOrderNumber(); |
7 | 7 | $this->send($order); |
8 | 8 | } |
9 | 9 | |
10 | - public function receiveDelivery(){ |
|
10 | + public function receiveDelivery() { |
|
11 | 11 | return $this->receive(); |
12 | 12 | } |
13 | 13 |
@@ -2,20 +2,20 @@ |
||
2 | 2 | |
3 | 3 | class OrderSplitter extends PEIP_ABS_Message_Splitter { |
4 | 4 | |
5 | - public function split(PEIP_INF_Message $message){ |
|
6 | - $order = $message->getContent(); |
|
7 | - $orderItems = $order->getItems(); |
|
8 | - $items = array(); |
|
9 | - foreach($orderItems as $item){ |
|
10 | - $nr = $item['number']; |
|
11 | - unset($item['number']); |
|
12 | - $item['order'] = $order->getOrderNumber(); |
|
13 | - for($x = 0; $x < $nr; $x++){ |
|
14 | - $items[] = $item; |
|
15 | - } |
|
16 | - } |
|
17 | - echo PEIP_LINE_SEPARATOR."OrderSplitter: split order #: ".$order->getOrderNumber(); |
|
18 | - return $items; |
|
19 | - } |
|
5 | + public function split(PEIP_INF_Message $message){ |
|
6 | + $order = $message->getContent(); |
|
7 | + $orderItems = $order->getItems(); |
|
8 | + $items = array(); |
|
9 | + foreach($orderItems as $item){ |
|
10 | + $nr = $item['number']; |
|
11 | + unset($item['number']); |
|
12 | + $item['order'] = $order->getOrderNumber(); |
|
13 | + for($x = 0; $x < $nr; $x++){ |
|
14 | + $items[] = $item; |
|
15 | + } |
|
16 | + } |
|
17 | + echo PEIP_LINE_SEPARATOR."OrderSplitter: split order #: ".$order->getOrderNumber(); |
|
18 | + return $items; |
|
19 | + } |
|
20 | 20 | |
21 | 21 | } |
@@ -2,15 +2,15 @@ |
||
2 | 2 | |
3 | 3 | class OrderSplitter extends PEIP_ABS_Message_Splitter { |
4 | 4 | |
5 | - public function split(PEIP_INF_Message $message){ |
|
5 | + public function split(PEIP_INF_Message $message) { |
|
6 | 6 | $order = $message->getContent(); |
7 | 7 | $orderItems = $order->getItems(); |
8 | 8 | $items = array(); |
9 | - foreach($orderItems as $item){ |
|
9 | + foreach ($orderItems as $item) { |
|
10 | 10 | $nr = $item['number']; |
11 | 11 | unset($item['number']); |
12 | 12 | $item['order'] = $order->getOrderNumber(); |
13 | - for($x = 0; $x < $nr; $x++){ |
|
13 | + for ($x = 0; $x < $nr; $x++) { |
|
14 | 14 | $items[] = $item; |
15 | 15 | } |
16 | 16 | } |
@@ -31,19 +31,19 @@ |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | protected function prepareDrink($orderNumber, $type, $iced){ |
34 | - $drink = new Drink($orderNumber, $type, $iced); |
|
35 | - return $drink; |
|
34 | + $drink = new Drink($orderNumber, $type, $iced); |
|
35 | + return $drink; |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | protected function printAction($cold, $orderNr){ |
39 | - if($cold){ |
|
40 | - $type = 'cold'; |
|
41 | - $count = $this->coldDrinkCounter; |
|
42 | - }else{ |
|
43 | - $type = 'hot'; |
|
44 | - $count = $this->hotDrinkCounter; |
|
45 | - } |
|
46 | - $total = $this->coldDrinkCounter + $this->hotDrinkCounter; |
|
39 | + if($cold){ |
|
40 | + $type = 'cold'; |
|
41 | + $count = $this->coldDrinkCounter; |
|
42 | + }else{ |
|
43 | + $type = 'hot'; |
|
44 | + $count = $this->hotDrinkCounter; |
|
45 | + } |
|
46 | + $total = $this->coldDrinkCounter + $this->hotDrinkCounter; |
|
47 | 47 | echo PEIP_LINE_SEPARATOR."Barista: prepared $type drink (total #$total- $type #$count) for order #$orderNr"; |
48 | 48 | flush(); |
49 | 49 | } |
@@ -30,16 +30,16 @@ |
||
30 | 30 | return $this->prepareDrink($orderItem['order'], $orderItem['type'], true); |
31 | 31 | } |
32 | 32 | |
33 | - protected function prepareDrink($orderNumber, $type, $iced){ |
|
33 | + protected function prepareDrink($orderNumber, $type, $iced) { |
|
34 | 34 | $drink = new Drink($orderNumber, $type, $iced); |
35 | 35 | return $drink; |
36 | 36 | } |
37 | 37 | |
38 | - protected function printAction($cold, $orderNr){ |
|
39 | - if($cold){ |
|
38 | + protected function printAction($cold, $orderNr) { |
|
39 | + if ($cold) { |
|
40 | 40 | $type = 'cold'; |
41 | 41 | $count = $this->coldDrinkCounter; |
42 | - }else{ |
|
42 | + }else { |
|
43 | 43 | $type = 'hot'; |
44 | 44 | $count = $this->hotDrinkCounter; |
45 | 45 | } |
@@ -39,7 +39,7 @@ |
||
39 | 39 | if($cold){ |
40 | 40 | $type = 'cold'; |
41 | 41 | $count = $this->coldDrinkCounter; |
42 | - }else{ |
|
42 | + } else{ |
|
43 | 43 | $type = 'hot'; |
44 | 44 | $count = $this->hotDrinkCounter; |
45 | 45 | } |