@@ -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 | } |
@@ -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,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,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 | } |
@@ -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 | } |
@@ -7,16 +7,16 @@ discard block |
||
| 7 | 7 | $orderNumber; |
| 8 | 8 | protected static $orderCount = 0; |
| 9 | 9 | |
| 10 | - public function __construct(){ |
|
| 10 | + public function __construct() { |
|
| 11 | 11 | self::$orderCount++; |
| 12 | 12 | $this->orderNumber = self::$orderCount; |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | - public function getOrderNumber(){ |
|
| 15 | + public function getOrderNumber() { |
|
| 16 | 16 | return $this->orderNumber; |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | - public function addItem($type, $number, $iced = false){ |
|
| 19 | + public function addItem($type, $number, $iced = false) { |
|
| 20 | 20 | $this->items[] = |
| 21 | 21 | array( |
| 22 | 22 | 'type' => $type, |
@@ -25,13 +25,13 @@ discard block |
||
| 25 | 25 | ); |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - public function getItems(){ |
|
| 28 | + public function getItems() { |
|
| 29 | 29 | return $this->items; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - public function getTotalCount(){ |
|
| 32 | + public function getTotalCount() { |
|
| 33 | 33 | $x = 0; |
| 34 | - foreach($this->items as $item){ |
|
| 34 | + foreach ($this->items as $item) { |
|
| 35 | 35 | $x += (int)$item['number']; |
| 36 | 36 | } |
| 37 | 37 | return $x; |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | $deliveredDrinks, |
| 7 | 7 | $orderNumber; |
| 8 | 8 | |
| 9 | - public function __construct(array $deliveredDrinks){ |
|
| 9 | + public function __construct(array $deliveredDrinks) { |
|
| 10 | 10 | $this->deliveredDrinks = $deliveredDrinks; |
| 11 | 11 | $this->orderNumber = $deliveredDrinks[0]->getOrderNumber(); |
| 12 | 12 | } |
@@ -8,21 +8,21 @@ |
||
| 8 | 8 | $type, |
| 9 | 9 | $iced; |
| 10 | 10 | |
| 11 | - public function __construct($orderNumber, $type, $iced){ |
|
| 11 | + public function __construct($orderNumber, $type, $iced) { |
|
| 12 | 12 | $this->orderNumber = $orderNumber; |
| 13 | 13 | $this->type = $type; |
| 14 | 14 | $this->iced = $iced; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - public function getType(){ |
|
| 17 | + public function getType() { |
|
| 18 | 18 | return $this->type; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - public function getIced(){ |
|
| 21 | + public function getIced() { |
|
| 22 | 22 | return $this->iced; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - public function getOrderNumber(){ |
|
| 25 | + public function getOrderNumber() { |
|
| 26 | 26 | return $this->orderNumber; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -3,7 +3,7 @@ |
||
| 3 | 3 | class Cafe |
| 4 | 4 | extends PEIA_Simple_Messaging_Gateway { |
| 5 | 5 | |
| 6 | - public function placeOrder(Order $order){ |
|
| 6 | + public function placeOrder(Order $order) { |
|
| 7 | 7 | return $this->sendAndReceive($order); |
| 8 | 8 | } |
| 9 | 9 | |