I would like to integrate Doctrine 2 ORM into WordPress for use in the plugins I’m developing. There is currently a plugin that offers Doctrine 1.2.3 ORM support in WordPress, but not v2.
The biggest problem I’m having is that I don’t understand how Doctrine 2 ORM interacts with my code; specifically, what their configuration code provides me with and where I should go from here:
// 3.1.1
require dirname( __FILE__ ) . '/lib/Doctrine/ORM/Tools/Setup.php';
$lib = dirname( __FILE__ ) . '/lib';
DoctrineORMToolsSetup::registerAutoloadDirectory($lib);
// 3.1.2
use DoctrineORMEntityManager,
DoctrineORMConfiguration;
if($applicationMode == "development") {
$cache = new DoctrineCommonCacheArrayCache;
} else {
$cache = new DoctrineCommonCacheApcCache;
}
$config = new Configuration;
$config->setMetadataCacheImpl($cache);
$driverImpl = $config->newDefaultAnnotationDriver('/path/to/lib/MyProject/Entities');
$config->setMetadataDriverImpl($driverImpl);
$config->setQueryCacheImpl($cache);
$config->setProxyDir('/path/to/myproject/lib/MyProject/Proxies');
$config->setProxyNamespace('MyProjectProxies');
if ($applicationMode == "development") {
$config->setAutoGenerateProxyClasses(true);
} else {
$config->setAutoGenerateProxyClasses(false);
}
$connectionOptions = array(
'driver' => 'pdo_sqlite',
'path' => 'database.sqlite'
);
$em = EntityManager::create($connectionOptions, $config);
I had continued reading through sections of the documentation up to section 8 and have some understanding. My questions are:
-
Is this configuration enough to allow me to work with Doctrine 2 ORM in my plugins?
-
Are there any other key steps I’m missing before working with Doctrine 2 ORM? The WordPress plugin seems to automatically generate all of the appropriate classes from the database. I read the documentation a few times, but I feel like I’m missing some big step… or maybe Doctrine 2 ORM is just that much different?
-
Is the EntityManager some global variable that I can use throughout my entities?
-
I assume I have to link everything together,
@Entity
in a file is not enough for Doctrine to know where the entity is. Is there somewhere in the documentation that defines this?
If anyone can provide a quick rundown of how it all works together: configuration, entities, etc. Or provide any clear cut tutorials that may already be out there, I would really appreciate it.
IMHO you shouldn’t use Doctrine2 with WP
Doctrine 2 is more appropriate solution for site with huge business logic and I believe you don’t use WP for this purposes
Doctrine 2 has huge code base (~11MB) which add overhead for classloading and processing of requests
Doctrine 2 use a lot of memory with default hydration mode (object)
Building custom sql is much harder with Doctrine.