This commit is contained in:
Dominik Liebler
2013-09-13 14:05:31 +02:00
parent 644d9cbd49
commit 8452c63b7e
6 changed files with 189 additions and 143 deletions

49
State/CreateOrder.php Normal file
View File

@@ -0,0 +1,49 @@
<?php
namespace DesignPatterns\Status;
/**
* 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($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!');
}
}