Created
January 21, 2012 11:42
-
-
Save Ocramius/1652475 to your computer and use it in GitHub Desktop.
example doctrine bootstrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Doctrine\Common\ClassLoader, | |
Doctrine\ORM\Tools\Setup, | |
Doctrine\ORM\Mapping\Driver\AnnotationDriver, | |
Doctrine\Common\Annotations\AnnotationReader, | |
Doctrine\ORM\EntityManager; | |
// Autoloaders | |
require_once __DIR__ . '/../lib/doctrine/lib/Doctrine/ORM/Tools/Setup.php'; | |
Doctrine\ORM\Tools\Setup::registerAutoloadGit(__DIR__ . '/../lib/doctrine'); | |
$classLoader = new ClassLoader('Entities', __DIR__); | |
$classLoader->register(); | |
$classLoader = new ClassLoader('DoctrineProxies', __DIR__); | |
$classLoader->register(); | |
$classLoader = new ClassLoader('Classes', __DIR__); | |
$classLoader->register(); | |
// Config | |
$isDevMode = true; //you want to autogenerate stuff and not use caches. So yes, it is dev mode! | |
$proxyDir = __DIR__ . DIRECTORY_SEPARATOR . 'DoctrineProxies'; //that's what the Setup tool uses internally | |
$config = Setup::createConfiguration($isDevMode, $proxyDir); | |
$paths = array(__DIR__ . DIRECTORY_SEPARATOR . 'Entities'); // paths that are crawled by the annotation metadata driver | |
$config->setMetadataDriverImpl(new AnnotationDriver( | |
new AnnotationReader(), | |
$paths | |
)); | |
$dbParams = array( | |
'dbname' => DB_DATABASE, | |
'user' => DB_USERNAME, | |
'password' => DB_PASSWORD, | |
'host' => DB_HOST_URL, | |
'driver' => 'pdo_mysql', | |
); | |
return EntityManager::create($dbParams, $config); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment