forked from DesignPatternsPHP/DesignPatternsPHP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderFactory.php
More file actions
35 lines (31 loc) · 727 Bytes
/
OrderFactory.php
File metadata and controls
35 lines (31 loc) · 727 Bytes
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
<?php
namespace DesignPatterns\Status;
/**
* Class OrderFactory
*/
class OrderFactory
{
private function __construct()
{
throw Exception('Can not instance the OrderFactory class!');
}
/**
* @param int $id
*
* @return CreateOrder|ShippingOrder
* @throws \Exception
*/
public static function getOrder($id)
{
$order = 'Get Order From Database';
switch ($order['status']) {
case 'created':
return new CreateOrder($order);
case 'shipping':
return new ShippingOrder($order);
default:
throw new \Exception('Order status error!');
break;
}
}
}