setAttribute(Doctrine::ATTR_QUERY_CACHE, new Doctrine_Cache_Apc()); $manager->setAttribute(Doctrine::ATTR_RESULT_CACHE, new Doctrine_Cache_Apc()); $manager->setAttribute(Doctrine::ATTR_RESULT_CACHE_LIFESPAN, 3600); } $manager->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true); $dbarray = $dbconfig->toArray(); $dbarray = array_keys($dbarray); function getPDO($dsn,$user,$pass) { try { $pdo = new PDO($dsn,$user,$pass); } catch (PDOException $e) { return false; } return $pdo; } require_once('Zend/Db.php'); foreach($dbarray as $dbname) { if($dbname != 'debug') { $dbengine = isset($dbconfig->$dbname->dbengine) ? $dbconfig->$dbname->dbengine : 'pdo'; $dbtype = isset($dbconfig->$dbname->dbtype) ? $dbconfig->$dbname->dbtype : 'mysql'; switch(strtolower($dbconfig->$dbname->dbclass)) { case 'zend': if(!isset($zdb)) { $zdb = array(); } if($dbconfig->$dbname->dbtype == 'odbc') { require_once('Crystal/Db/Odbc.php'); } $dbtype = $dbconfig->$dbname->dbengine == 'pdo' ? 'Pdo_'.ucfirst($dbconfig->$dbname->dbtype) : ucfirst($dbconfig->$dbname->dbengine); $zdb[$dbname] = Zend_Db::factory($dbtype,array( 'host'=>$dbconfig->$dbname->dbhost, 'username'=>$dbconfig->$dbname->dbuser, 'password'=>$dbconfig->$dbname->dbpass, 'dbname'=>$dbconfig->$dbname->dbname )); if(isset($dbconfig->$dbname->profile)) { $zdb[$dbname]->getProfiler()->setEnabled(true); } Zend_Registry::set('ZendDb',$zdb); break; case 'doctrine': switch($dbengine) { case 'pdo': $pdo = false; $tries = 0; while(!$pdo) { $pdo = getPDO("{$dbtype}:host={$dbconfig->$dbname->dbhost};dbname={$dbconfig->$dbname->dbname}", $dbconfig->$dbname->dbuser, $dbconfig->$dbname->dbpass); if($dbtype == 'mysql') { $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES,true); $pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,1); } if(!$pdo) { sleep(1); } } $conn = Doctrine_Manager::connection($pdo, $dbname); break; default: $dsn = "{$dbtype}://{$dbconfig->$dbname->dbuser}:{$dbconfig->$dbname->dbpass}@{$dbconfig->$dbname->dbhost}/{$dbconfig->$dbname->dbname}"; $conn = Doctrine_Manager::connection($dsn); break; } $conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true); break; default: // both if(!isset($zdb)) { $zdb = array(); } $dbtype = $dbconfig->$dbname->dbengine == 'pdo' ? 'Pdo_'.ucfirst($dbconfig->$dbname->dbtype) : ucfirst($dbconfig->$dbname->dbengine); $zdb[$dbname] = Zend_Db::factory($dbtype,array( 'host'=>$dbconfig->$dbname->dbhost, 'username'=>$dbconfig->$dbname->dbuser, 'password'=>$dbconfig->$dbname->dbpass, 'dbname'=>$dbconfig->$dbname->dbname )); $pdo = $zdb[$dbname]->getConnection(); if($dbtype == 'mysql') { $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES,true); $pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,1); } $conn = Doctrine_Manager::connection($pdo, $dbname); $conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true); Zend_Registry::set('ZendDb',$zdb); break; } //$profiler = new Doctrine_Connection_Profiler(); //$conn->setListener($profiler); if(isset($dbconfig->debug) && isset($conn)) { require_once('Crystal/CDoctrine/Debug.php'); $debugger = new Doctrine_Debug(); $debugger->_config = $dbconfig->debug; $conn->addListener($debugger); } } } unset($dbconfig); unset($dbarray); /** * Load base model */ Zend_Loader::loadClass('Crystal_Record'); /** * Set up the application's models path (modules will define their own model directories */ $model_path = array(); $model_path['basemodels']= $base_path.DIRECTORY_SEPARATOR.'application'.DIRECTORY_SEPARATOR.'models'.DIRECTORY_SEPARATOR.'generated'; $model_path['core'] = $base_path.DIRECTORY_SEPARATOR.'application'.DIRECTORY_SEPARATOR.'models'; Zend_Registry::set('model_path',$model_path); /** * Grab any modules and run their bootstrap (to set up observers, plugins, add extra controller dirs, etc) */ $config = new Zend_Config_Ini($base_path.DIRECTORY_SEPARATOR.'config.ini','modules'); if($config->count() > 0) { $modules = $config->toArray(); if(count($modules) > 0) { foreach($modules as $module_name => $module) { if(isset($module['bootstrap_cli'])) { require_once($module['bootstrap_cli']); } elseif(file_exists($base_path.DIRECTORY_SEPARATOR.'application'.DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR.$module['name'].DIRECTORY_SEPARATOR.'bootstrap_cli.php')) { require_once($base_path.DIRECTORY_SEPARATOR.'application'.DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR.$module['name'].DIRECTORY_SEPARATOR.'bootstrap_cli.php'); } } } } /** * The bootstrap.php file in the application root will be extra configuration for the application. * This way we don't have to redo our main bootstrap file every time we have some tweaks to add for * a specific application. */ if(file_exists($base_path.DIRECTORY_SEPARATOR.'application/bootstrap_cli.php')) { require_once($base_path.DIRECTORY_SEPARATOR.'application/bootstrap_cli.php'); } ?>