php - How does Doctrine set private IDs -
in php, can create model private/protected $id variable , no setter.
doctrine orm able set property when object saved/loaded.
how work internally? assume handled serialization, haven't been able find code responsible of behavior.
the first time doctrine instantiates entity (such user), this:
$this->prototype = unserialize(sprintf('o:%d:"%s":0:{}', strlen($this->name), $this->name)); which creates object of type without calling constructor (deserialization avoids phone call __construct, , intentionally don't have worry constructor looks or does).
after first object has been initialized, doctrine uses clone create new instances of same object type.
$entity = clone $this->prototype; from cloned objects, will:
$reflection = new \reflectionobject($entity); $property = $reflection->getproperty('idfield'); $property->setaccessible(true); $property->setvalue($entity, 123); the actual code more complex due doctrine's back upwards compound primary keys, should guide right direction.
php doctrine2
No comments:
Post a Comment