2 use Doctrine\Common\ClassLoader
,
3 Doctrine\ORM\Configuration
,
4 Doctrine\ORM\EntityManager
,
5 Doctrine\Common\Cache\ApcCache
,
6 Doctrine\Common\Cache\ArrayCache
,
7 Doctrine\DBAL\Event\Listeners\MysqlSessionInit
;
9 require_once 'lib/Doctrine/Common/ClassLoader.php';
11 // Set up class loading. You could use different autoloaders, provided by your favorite framework,
14 $classLoader = new ClassLoader('Doctrine\ORM', realpath(__DIR__ . '/lib'));
15 $classLoader->register();
16 $classLoader = new ClassLoader('Doctrine\DBAL', realpath(__DIR__ . '/lib'));
17 $classLoader->register();
18 $classLoader = new ClassLoader('Doctrine\Common', realpath(__DIR__ . '/lib'));
19 $classLoader->register();
20 $classLoader = new ClassLoader('Symfony', realpath(__DIR__ . '/lib'));
21 $classLoader->register();
23 $classLoader = new ClassLoader('Doctrine\ORM', 'lib');
24 $classLoader->register();
25 $classLoader = new ClassLoader('Doctrine\DBAL', 'lib');
26 $classLoader->register();
27 $classLoader = new ClassLoader('Doctrine\Common', 'lib');
28 $classLoader->register();
29 $classLoader = new ClassLoader('Symfony', 'lib');
30 $classLoader->register();
35 // Custom class loaders
44 foreach($namespaces as $namespace) {
45 $classLoader = new ClassLoader($namespace, realpath(__DIR__
. '/classes'));
46 $classLoader->register();
50 $config = new Configuration
;
51 //$cache = new ApcCache;
52 $cache = new ArrayCache
;
53 $config->setMetadataCacheImpl($cache);
54 $driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__
. '/classes/Entities'));
55 $config->setMetadataDriverImpl($driverImpl);
56 $config->setQueryCacheImpl($cache);
58 // Proxy configuration
59 $config->setProxyDir(__DIR__
. '/classes/Proxies');
60 $config->setProxyNamespace('Proxies');
61 $config->setAutoGenerateProxyClasses(false);
63 require('db-config.php');
65 // Create EntityManager
66 $em = EntityManager
::create($connectionOptions, $config);
67 $em->getEventManager()->addEventSubscriber(new MysqlSessionInit('utf8', 'utf8_unicode_ci'));
69 // Helpers for console
70 $helperSet = new \Symfony\Component\Console\Helper\HelperSet
;
71 $helperSet->set(new \Doctrine\DBAL\Tools\Console\Helper\
ConnectionHelper($em->getConnection()), 'db');
72 $helperSet->set(new \Doctrine\ORM\Tools\Console\Helper\
EntityManagerHelper($em), 'em');