1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
// please, change "<br>" to "\n" in the follwing line, when you run this file in the CLI
|
4
|
|
|
define('PEIP_LINE_SEPARATOR', "\n");
|
5
|
|
|
|
6
|
|
|
// This is PEIP�s (basic) way of the famous starbucks example from
|
7
|
|
|
// Gregor Hohpe http://www.eaipatterns.com/ramblings/18_starbucks.html
|
8
|
|
|
|
9
|
|
|
// Note since this example works in a single threaded environment it
|
10
|
|
|
// processes the orders in a synchronous way - every order is placed,
|
11
|
|
|
// prepared and delivered one after the other.
|
12
|
|
|
// How to avoid this behavior will be shown in further examples.
|
13
|
|
|
|
14
|
|
|
|
15
|
|
|
// requiring autoloader
|
16
|
|
|
require_once(dirname(__FILE__).'/misc/bootstrap.php');
|
17
|
|
|
|
18
|
|
|
|
19
|
|
|
$context = PEIP\Context\XMLContext::createFromFile(dirname(__FILE__).'/config/config.xml');
|
20
|
|
|
$cafe = $context->getGateway('CafeGateway');
|
|
|
|
|
21
|
|
|
|
22
|
|
|
// this would be the same done by scripting.
|
|
|
|
|
23
|
|
|
/* ==
|
24
|
|
|
* $registry = new PEIP_Channel_Registry;
|
25
|
|
|
* $orders = new PEIP_Publish_Subscribe_Channel('orders');
|
26
|
|
|
* $preparedDrinks = new PEIP_Publish_Subscribe_Channel('preparedDrinks');
|
27
|
|
|
* $coldDrinks = new PEIP_Pollable_Channel('coldDrinks');
|
28
|
|
|
* $registry->register($coldDrinks);
|
29
|
|
|
* $hotDrinks = new PEIP_Pollable_Channel('hotDrinks');
|
30
|
|
|
* $registry->register($hotDrinks);
|
31
|
|
|
* $deliveries = new PEIP_Pollable_Channel('deliveries');
|
32
|
|
|
* $cafeGateway = new CafeGateway($orders, $deliveries);
|
33
|
|
|
* $orderWiretap = PEIP_Wiretap($orders);
|
34
|
|
|
* $orderSplitter = new OrderSplitter($orders);
|
35
|
|
|
* $router = new DrinkRouter($orderSplitter);
|
36
|
|
|
* $barista = new Barista;
|
37
|
|
|
* $coldDrinksActivator = new PEIP_Service_Activator(array($barista, 'prepareColdDrink'), $coldDrinks, $preparedDrinks);
|
38
|
|
|
* $hotDrinksActivator = new PEIP_Service_Activator(array($barista, 'prepareHotDrink'), $hotDrinks, $preparedDrinks);
|
39
|
|
|
* $drinkAggregator = new DrinkAggregator($preparedDrinks);
|
40
|
|
|
* $aggregatorActivator = new PEIP_Service_Activator(array($drinkAggregator, 'receiveOrder'), $orderWiretap);
|
41
|
|
|
* $waiter = new Waiter;
|
42
|
|
|
* $waiterActivator = new PEIP_Service_Activator(array($waiter, 'prepareDelivery'), $drinkAggregator, $deliveries);
|
43
|
|
|
* $cafe = $cafeGateway;
|
44
|
|
|
*/
|
45
|
|
|
|
46
|
|
|
|
47
|
|
|
if($cafe){
|
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();
|
57
|
|
|
var_dump($drinks);
|
58
|
|
|
}
|
59
|
|
|
|
60
|
|
|
}else{
|
61
|
|
|
throw new RuntimeException('Could not get CafeGateway');
|
62
|
|
|
}
|
63
|
|
|
|
64
|
|
|
|
65
|
|
|
|
66
|
|
|
|
67
|
|
|
|
This method has been deprecated.