This commit is contained in:
Dominik Liebler
2013-09-13 14:05:31 +02:00
parent 644d9cbd49
commit 8452c63b7e
6 changed files with 189 additions and 143 deletions

35
State/OrderFactory.php Normal file
View File

@@ -0,0 +1,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;
}
}
}