-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
80 lines (68 loc) · 3.39 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<pre>
<?php
require_once __DIR__.'/vendor/autoload.php';
use Example\Order\Process\Postpayment;
use Example\Order\ProcessConstants;
use Example\Order\EventConstants;
use Example\Order\Order;
use Example\Order\Process\Prepayment;
use Metabor\NamedCollection;
$processes = new NamedCollection();
$processes->add(new Prepayment());
$processes->add(new Postpayment());
$orders = array();
$orders['PREPAYMENT 1'] = new Order('PREPAYMENT 1', $processes->get(ProcessConstants::PROCESS_PREPAYMENT));
$orders['PREPAYMENT 2'] = new Order('PREPAYMENT 2', $processes->get(ProcessConstants::PROCESS_PREPAYMENT));
$orders['POSTPAYMENT 1'] = new Order('POSTPAYMENT 1', $processes->get(ProcessConstants::PROCESS_POSTPAYMENT));
$orders['POSTPAYMENT 2'] = new Order('POSTPAYMENT 2', $processes->get(ProcessConstants::PROCESS_POSTPAYMENT));
echo '============================================================='.PHP_EOL;
echo 'all created orders have the status "new"'.PHP_EOL;
echo '============================================================='.PHP_EOL;
foreach ($orders as $order) {
echo $order.' has status '.$order->getCurrentStateName().PHP_EOL;
echo 'possible events: '.implode(', ', $order->getEventNames()).PHP_EOL;
echo '-------------------------------------------------------------'.PHP_EOL;
}
echo '============================================================='.PHP_EOL;
echo 'now we are authorizing all orders if possible'.PHP_EOL;
echo '============================================================='.PHP_EOL;
foreach ($orders as $order) {
echo $order.' has status '.$order->getCurrentStateName().PHP_EOL;
if ($order->hasEvent(EventConstants::EVENT_AUTHORIZE)) {
$order->triggerEvent(EventConstants::EVENT_AUTHORIZE);
echo $order.' has status '.$order->getCurrentStateName().PHP_EOL;
}
if ($order->hasEvent(EventConstants::EVENT_PAID)) {
$order->triggerEvent(EventConstants::EVENT_PAID);
echo $order.' has status '.$order->getCurrentStateName().PHP_EOL;
}
echo '-------------------------------------------------------------'.PHP_EOL;
}
echo '============================================================='.PHP_EOL;
echo 'now we are shipping all orders if possible'.PHP_EOL;
echo '============================================================='.PHP_EOL;
foreach ($orders as $order) {
echo $order.' has status '.$order->getCurrentStateName().PHP_EOL;
if ($order->hasEvent(EventConstants::EVENT_SHIPPING)) {
$order->triggerEvent(EventConstants::EVENT_SHIPPING);
echo $order.' has status '.$order->getCurrentStateName().PHP_EOL;
}
echo '-------------------------------------------------------------'.PHP_EOL;
}
echo '============================================================='.PHP_EOL;
echo 'now all orders will be returned'.PHP_EOL;
echo '============================================================='.PHP_EOL;
foreach ($orders as $order) {
$eventName = EventConstants::EVENT_RETURNED;
echo $order.' has status '.$order->getCurrentStateName().PHP_EOL;
try {
$order->triggerEvent($eventName);
} catch (Exception $e) {
echo 'Triggering the event "'.EventConstants::EVENT_RETURNED.'" on order "'.$order
.'" throws an error: '.$e->getMessage().PHP_EOL;
}
echo $order.' has status '.$order->getCurrentStateName().PHP_EOL;
echo '-------------------------------------------------------------'.PHP_EOL;
}
?>
</pre>