@@ -46,19 +46,19 @@ |
||
| 46 | 46 | |
| 47 | 47 | if($cafe){
|
| 48 | 48 | |
| 49 | - for ($i = 1; $i <= 10; $i++) {
|
|
| 50 | - // create and place orders |
|
| 51 | - $order = new Order(); |
|
| 52 | - $order->addItem("LATTE", 2, false);
|
|
| 53 | - $order->addItem("MOCCA", 3, true);
|
|
| 54 | - $cafe->placeOrder($order); |
|
| 55 | - // receive drinks |
|
| 56 | - $drinks = $cafe->receiveDelivery(); |
|
| 49 | + for ($i = 1; $i <= 10; $i++) {
|
|
| 50 | + // create and place orders |
|
| 51 | + $order = new Order(); |
|
| 52 | + $order->addItem("LATTE", 2, false);
|
|
| 53 | + $order->addItem("MOCCA", 3, true);
|
|
| 54 | + $cafe->placeOrder($order); |
|
| 55 | + // receive drinks |
|
| 56 | + $drinks = $cafe->receiveDelivery(); |
|
| 57 | 57 | var_dump($drinks); |
| 58 | - } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | 60 | }else{
|
| 61 | - throw new RuntimeException('Could not get CafeGateway');
|
|
| 61 | + throw new RuntimeException('Could not get CafeGateway');
|
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | |
@@ -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 | |
@@ -57,7 +57,7 @@ |
||
| 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,13 +4,13 @@ |
||
| 4 | 4 | |
| 5 | 5 | class CafeGateway extends SimpleMessagingGateway {
|
| 6 | 6 | |
| 7 | - public function placeOrder(Order $order){
|
|
| 8 | - echo "\nCafe: place order #".$order->getOrderNumber(); |
|
| 9 | - $this->send($order); |
|
| 10 | - } |
|
| 7 | + public function placeOrder(Order $order){
|
|
| 8 | + echo "\nCafe: place order #".$order->getOrderNumber(); |
|
| 9 | + $this->send($order); |
|
| 10 | + } |
|
| 11 | 11 | |
| 12 | - public function receiveDelivery(){
|
|
| 13 | - return $this->receive(); |
|
| 14 | - } |
|
| 12 | + public function receiveDelivery(){
|
|
| 13 | + return $this->receive(); |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | 16 | } |
@@ -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 | |
@@ -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 | |