50 lines
1007 B
PHP
Raw Normal View History

2013-09-13 14:05:31 +02:00
<?php
namespace DesignPatterns\Behavioral\State;
2013-09-13 14:05:31 +02:00
/**
* 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;
2014-05-29 15:31:12 +08:00
return $this->updateOrder($this->order);
2013-09-13 14:05:31 +02:00
}
/**
* @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!');
}
}