mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-02-23 17:22:41 +01:00
50 lines
1007 B
PHP
50 lines
1007 B
PHP
<?php
|
|
|
|
namespace DesignPatterns\Behavioral\State;
|
|
|
|
/**
|
|
* Class CreateOrder
|
|
*/
|
|
class CreateOrder implements OrderInterface
|
|
{
|
|
/**
|
|
* @var array
|
|
*/
|
|
private $order;
|
|
|
|
/**
|
|
* @param array $order
|
|
*
|
|
* @throws \Exception
|
|
*/
|
|
public function __construct(array $order)
|
|
{
|
|
if (empty($order)) {
|
|
throw new \Exception('Order can not be empty!');
|
|
}
|
|
$this->order = $order;
|
|
}
|
|
|
|
/**
|
|
* @return mixed
|
|
*/
|
|
public function shipOrder()
|
|
{
|
|
$this->order['status'] = 'shipping';
|
|
$this->order['updatedTime'] = time();
|
|
|
|
// Setting the new order status into database;
|
|
return $this->updateOrder($this->order);
|
|
}
|
|
|
|
/**
|
|
* @return mixed|void
|
|
* @throws \Exception
|
|
*/
|
|
public function completeOrder()
|
|
{
|
|
//Can not complete the order which status is created, throw exception;
|
|
throw new \Exception('Can not complete the order which status is created!');
|
|
}
|
|
}
|