mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-09 16:36:37 +02:00
start a restructure
This commit is contained in:
35
Behavioral/State/OrderFactory.php
Normal file
35
Behavioral/State/OrderFactory.php
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user