[PR #959] [CLOSED] Implemented an ObjectPersisterInterface for entity/object storage #8963

Closed
opened 2026-01-22 16:02:31 +01:00 by admin · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/doctrine/orm/pull/959
Author: @linaori
Created: 2/21/2014
Status: Closed

Base: masterHead: master


📝 Commits (1)

  • c09bcb8 Implemented an ObjectPersisterInterface for entity/object storage

📊 Changes

2 files changed (+20 additions, -1 deletions)

View changed files

📝 lib/Doctrine/ORM/EntityManager.php (+1 -1)
lib/Doctrine/ORM/ObjectPersisterInterface.php (+19 -0)

📄 Description

Moved to: https://github.com/doctrine/common/pull/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?).

Example


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();
    }
}


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/doctrine/orm/pull/959 **Author:** [@linaori](https://github.com/linaori) **Created:** 2/21/2014 **Status:** ❌ Closed **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (1) - [`c09bcb8`](https://github.com/doctrine/orm/commit/c09bcb8eeba772ea55bd8f06b49af56e2e05305d) Implemented an ObjectPersisterInterface for entity/object storage ### 📊 Changes **2 files changed** (+20 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `lib/Doctrine/ORM/EntityManager.php` (+1 -1) ➕ `lib/Doctrine/ORM/ObjectPersisterInterface.php` (+19 -0) </details> ### 📄 Description Moved to: https://github.com/doctrine/common/pull/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?). #### 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(); } } ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
admin added the pull-request label 2026-01-22 16:02:31 +01:00
admin closed this issue 2026-01-22 16:02:32 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#8963