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
|
|
|
for ($i = 1; $i <= 10; $i++) { |
49
|
|
|
// create and place orders |
50
|
|
|
$order = new Order(); |
51
|
|
|
$order->addItem('LATTE', 2, false); |
52
|
|
|
$order->addItem('MOCCA', 3, true); |
53
|
|
|
$cafe->placeOrder($order); |
54
|
|
|
// receive drinks |
55
|
|
|
$drinks = $cafe->receiveDelivery(); |
56
|
|
|
} |
57
|
|
|
} else { |
58
|
|
|
throw new RuntimeException('Could not get CafeGateway'); |
59
|
|
|
} |
60
|
|
|
|
This method has been deprecated.