PHP OOP: Providing Entities with an Identity Domain

A bit abstract problem here. I am experimenting with a domain model template and prohibiting other conflicts with dependencies. I need advice on creating an Identity for use on an identity card.

In most examples for the Data Mapper template that I saw (including the one described in this book: http://apress.com/book/view/9781590599099 ) - the user manually sets the identifier for this domain object using the installer:

$UserMapper = new UserMapper;

//returns a fully formed user object from record sets
$User = $UserMapper->find(1);

//returns an empty object with appropriate properties for completion
$UserBlank = $UserMapper->get();
$UserBlank->setId();
$UserBlank->setOtherProperties();

Now I don’t know if I am reading the examples incorrectly, but in the first $ User object the $ id property is retrieved from the data store (I assume that $ id is the row identifier). In the latter case, however, how can you set $ id for an object if it has not yet acquired one from the data store? The problem is to create the correct "identity" for the object so that it can be supported with the help of an identification card, so generating an arbitrary whole does not solve it.

My real thinking is to assign different fields for identification (i.e. email) and require their presence when creating empty domain objects. Alternatively, requiring that all objects be fully formed and use all properties as their identity ... are hardly effective.

(, , DBAL/DAO/Transaction..., ORM, ...)

+3
1

setId, , , / , (.. ). setId() "" ( ) .

, , . setId , . "" , . .

0

Source: https://habr.com/ru/post/1741997/


All Articles