Created
October 14, 2015 06:18
-
-
Save nimmneun/cc323762032dc73119ff to your computer and use it in GitHub Desktop.
Oversimplified Order Aggregate ... just trying stuff *lol
This file contains hidden or 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 | |
/** | |
* @inherits ArrayAccess, IteratorAggregate, Countable from Collection | |
* @author neun | |
* @since 12.10.2015 22:24 | |
*/ | |
class OrderAggregate extends Collection | |
{ | |
/** | |
* @var Order | |
*/ | |
protected $order; | |
/** | |
* @var Customer | |
*/ | |
protected $customer; | |
/** | |
* @var OrderItem[] | |
*/ | |
protected $items; | |
public function __construct($orderId) | |
{ | |
$sql = "SELECT * FROM `order` WHERE id = {$orderId}"; | |
$this->order = pdo('mono')->query($sql)->fetchObject('Order'); | |
$sql = "SELECT * FROM `customer` WHERE id = {$this->order->customerId()}"; | |
$this->customer = pdo('mono')->query($sql)->fetchObject('Customer'); | |
$sql = "SELECT * FROM `order_item` WHERE order_id = {$orderId}"; | |
$stm = pdo('mono')->query($sql); | |
while ($item = $stm->fetchObject('OrderItem')) { | |
$this->add($item); | |
} | |
} | |
public function order() | |
{ | |
return $this->order; | |
} | |
public function customer() | |
{ | |
return $this->customer; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Well ... I guess I just learned that ...
... actually not only fills the properties of a model ... but also retains their visibility if column_name equals property_name ... and since you dont access properties directly your getters can still look like...
sw33t =)