Skip to content


DCOM-235: [GH-317] Implemented an ObjectPersisterInterface for entity/object storage #543

doctrinebot opened this Issue · 3 comments

2 participants


Jira issue originally created by user @doctrinebot:

This issue is created automatically through a Github pull request on behalf of iltar:

Url: #317


Why is this useful?

Instead of using the repositoryClass, we use 'Repository as a Service'. This means that we inject our repository service instead of doing $em->getRepository('MyEntity'), this provides typehinting and autocomplete in IDEs. This introduces a minor inconvenience, we need to inject an EntityManagerInterface to provide persist/flush. We don't want the entire EntityManagerInterface capabilities just to store an object.

Using the ObjectPersisterInterface we can "hide" the EntityManagerInterface and only let the code know we have the persist and flush methods available. By default this is implemented on the EntityManager, but is also possible to be mocked or replaced by a custom implementation (rotating entity managers?).


class MyService
    private $op;
    private $es;

    public function **construct(ObjectPersisterInterface $op, MyEntityService $es)
        $this->op = $op;
        $this->es = $es;

    public function doSomething($value)
        $entity = $this->es->findByValue($value)->setValue('something');

    public function doSomethingElse()
        $entity = new MyEntity();

Comment created by @doctrinebot:

A related Github Pull-Request [GH-317] was closed:


Issue was closed with resolution "Won't Fix"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.