@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | |
46 | 46 | |
47 | -if($cafe){ |
|
47 | +if ($cafe) { |
|
48 | 48 | |
49 | 49 | for ($i = 1; $i <= 10; $i++) { |
50 | 50 | // create and place orders |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | var_dump($drinks); |
58 | 58 | } |
59 | 59 | |
60 | -}else{ |
|
60 | +}else { |
|
61 | 61 | throw new RuntimeException('Could not get CafeGateway'); |
62 | 62 | } |
63 | 63 |
@@ -2,11 +2,11 @@ |
||
2 | 2 | |
3 | 3 | require_once(dirname(__FILE__).'/../../../misc/bootstrap.php'); |
4 | 4 | |
5 | -foreach (glob(realpath(dirname(__FILE__)."/../lib/model/")."/*.php") as $filename){ |
|
5 | +foreach (glob(realpath(dirname(__FILE__)."/../lib/model/")."/*.php") as $filename) { |
|
6 | 6 | require_once $filename; |
7 | 7 | } |
8 | 8 | |
9 | -foreach (glob(realpath(dirname(__FILE__)."/../lib/messaging/")."/*.php") as $filename){ |
|
9 | +foreach (glob(realpath(dirname(__FILE__)."/../lib/messaging/")."/*.php") as $filename) { |
|
10 | 10 | require_once $filename; |
11 | 11 | } |
12 | 12 |
@@ -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 | } |
@@ -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,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 | } |
@@ -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,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 |
@@ -38,16 +38,16 @@ discard block |
||
38 | 38 | * @param $parameters |
39 | 39 | * @return |
40 | 40 | */ |
41 | - protected function __construct($callable ,array $parameters = array()){ |
|
41 | + protected function __construct($callable, array $parameters = array()) { |
|
42 | 42 | $this->callable = $callable; |
43 | 43 | $this->setParameters($parameters); |
44 | 44 | } |
45 | 45 | |
46 | - public static function getfromClass($class, array $parameters = array()){ |
|
46 | + public static function getfromClass($class, array $parameters = array()) { |
|
47 | 47 | return new DedicatedFactory(array($class, '__construct'), $parameters); |
48 | 48 | } |
49 | 49 | |
50 | - public static function getfromCallable($callable, array $parameters = array()){ |
|
50 | + public static function getfromCallable($callable, array $parameters = array()) { |
|
51 | 51 | return new DedicatedFactory($callable, $parameters); |
52 | 52 | } |
53 | 53 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @param $arguments |
58 | 58 | * @return |
59 | 59 | */ |
60 | - public function build(array $arguments = array()){ |
|
60 | + public function build(array $arguments = array()) { |
|
61 | 61 | $arguments = count($arguments) > 0 ? $arguments : $this->getParameters(); |
62 | 62 | return (is_array($this->callable) && $this->callable[1] == '__construct') |
63 | 63 | ? GenericBuilder::GetInstance($this->callable[0])->build($arguments) |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @param $method |
71 | 71 | * @return |
72 | 72 | */ |
73 | - public function setConstructor($method){ |
|
73 | + public function setConstructor($method) { |
|
74 | 74 | $this->constructor = (string)$method; |
75 | 75 | return $this; |
76 | 76 | } |