mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-02-23 17:22:41 +01:00
36 lines
742 B
PHP
36 lines
742 B
PHP
<?php
|
|
|
|
namespace DesignPatterns\Behavioral\State;
|
|
|
|
/**
|
|
* Class OrderFactory
|
|
*/
|
|
class OrderFactory
|
|
{
|
|
private function __construct()
|
|
{
|
|
throw new \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;
|
|
}
|
|
}
|
|
}
|