Last active
May 23, 2018 04:32
-
-
Save nahidulhasan/02fcfb1ca67190bda2446c09c004c41b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Report; | |
use Report\Repositories\OrdersRepository; | |
class OrdersReport | |
{ | |
protected $repo; | |
protected $formatter; | |
public function __construct(OrdersRepository $repo, OrdersOutPutInterface $formatter) | |
{ | |
$this->repo = $repo; | |
$this->formatter = $formatter; | |
} | |
public function getOrdersInfo($startDate, $endDate) | |
{ | |
$orders = $this->repo->getOrdersWithDate($startDate, $endDate); | |
return $this->formatter->output($orders); | |
} | |
} | |
namespace Report; | |
interface OrdersOutPutInterface | |
{ | |
public function output($orders); | |
} | |
namespace Report; | |
class HtmlOutput implements OrdersOutPutInterface | |
{ | |
public function output($orders) | |
{ | |
return '<h1>Orders: ' . $orders . '</h1>'; | |
} | |
} | |
namespace Report\Repositories; | |
use DB; | |
class OrdersRepository | |
{ | |
public function getOrdersWithDate($startDate, $endDate) | |
{ | |
return DB::table('orders')->whereBetween('created_at', [$startDate, $endDate])->get(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment