Skip to content

Instantly share code, notes, and snippets.

Created October 30, 2009 19:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save anonymous/222645 to your computer and use it in GitHub Desktop.
Save anonymous/222645 to your computer and use it in GitHub Desktop.
resources.Database.dsn = "mysql://root@localhost/treehousemb"
resources.Database.modelLoading = "conservative"
resources.Database.modelsPath = APPLICATION_PATH "/models"
resources.Database.cache.enabled = false
resources.Database.cache.servers.0.host = "localhost"
resources.Database.cache.servers.0.port = 11211
resources.Database.cache.servers.0.peristent = true
resources.Database.cache.queryCaching = false
resources.Database.cache.resultCaching = false
resources.Database.cache.defaultTTL = 360
require_once 'Zend/Application/Resource/ResourceAbstract.php';
/**
* TODO: short description.
*
* TODO: long description.
*
*/
class My_Resource_Database extends Zend_Application_Resource_ResourceAbstract
{
/**
* TODO: short description.
*
* @return TODO
*/
public function init()
{
$options = $this->getOptions();
require_once 'Doctrine.php';
require_once 'Doctrine/Manager.php';
$manager = Doctrine_Manager::getInstance();
$connection = $manager->connection( $options['dsn'] );
if( $options['modelLoading'] == "conservative" ) {
$manager->setAttribute(
Doctrine::ATTR_MODEL_LOADING,
Doctrine::MODEL_LOADING_CONSERVATIVE
);
}
$manager->setAttribute('use_native_enum', true);
$manager->setAttribute( Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true );
Doctrine::loadModels( $options['modelsPath'] );
//------------------------------------------------------
// Doctrine Caching
//------------------------------------------------------
if( $options['cache']['enabled'] ) {
require_once 'Doctrine/Cache/Memcache.php';
$cacheDriver = new Doctrine_Cache_Memcache(array(
'servers' => $options['cache']['servers'],
'compression' => false
));
if ( $options['cache']['queryCaching'] ) {
$manager->setAttribute( Doctrine::ATTR_QUERY_CACHE, $cacheDriver );
}
if ( $options['cache']['resultCaching'] ) {
$manager->setAttribute( Doctrine::ATTR_RESULT_CACHE, $cacheDriver );
}
$manager->setAttribute(
Doctrine::ATTR_RESULT_CACHE_LIFESPAN,
$option['cache']['defaultTTL']
);
}
return $connection;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment