Acceptable entity logic?

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)
{
    // get reflection property
    $version = clone $this->getActiveVersion();
    $refl = new \ReflectionProperty($version, $property);
    $refl->setAccessible(true);

    // update value
    $version->setCreatedBy($this->getCurrentUser());
    $refl->setValue($version, $value);

    // clear ID
    $reflProp = new \ReflectionProperty($version, 'id');
    $reflProp->setAccessible(true);
    $reflProp->setValue($version, null);

    // set to new version
    $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.

0
source share
2 answers

It's fine. Of course, you should always find your own workflow on how to mix classes and instances.

0
source

, Doctrine2 - , . .

PS. Post PostVersion (, MyProject\Entity\Blog)

+1

All Articles