2011-10-04 36 views
2

在WordPress中,插件是作为其他WordPress用户的安装包创建和分发的。Doctrine 2 ORM和WordPress - 集中化多个相关应用程序的Doctrine管理

我创建的每个插件在核心插件中共享某些常见实体。我正在努力创建和管理在这些插件中使用的EntitiyManager

我已经想出了两种方法来实现这一点,并想继续之前听到一些反馈:

选项1:单一的全球性的EntityManager

// 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 

与此问题版本是,虽然为路径添加到MetadataDriver道:

$entityManager->getConfig()->getMetadataDriverImpl()->addPaths();

我不确定这是否会实际更新此EntityManagerconfig内的MetadataDriver。我担心的是,这只会返回已更新为新路径的config,而不会更新EntityManager的配置。

这是真的吗?

注意,没有setConfig功能,所以如果是这样,我将不得不重新从每个插件EntityManager,击败的集中EntityManager目的。

选项2:多EntityManagers

// 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 

这种实现的问题是,它似乎效率不高。我注意到WordPress有一个Doctrine插件,虽然它是Doctrine 1.2.3,它允许你有一个集中的地方,因为我认为它适合于管理像核心实体那样共享资源的应用程序。

对于这种情况下使用Doctrine有什么想法。有没有办法集中操作,以便通过其他人依赖的一个中央插件来管理ORM?

回答

1

我能弄清楚的是:

$entityManager->getConfiguration()->getMetadataDriverImpl()->addPaths(); 

事实上确实增加额外的路径到$entityManager对象,而不是仅仅是与getConfiguration返回的配置。

我将继续完成此实现,并在此处更新结果。希望核心可以作为其他程序员使用的插件分发。