Skip to content

Instantly share code, notes, and snippets.

@ornicar
Created August 23, 2010 11:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ornicar/545320 to your computer and use it in GitHub Desktop.
Save ornicar/545320 to your computer and use it in GitHub Desktop.
<?php
/**
* The problem
* -----------
* People start to build Symfony2 Bundles which need a database.
* Instead of having ORM-only Bundles and ODM-only Bundles,
* people try to make Bundles more generic, for obvious reasons.
*
* A proposition
* ----------
* Here is a proposition of a minimalist interface that
* EntityManager and DocumentManager could implement.
* It could make Bundle developers life easier.
* This is just a draft designed to create a discussion.
* All these methods already exist in ORM and ODM.
* I'm not sure if they make sense with CouchDB.
* Thoughts?
*/
interface ObjectManagerInterface
{
/**
* Tells the ObjectManager to make an instance managed and persistent.
*/
public function persist($object);
/**
* Removes a document instance.
*/
public function remove($object);
/**
* Refreshes the persistent state of an object from the database,
* overriding any local changes that have not yet been persisted.
*/
public function refresh($object);
/**
* Detaches a document from the DocumentManager, causing a managed object to
* become detached. Unflushed changes made to the object if any
* (including removal of the document), will not be synchronized to the database.
* Objects which previously referenced the detached object will continue to
* reference it.
*/
public function detach($document);
/**
* Flushes all changes to objects that have been queued up to now to the database.
* This effectively synchronizes the in-memory state of managed objects with the
* database.
*/
public function flush();
}
@henrikbjorn
Copy link

Personally i think this is a good idea since doctrine has more than one *Manager classes this would solve a problem with supporting both ORM and ODM

@jmikola
Copy link

jmikola commented Sep 29, 2010

Would this be a candidate for doctrine-common, perhaps? I've taken a look at your ForumBundle and it's use of generic DAO classes, and both would be a good style for cross-DB bundles.

@ornicar
Copy link
Author

ornicar commented Sep 29, 2010

Yeah we reproduced on ForumBundle the strategy I tried for DoctrineUserBundle. It looks usable, but will only work with Doctrine. And I assume entity and document mappers share methods like "persist" and "flush".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment