@@ -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 | |
@@ -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 | |
@@ -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; |
@@ -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 | |
@@ -5,18 +5,18 @@ |
||
| 5 | 5 | |
| 6 | 6 | protected $orders; |
| 7 | 7 | |
| 8 | - public function prepareDelivery(array $drinks){ |
|
| 8 | + public function prepareDelivery(array $drinks) { |
|
| 9 | 9 | echo PEIP_LINE_SEPARATOR.'Waiter: prepareDelivery: #'.$drinks[0]->getOrderNumber(); |
| 10 | 10 | return new Delivery($drinks); |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | |
| 14 | - public function receiveOrder(Order $order){ |
|
| 14 | + public function receiveOrder(Order $order) { |
|
| 15 | 15 | echo PEIP_LINE_SEPARATOR.'Waiter: receiveOrder'; |
| 16 | 16 | $this->orders[$order->getOrderNumber()] = $order; |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | - public function getOrder($nr){ |
|
| 19 | + public function getOrder($nr) { |
|
| 20 | 20 | return $this->orders[$nr]; |
| 21 | 21 | } |
| 22 | 22 | |
@@ -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 | } |
@@ -4,12 +4,12 @@ |
||
| 4 | 4 | |
| 5 | 5 | class CafeGateway extends SimpleMessagingGateway {
|
| 6 | 6 | |
| 7 | - public function placeOrder(Order $order){
|
|
| 7 | + public function placeOrder(Order $order) {
|
|
| 8 | 8 | echo "\nCafe: place order #".$order->getOrderNumber(); |
| 9 | 9 | $this->send($order); |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | - public function receiveDelivery(){
|
|
| 12 | + public function receiveDelivery() {
|
|
| 13 | 13 | return $this->receive(); |
| 14 | 14 | } |
| 15 | 15 | |
@@ -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 | } |