private function loadDoctrine($dbname, $host, $username, $password) { $lib = APPLICATION_PATH . "/doctrine-orm"; Doctrine\ORM\Tools\Setup::registerAutoloadDirectory($lib); if (APPLICATION_ENV == "production") { $cache = new \Doctrine\Common\Cache\ApcCache(); } else { $cache = new \Doctrine\Common\Cache\ArrayCache(); } $config = new Configuration(); $config->setMetadataCacheImpl($cache); $driverImpl = $config->newDefaultAnnotationDriver(APPLICATION_PATH . '/modules/default/models'); $config->setMetadataDriverImpl($driverImpl); $config->setQueryCacheImpl($cache); $config->setProxyDir(APPLICATION_PATH . '/Proxies'); $config->setProxyNamespace('EasyCMS\\Proxies'); if ($applicationMode == "production") { $config->setAutoGenerateProxyClasses(false); } else { $config->setAutoGenerateProxyClasses(true); } $connectionOptions = array('driver' => 'pdo_mysql', 'dbname' => $dbname, 'user' => $username, 'password' => $password, 'host' => $host); $em = EntityManager::create($connectionOptions, $config); Zend_Registry::set('**application_db_connection**', $em); }
/** * Get Doctrine2Cache * * @return Doctrine\Common\Cache */ public function getDoctrine2cache() { if ($this->_d2cache === null) { // Get Doctrine configuration options from the application.ini file $config = $this->getOptions(); if (!isset($config['autoload_method'])) { $config['autoload_method'] = 'git'; } switch ($config['autoload_method']) { case 'pear': require_once $config['path'] . '/Tools/Setup.php'; Doctrine\ORM\Tools\Setup::registerAutoloadPEAR(); break; case 'dir': require_once $config['path'] . '/Tools/Setup.php'; // FIXME Doctrine\ORM\Tools\Setup::registerAutoloadDirectory(); break; case 'composer': break; default: require_once $config['path'] . '/lib/Doctrine/ORM/Tools/Setup.php'; Doctrine\ORM\Tools\Setup::registerAutoloadGit($config['path']); } if ($config['type'] == 'ApcCache') { $cache = new \Doctrine\Common\Cache\ApcCache(); } elseif ($config['type'] == 'MemcacheCache') { $memcache = new Memcache(); for ($cnt = 0; $cnt < count($config['memcache']['servers']); $cnt++) { $server = $config['memcache']['servers'][$cnt]; $memcache->addServer(isset($server['host']) ? $server['host'] : '127.0.0.1', isset($server['port']) ? $server['port'] : 11211, isset($server['persistent']) ? $server['persistent'] : false, isset($server['weight']) ? $server['weight'] : 1, isset($server['timeout']) ? $server['timeout'] : 1, isset($server['retry_int']) ? $server['retry_int'] : 15); } $cache = new \Doctrine\Common\Cache\MemcacheCache(); $cache->setMemcache($memcache); } else { $cache = new \Doctrine\Common\Cache\ArrayCache(); } if (isset($config['namespace'])) { $cache->setNamespace($config['namespace']); } // stick the cache in the registry Zend_Registry::set('d2cache', $cache); $this->setDoctrine2Cache($cache); } return $this->_d2cache; }
<?php require "Doctrine/ORM/Tools/Setup.php"; Doctrine\ORM\Tools\Setup::registerAutoloadDirectory('.'); // use Doctrine\ORM\Tools\Setup; // use Doctrine\ORM\EntityManager; $isDevMode = true; // the connection configuration $dbParams = array('driver' => 'pdo_mysql', 'user' => 'lab', 'password' => '7DULcn6NaWdvVxaN', 'dbname' => 'lab', 'host' => 'localhost'); //$config = Setup::createAnnotationMetadataConfiguration(array('config/Entities/'), $isDevMode); $config = Doctrine\ORM\Tools\Setup::createYAMLMetadataConfiguration(array('config/yml/'), $isDevMode); $em = Doctrine\ORM\EntityManager::create($dbParams, $config); $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array('em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em))); include "ORM/load.php";
if (is_file(__DIR__ . '/' . $file)) { include $file; return true; } return false; }); //initialize smarty require __DIR__ . '/lib/php/Smarty-3.1.12/libs/Smarty.class.php'; $smarty = new Smarty(); $smarty->setCacheDir("tmp"); $smarty->setCompileDir("tmp"); //initialize doctrine date_default_timezone_set("Europe/Berlin"); // Setup Autoloader (1) require __DIR__ . '/lib/php/DoctrineORM-2.3.0/Doctrine/ORM/Tools/Setup.php'; Doctrine\ORM\Tools\Setup::registerAutoloadDirectory(__DIR__ . "/lib/php/DoctrineORM-2.3.0"); $config = new Doctrine\ORM\Configuration(); // (2) // Proxy Configuration (3) $config->setProxyDir(__DIR__ . '/tmp'); $config->setProxyNamespace('tmp'); $config->setAutoGenerateProxyClasses(true); // Mapping Configuration (4) $driverImpl = $config->newDefaultAnnotationDriver(__DIR__ . "/model"); $config->setMetadataDriverImpl($driverImpl); // Caching Configuration (5) $cache = new \Doctrine\Common\Cache\ArrayCache(); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); // database configuration parameters (6) $conn = array('driver' => 'pdo_sqlite', 'path' => __DIR__ . '/tmp/db.sqlite', 'driverOptions' => array(1002 => 'SET NAMES utf8'));