Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 11th, 2012  |  syntax: None  |  size: 2.45 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. use Doctrine\ORM\EntityManager,
  4.     Doctrine\ORM\Configuration;
  5.  
  6. class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
  7. {
  8.        
  9.         public function _initAutoload()
  10.         {
  11.             $resourceLoader = new Zend_Loader_Autoloader_Resource(array(
  12.                 'basePath'  => '/',
  13.                 'namespace' => '',
  14.             ));        
  15.         }
  16.        
  17.     /**
  18.      * _initDoctrine
  19.      *
  20.      * @access protected
  21.      * @return void
  22.      */
  23.     protected function _initDoctrine()
  24.     {
  25.         // include and register Doctrine's class loader
  26.         require_once('Doctrine/Common/ClassLoader.php');
  27.         $classLoader = new \Doctrine\Common\ClassLoader(
  28.             'Doctrine'
  29.         );
  30.         $classLoader->register();
  31.  
  32.         // create the Doctrine configuration
  33.         $config = new \Doctrine\ORM\Configuration();
  34.  
  35.         // setting the cache ( to ArrayCache. Take a look at
  36.         // the Doctrine manual for different options ! )
  37.         $cache = new \Doctrine\Common\Cache\ArrayCache;
  38.         $config->setMetadataCacheImpl($cache);
  39.         $config->setQueryCacheImpl($cache);
  40.  
  41.         // choosing the driver for our database schema
  42.         // we'll use annotations
  43.         $driver = $config->newDefaultAnnotationDriver(
  44.             APPLICATION_PATH . '/modules/default/models'
  45.         );
  46.         $config->setMetadataDriverImpl($driver);
  47.  
  48.         // set the proxy dir and set some options
  49.         $config->setProxyDir(
  50.             APPLICATION_PATH . '/modules/default/models/Proxies'
  51.         );
  52.         $config->setAutoGenerateProxyClasses(true);
  53.         $config->setProxyNamespace('App\Proxies');
  54.  
  55.         // now create the entity manager and use the connection
  56.         // settings we defined in our application.ini
  57.         $connectionSettings = $this->getOption('doctrine');
  58.         $conn = array(
  59.             'driver'    => $connectionSettings['connection']['driver'],
  60.             'user'      => $connectionSettings['connection']['user'],
  61.             'password'  => $connectionSettings['connection']['password'],
  62.             'dbname'    => $connectionSettings['connection']['dbname'],
  63.             'host'      => $connectionSettings['connection']['host']
  64.         );
  65.         $entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
  66.  
  67.         // push the entity manager into our registry for later use
  68.         $registry = Zend_Registry::getInstance();
  69.         $registry->entityManager = $entityManager;
  70.  
  71.         return $entityManager;
  72.     }
  73. }