@@ -4,38 +4,38 @@ |
||
4 | 4 | use PEIP\INF\Message\Message; |
5 | 5 | |
6 | 6 | class DrinkAggregator |
7 | - extends \PEIP\Pipe\Pipe { |
|
7 | + extends \PEIP\Pipe\Pipe { |
|
8 | 8 | |
9 | - protected $orders = array(); |
|
10 | - protected $preparedDrinks = array(); |
|
9 | + protected $orders = array(); |
|
10 | + protected $preparedDrinks = array(); |
|
11 | 11 | |
12 | - public function __construct(Channel $inputChannel, Channel $outputChannel = NULL){ |
|
13 | - $this->setInputChannel($inputChannel); |
|
14 | - if(is_object($outputChannel)){ |
|
15 | - $this->setOutputChannel($outputChannel); |
|
16 | - } |
|
17 | - $this->registerCommand('ADD_ORDER', array($this, 'receiveOrder')); |
|
18 | - } |
|
12 | + public function __construct(Channel $inputChannel, Channel $outputChannel = NULL){ |
|
13 | + $this->setInputChannel($inputChannel); |
|
14 | + if(is_object($outputChannel)){ |
|
15 | + $this->setOutputChannel($outputChannel); |
|
16 | + } |
|
17 | + $this->registerCommand('ADD_ORDER', array($this, 'receiveOrder')); |
|
18 | + } |
|
19 | 19 | |
20 | - protected function doReply(Message $message){ |
|
21 | - $drink = $message->getContent(); |
|
22 | - $nr = $drink->getOrderNumber(); |
|
23 | - if(!isset($this->preparedDrinks[$nr])){ |
|
24 | - $this->preparedDrinks[$nr] = array(); |
|
25 | - } |
|
26 | - $this->preparedDrinks[$drink->getOrderNumber()][] = $drink; |
|
27 | - if(isset($this->orders[$nr]) |
|
28 | - && $this->orders[$nr]->getTotalCount() == count($this->preparedDrinks[$nr])){ |
|
29 | - $this->replyMessage($this->preparedDrinks[$nr]); |
|
30 | - unset($this->preparedDrinks[$nr]); |
|
31 | - echo PEIP_LINE_SEPARATOR.'DrinkAggregator : reply #'.$nr; |
|
32 | - } |
|
33 | - } |
|
20 | + protected function doReply(Message $message){ |
|
21 | + $drink = $message->getContent(); |
|
22 | + $nr = $drink->getOrderNumber(); |
|
23 | + if(!isset($this->preparedDrinks[$nr])){ |
|
24 | + $this->preparedDrinks[$nr] = array(); |
|
25 | + } |
|
26 | + $this->preparedDrinks[$drink->getOrderNumber()][] = $drink; |
|
27 | + if(isset($this->orders[$nr]) |
|
28 | + && $this->orders[$nr]->getTotalCount() == count($this->preparedDrinks[$nr])){ |
|
29 | + $this->replyMessage($this->preparedDrinks[$nr]); |
|
30 | + unset($this->preparedDrinks[$nr]); |
|
31 | + echo PEIP_LINE_SEPARATOR.'DrinkAggregator : reply #'.$nr; |
|
32 | + } |
|
33 | + } |
|
34 | 34 | |
35 | - public function receiveOrder(Order $order){ |
|
36 | - echo PEIP_LINE_SEPARATOR.'DrinkAggregator: received Order'; |
|
37 | - $this->orders[$order->getOrderNumber()] = $order; |
|
38 | - } |
|
35 | + public function receiveOrder(Order $order){ |
|
36 | + echo PEIP_LINE_SEPARATOR.'DrinkAggregator: received Order'; |
|
37 | + $this->orders[$order->getOrderNumber()] = $order; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | 41 | } |
@@ -9,30 +9,30 @@ |
||
9 | 9 | protected $orders = array(); |
10 | 10 | protected $preparedDrinks = array(); |
11 | 11 | |
12 | - public function __construct(Channel $inputChannel, Channel $outputChannel = NULL){ |
|
12 | + public function __construct(Channel $inputChannel, Channel $outputChannel = NULL) { |
|
13 | 13 | $this->setInputChannel($inputChannel); |
14 | - if(is_object($outputChannel)){ |
|
14 | + if (is_object($outputChannel)) { |
|
15 | 15 | $this->setOutputChannel($outputChannel); |
16 | 16 | } |
17 | 17 | $this->registerCommand('ADD_ORDER', array($this, 'receiveOrder')); |
18 | 18 | } |
19 | 19 | |
20 | - protected function doReply(Message $message){ |
|
20 | + protected function doReply(Message $message) { |
|
21 | 21 | $drink = $message->getContent(); |
22 | 22 | $nr = $drink->getOrderNumber(); |
23 | - if(!isset($this->preparedDrinks[$nr])){ |
|
23 | + if (!isset($this->preparedDrinks[$nr])) { |
|
24 | 24 | $this->preparedDrinks[$nr] = array(); |
25 | 25 | } |
26 | 26 | $this->preparedDrinks[$drink->getOrderNumber()][] = $drink; |
27 | - if(isset($this->orders[$nr]) |
|
28 | - && $this->orders[$nr]->getTotalCount() == count($this->preparedDrinks[$nr])){ |
|
27 | + if (isset($this->orders[$nr]) |
|
28 | + && $this->orders[$nr]->getTotalCount() == count($this->preparedDrinks[$nr])) { |
|
29 | 29 | $this->replyMessage($this->preparedDrinks[$nr]); |
30 | 30 | unset($this->preparedDrinks[$nr]); |
31 | 31 | echo PEIP_LINE_SEPARATOR.'DrinkAggregator : reply #'.$nr; |
32 | 32 | } |
33 | 33 | } |
34 | 34 | |
35 | - public function receiveOrder(Order $order){ |
|
35 | + public function receiveOrder(Order $order) { |
|
36 | 36 | echo PEIP_LINE_SEPARATOR.'DrinkAggregator: received Order'; |
37 | 37 | $this->orders[$order->getOrderNumber()] = $order; |
38 | 38 | } |
@@ -4,14 +4,14 @@ |
||
4 | 4 | use PEIP\INF\Message\Message; |
5 | 5 | |
6 | 6 | class DrinkRouter |
7 | - extends Router { |
|
7 | + extends Router { |
|
8 | 8 | |
9 | - protected function selectChannels(Message $message){ |
|
10 | - $order = $message->getContent(); |
|
11 | - $channelName = $order['iced'] ? 'coldDrinks' : 'hotDrinks'; |
|
12 | - echo PEIP_LINE_SEPARATOR."DrinkRouter: routed to channel: $channelName"; |
|
13 | - return $channelName; |
|
14 | - } |
|
9 | + protected function selectChannels(Message $message){ |
|
10 | + $order = $message->getContent(); |
|
11 | + $channelName = $order['iced'] ? 'coldDrinks' : 'hotDrinks'; |
|
12 | + echo PEIP_LINE_SEPARATOR."DrinkRouter: routed to channel: $channelName"; |
|
13 | + return $channelName; |
|
14 | + } |
|
15 | 15 | |
16 | 16 | |
17 | 17 | } |
@@ -6,9 +6,9 @@ |
||
6 | 6 | class DrinkRouter |
7 | 7 | extends Router { |
8 | 8 | |
9 | - protected function selectChannels(Message $message){ |
|
9 | + protected function selectChannels(Message $message) { |
|
10 | 10 | $order = $message->getContent(); |
11 | - $channelName = $order['iced'] ? 'coldDrinks' : 'hotDrinks'; |
|
11 | + $channelName = $order['iced'] ? 'coldDrinks' : 'hotDrinks'; |
|
12 | 12 | echo PEIP_LINE_SEPARATOR."DrinkRouter: routed to channel: $channelName"; |
13 | 13 | return $channelName; |
14 | 14 | } |
@@ -5,20 +5,20 @@ |
||
5 | 5 | |
6 | 6 | class OrderSplitter extends MessageSplitter { |
7 | 7 | |
8 | - public function split(Message $message){ |
|
9 | - $order = $message->getContent(); |
|
10 | - $orderItems = $order->getItems(); |
|
11 | - $items = array(); |
|
12 | - foreach($orderItems as $item){ |
|
13 | - $nr = $item['number']; |
|
14 | - unset($item['number']); |
|
15 | - $item['order'] = $order->getOrderNumber(); |
|
16 | - for($x = 0; $x < $nr; $x++){ |
|
17 | - $items[] = $item; |
|
18 | - } |
|
19 | - } |
|
20 | - echo PEIP_LINE_SEPARATOR."OrderSplitter: split order #: ".$order->getOrderNumber(); |
|
21 | - return $items; |
|
22 | - } |
|
8 | + public function split(Message $message){ |
|
9 | + $order = $message->getContent(); |
|
10 | + $orderItems = $order->getItems(); |
|
11 | + $items = array(); |
|
12 | + foreach($orderItems as $item){ |
|
13 | + $nr = $item['number']; |
|
14 | + unset($item['number']); |
|
15 | + $item['order'] = $order->getOrderNumber(); |
|
16 | + for($x = 0; $x < $nr; $x++){ |
|
17 | + $items[] = $item; |
|
18 | + } |
|
19 | + } |
|
20 | + echo PEIP_LINE_SEPARATOR."OrderSplitter: split order #: ".$order->getOrderNumber(); |
|
21 | + return $items; |
|
22 | + } |
|
23 | 23 | |
24 | 24 | } |
@@ -5,15 +5,15 @@ |
||
5 | 5 | |
6 | 6 | class OrderSplitter extends MessageSplitter { |
7 | 7 | |
8 | - public function split(Message $message){ |
|
8 | + public function split(Message $message) { |
|
9 | 9 | $order = $message->getContent(); |
10 | 10 | $orderItems = $order->getItems(); |
11 | 11 | $items = array(); |
12 | - foreach($orderItems as $item){ |
|
12 | + foreach ($orderItems as $item) { |
|
13 | 13 | $nr = $item['number']; |
14 | 14 | unset($item['number']); |
15 | 15 | $item['order'] = $order->getOrderNumber(); |
16 | - for($x = 0; $x < $nr; $x++){ |
|
16 | + for ($x = 0; $x < $nr; $x++) { |
|
17 | 17 | $items[] = $item; |
18 | 18 | } |
19 | 19 | } |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class Cafe |
4 | - extends \PEIP\Gateway\SimpleMessagingGateway { |
|
4 | + extends \PEIP\Gateway\SimpleMessagingGateway { |
|
5 | 5 | |
6 | - public function placeOrder(Order $order){ |
|
7 | - return $this->sendAndReceive($order); |
|
8 | - } |
|
6 | + public function placeOrder(Order $order){ |
|
7 | + return $this->sendAndReceive($order); |
|
8 | + } |
|
9 | 9 | |
10 | 10 | } |
11 | 11 |
@@ -3,7 +3,7 @@ |
||
3 | 3 | class Cafe |
4 | 4 | extends \PEIP\Gateway\SimpleMessagingGateway { |
5 | 5 | |
6 | - public function placeOrder(Order $order){ |
|
6 | + public function placeOrder(Order $order) { |
|
7 | 7 | return $this->sendAndReceive($order); |
8 | 8 | } |
9 | 9 |
@@ -9,9 +9,9 @@ |
||
9 | 9 | // simple service class |
10 | 10 | class HelloService { |
11 | 11 | |
12 | - public function greet($name){ |
|
13 | - return 'Hello '.$name; |
|
14 | - } |
|
12 | + public function greet($name){ |
|
13 | + return 'Hello '.$name; |
|
14 | + } |
|
15 | 15 | |
16 | 16 | } |
17 | 17 |
@@ -9,7 +9,7 @@ |
||
9 | 9 | // simple service class |
10 | 10 | class HelloService { |
11 | 11 | |
12 | - public function greet($name){ |
|
12 | + public function greet($name) { |
|
13 | 13 | return 'Hello '.$name; |
14 | 14 | } |
15 | 15 |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @param mixed $offset the offset |
33 | 33 | * @return |
34 | 34 | */ |
35 | - public function offsetExists($offset){ |
|
35 | + public function offsetExists($offset) { |
|
36 | 36 | return array_key_exists($name, $this->values); |
37 | 37 | } |
38 | 38 | |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @param mixed $offset the offset |
44 | 44 | * @return |
45 | 45 | */ |
46 | - public function offsetGet($offset){ |
|
46 | + public function offsetGet($offset) { |
|
47 | 47 | return array_key_exists($name, $this->values) ? $this->values[$offset] : NULL; |
48 | 48 | } |
49 | 49 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @param mixed $offset the offset |
55 | 55 | * @return |
56 | 56 | */ |
57 | - public function offsetUnset($offset){ |
|
57 | + public function offsetUnset($offset) { |
|
58 | 58 | unset($this->values[$offset]); |
59 | 59 | } |
60 | 60 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param mixed $value value for the offset |
67 | 67 | * @return |
68 | 68 | */ |
69 | - public function offsetSet($offset, $value){ |
|
69 | + public function offsetSet($offset, $value) { |
|
70 | 70 | $this->values[$offset] = $value; |
71 | 71 | } |
72 | 72 |
@@ -33,10 +33,10 @@ |
||
33 | 33 | * @param \PEIP\INF\Message\Message $message message to call the service with it�s content/payload |
34 | 34 | * @return mixed result of calling the registered service callable with message content/payload |
35 | 35 | */ |
36 | - public function callService(\PEIP\INF\Message\Message $message){ |
|
37 | - if(is_callable($this->serviceCallable)){ |
|
36 | + public function callService(\PEIP\INF\Message\Message $message) { |
|
37 | + if (is_callable($this->serviceCallable)) { |
|
38 | 38 | $res = call_user_func_array($this->serviceCallable, $message->getContent()); |
39 | - }elseif(is_object($this->serviceCallable) && method_exists($this->serviceCallable, 'handle')){ |
|
39 | + }elseif (is_object($this->serviceCallable) && method_exists($this->serviceCallable, 'handle')) { |
|
40 | 40 | $res = call_user_func_array(array($this->serviceCallable, 'handle'), $message->getContent()); |
41 | 41 | } |
42 | 42 | return $res; |
@@ -36,7 +36,7 @@ |
||
36 | 36 | public function callService(\PEIP\INF\Message\Message $message){ |
37 | 37 | if(is_callable($this->serviceCallable)){ |
38 | 38 | $res = call_user_func_array($this->serviceCallable, $message->getContent()); |
39 | - }elseif(is_object($this->serviceCallable) && method_exists($this->serviceCallable, 'handle')){ |
|
39 | + } elseif(is_object($this->serviceCallable) && method_exists($this->serviceCallable, 'handle')){ |
|
40 | 40 | $res = call_user_func_array(array($this->serviceCallable, 'handle'), $message->getContent()); |
41 | 41 | } |
42 | 42 | return $res; |
@@ -49,10 +49,10 @@ |
||
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | - * @access public |
|
53 | - * @param $observer |
|
54 | - * @return |
|
55 | - */ |
|
52 | + * @access public |
|
53 | + * @param $observer |
|
54 | + * @return |
|
55 | + */ |
|
56 | 56 | public function addObserver(\PEIP\INF\Event\Observer $observer){ |
57 | 57 | $this->observers[] = $observer; |
58 | 58 | } |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | * @param $observedObject |
37 | 37 | * @return |
38 | 38 | */ |
39 | - public function __construct($observedObject){ |
|
39 | + public function __construct($observedObject) { |
|
40 | 40 | $this->setObserved($observedObject); |
41 | 41 | } |
42 | 42 | |
43 | - protected function setObserved($observedObject){ |
|
44 | - if(!is_object($observedObject)){ |
|
43 | + protected function setObserved($observedObject) { |
|
44 | + if (!is_object($observedObject)) { |
|
45 | 45 | throw new \InvalidArgumentException("$observedObject must be an object. ".gettype($var)." given."); |
46 | 46 | } |
47 | 47 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @param $observer |
54 | 54 | * @return |
55 | 55 | */ |
56 | - public function addObserver(\PEIP\INF\Event\Observer $observer){ |
|
56 | + public function addObserver(\PEIP\INF\Event\Observer $observer) { |
|
57 | 57 | $this->observers[] = $observer; |
58 | 58 | } |
59 | 59 | |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | * @param $observer |
64 | 64 | * @return |
65 | 65 | */ |
66 | - public function deleteObserver(\PEIP\INF\Event\Observer $observer){ |
|
67 | - foreach($this->observers as $key=>$obs){ |
|
68 | - if($obs == $observer){ |
|
66 | + public function deleteObserver(\PEIP\INF\Event\Observer $observer) { |
|
67 | + foreach ($this->observers as $key=>$obs) { |
|
68 | + if ($obs == $observer) { |
|
69 | 69 | unset($this->observers[$key]); |
70 | 70 | return true; |
71 | 71 | } |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | * @param $arguments |
79 | 79 | * @return |
80 | 80 | */ |
81 | - public function notifyObservers(array $arguments = array()){ |
|
82 | - if($this->hasChanged()){ |
|
83 | - foreach($this->observers as $observer){ |
|
81 | + public function notifyObservers(array $arguments = array()) { |
|
82 | + if ($this->hasChanged()) { |
|
83 | + foreach ($this->observers as $observer) { |
|
84 | 84 | $observer->update($this->observedObject); |
85 | 85 | } |
86 | 86 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @access public |
92 | 92 | * @return |
93 | 93 | */ |
94 | - public function countObservers(){ |
|
94 | + public function countObservers() { |
|
95 | 95 | return count($this->obeservers); |
96 | 96 | } |
97 | 97 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * @access public |
101 | 101 | * @return |
102 | 102 | */ |
103 | - public function hasChanged(){ |
|
103 | + public function hasChanged() { |
|
104 | 104 | return $this->hasChanged(); |
105 | 105 | } |
106 | 106 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @access public |
110 | 110 | * @return |
111 | 111 | */ |
112 | - public function setChanged(){ |
|
112 | + public function setChanged() { |
|
113 | 113 | $this->hasChanged = true; |
114 | 114 | } |
115 | 115 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @access public |
119 | 119 | * @return |
120 | 120 | */ |
121 | - public function clearChanged(){ |
|
121 | + public function clearChanged() { |
|
122 | 122 | $this->hasChanged = true; |
123 | 123 | } |
124 | 124 |
@@ -33,10 +33,10 @@ |
||
33 | 33 | * Send a message, blocking until either the message is accepted or the |
34 | 34 | * specified timeout period elapses. |
35 | 35 | * |
36 | - * @param message the {@link Message} to send |
|
37 | - * @param timeout the timeout in milliseconds |
|
36 | + * @param message \PEIP\INF\Message\Message {@link Message} to send |
|
37 | + * @param timeout integer timeout in milliseconds |
|
38 | 38 | * |
39 | - * @return <code>true</code> if the message is sent successfully, |
|
39 | + * @return null|boolean if the message is sent successfully, |
|
40 | 40 | * <code>false</false> if the specified timeout period elapses or |
41 | 41 | * the send is interrupted |
42 | 42 | */ |