mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-31 20:20:15 +02:00
State pattern is maintainable
state pattern change readme.rst
This commit is contained in:
@@ -2,34 +2,17 @@
|
||||
|
||||
namespace DesignPatterns\Behavioral\State;
|
||||
|
||||
class CreateOrder implements Order
|
||||
class CreateOrder extends StateOrder
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $details;
|
||||
|
||||
/**
|
||||
* @param array $details
|
||||
*/
|
||||
public function __construct(array $details)
|
||||
public function __construct()
|
||||
{
|
||||
$this->details = $details;
|
||||
$this->setStatus('created');
|
||||
}
|
||||
|
||||
public function shipOrder()
|
||||
protected function done()
|
||||
{
|
||||
$this->details['status'] = 'shipping';
|
||||
$this->details['updatedTime'] = time();
|
||||
}
|
||||
|
||||
public function completeOrder()
|
||||
{
|
||||
throw new \Exception('Can not complete the order which status is created');
|
||||
}
|
||||
|
||||
public function getStatus(): string
|
||||
{
|
||||
return $this->details['status'];
|
||||
$order = new ShippingOrder();
|
||||
static::$state = $order;
|
||||
//$this->setStatus('shipping');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user