doctrine - DDD PHP Doctrine2 - Mapping -
i hear how peoploe map domain objects data mapper pattern in doctrine2. went problem, when aggregates use clean php array , use php functions work array array_shift example. anyway till started integrate doctrine mappings domain entities. problem how doctrine works assosciations between entities. whenever aggregate root had 1 many relationship (or other tbh), doctrine used arraycollection class on that, instead of normal array. use 1 of methods toarray(), have check first in domain object if doctrine collections class, dirty. anyway chose in aggregate repository, before returning class. made reflection class set property public , replaced clean php array. works less dirty, still dont tbh. question is, how guys handle limitations od doctrine or maybe there no limitation :). , next question, if guys use doctrine arraycollection in domain classes?
what using array for?
i suspect problem using arrays instead of objects. objects should reflect domain , provide methods exists in domain. if replacing real world behaviour arrays not following ddd principles.
simple example:
/** * * @orm\table(name="sales_flat_order") * @orm\entity(repositoryclass="candle\orderbundle\repository\mage\orderrepository") */ class order implements orderinterface { /** * @orm\onetomany(targetentity="orderitem", mappedby="order", cascade={"persist"}) * * @var orderitem[] */ private $orderitems; /** * constructor. */ public function __construct() { $this->orderitems = new arraycollection(); } /** * check if items marked scanned * * @param integer $warehouseid warehouse id check for. * * @return boolean */ public function isorderscancompleted($warehouseid) { foreach ($this->orderitems $orderitem) { if ($orderitem->getwarehouseid() == $warehouseid && !$orderitem->isscancomplete()) { return false; } } return true; } }
i have iterated through array of db values of related orderitems , check values constitute "isscancomplete" flag, decided implement , encapsulate in orderitem class. hence no need array of values.