title: Doctrine 2 ORM and WordPress - Centralizing Doctrine management for multiple dependent applications
body: <p>In WordPress, plugins are created and distributed as packages for other WordPress users to install.</p>
  
  <p>Each of the plugins I'm creating share certain common entities in a core plugin. I'm struggling with creating and managing the <code>EntitiyManager</code> to use among these plugins.</p>
  
  <p>I've come up with two ways to implement this and would like to hear some feedback before moving forward:</p>
  
  <p><strong>Option 1:</strong> Single, global EntityManager</p>
  
  <pre><code>// Example Plugin
      // Unique Entities
      // Add Unique Entity Paths and REQUIRED Entity Paths from Core Entities to EntityManager
  
  // Example Plugin
      // Unique Entities
      // Add Unique Entity Paths and REQUIRED Entity Paths from Core Entities to EntityManager
  
  // Core Plugin
      // Core Entities
      // Contains EntityManager
  </code></pre>
  
  <p>The problem with this version is that, although there is a way to add paths to a <code>MetadataDriver</code>:</p>
  
  <p><code>$entityManager-&gt;getConfig()-&gt;getMetadataDriverImpl()-&gt;addPaths();</code></p>
  
  <p>I am not sure if this will actually update the <code>MetadataDriver</code> within the <code>config</code> of this <code>EntityManager</code>. My worries is that this will only return a <code>config</code> that has been updated with the new paths and not update the <code>EntityManager</code>'s config.</p>
  
  <p>Is this true?</p>
  
  <p>Note that there is no <code>setConfig</code> function so if it is, I would have to recreate the <code>EntityManager</code> from each plugin, defeating the purpose of a centralized <code>EntityManager</code>.</p>
  
  <p><strong>Option 2:</strong> Multiple EntityManagers</p>
  
  <pre><code>// Example Plugin
      // Unique Entities
      // Create EntityManager with Unique Entity path and path to Core Entities that are required for this plugin.
  
  // Core Plugin
      // Core Entities
  </code></pre>
  
  <p>The problem with this implementation is that it seems inefficient. I've noticed that there is a Doctrine plugin for WordPress, although it is Doctrine 1.2.3, and it allows you to have one centralized place as I would assume is appropriate for managing applications that share resources like the <em>Core Entities</em>.</p>
  
  <p>What are your thoughts on using Doctrine in this scenario. Is there a way to centralize the operations so that the ORM is managed through one central plugin that others depend upon?</p>