doctrine/common — pull request #317 by iltar (2014-02-21 16:20:35+00:00)
Title: Implemented an ObjectPersisterInterface for entity/object storage

### 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?).

#### Example
``` php

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');
$this->op->flush();
}

public function doSomethingElse()
{
$entity = new MyEntity();
$this->op->persist($entity);
$this->op->flush();
}
}

```