I have two objects: Post and Post \ Version. I configured it so that version control is automatically handled inside the Post object, so the developer does not need to use Post \ Version manually. It does not use EntityManager, just a little reflection ... is this normal?
<?php
public function setContent($content)
{
$this->_setVersionValue('content', $content);
}
private function _setVersionValue($property, $value)
{
$version = clone $this->getActiveVersion();
$refl = new \ReflectionProperty($version, $property);
$refl->setAccessible(true);
$version->setCreatedBy($this->getCurrentUser());
$refl->setValue($version, $value);
$reflProp = new \ReflectionProperty($version, 'id');
$reflProp->setAccessible(true);
$reflProp->setValue($version, null);
$this->setActiveVersion($version);
}
Post only keeps a link to the latest version. The version has a link back to the message in which they belong.
source
share