/**
  * Initialize a sfDoctrineDatabase connection with the given parameters.
  *
  * <code>
  * $parameters = array(
  *    'name'       => 'doctrine',
  *    'dsn'        => 'sqlite:////path/to/sqlite/db');
  *
  * $p = new sfDoctrineDatabase($parameters);
  * </code>
  *
  * @param array $parameters  Array of parameters used to initialize the database connection
  * @return void
  */
 public function initialize($parameters = array())
 {
     parent::initialize($parameters);
     $dsn = $this->getParameter('dsn');
     $name = $this->getParameter('name');
     // Make sure we pass non-PEAR style DSNs as an array
     if (!strpos($dsn, '://')) {
         $dsn = array($dsn, $this->getParameter('username'), $this->getParameter('password'));
     }
     // Make the Doctrine connection for $dsn and $name
     $this->_doctrineConnection = Doctrine_Manager::connection($dsn, $name);
     $attributes = $this->getParameter('attributes', array());
     foreach ($attributes as $name => $value) {
         $this->_doctrineConnection->setAttribute($name, $value);
     }
     $encoding = $this->getParameter('encoding', 'UTF8');
     $eventListener = new sfDoctrineConnectionListener($this->_doctrineConnection, $encoding);
     $this->_doctrineConnection->addListener($eventListener);
     // Load Query Logger Listener
     if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
         $this->_doctrineConnection->addListener(new sfDoctrineLogger());
     }
     // Invoke the configuration methods for the connection if they exist
     $configuration = sfProjectConfiguration::getActive();
     $method = sprintf('configureDoctrineConnection%s', ucwords($this->_doctrineConnection->getName()));
     if (method_exists($configuration, 'configureDoctrineConnection') && !method_exists($configuration, $method)) {
         $configuration->configureDoctrineConnection($this->_doctrineConnection);
     }
     if (method_exists($configuration, $method)) {
         $configuration->{$method}($this->_doctrineConnection);
     }
 }
 public function initialize($parameters = array(), $name = null)
 {
     parent::initialize($parameters);
     // if a default connection is defined we only open that one
     if ($defaultDatabase = sfConfig::get('sf_default_database')) {
         if ($name != $defaultDatabase) {
             return;
         }
     }
     // load doctrine config
     require sfConfigCache::getInstance()->checkConfig('config/doctrine.yml');
     $db_attributes = $default_attributes;
     if (isset($attributes[$name])) {
         $db_attributes = array_merge($default_attributes, $attributes[$name]);
     }
     $this->setParameter('attributes', $db_attributes);
     $this->setParameter('name', $name);
     // take care of the component binding
     // suppress errors from include_once
     // because config/schemas.yml is optional.
     @(include_once sfConfigCache::getInstance()->checkConfig('config/schemas.yml', true));
     // opening the doctrine connection
     // determine how to get our parameters
     $method = $this->getParameter('method', 'dsn');
     // get parameters
     switch ($method) {
         case 'dsn':
             $dsn = $this->getParameter('dsn');
             if ($dsn == null) {
                 // missing required dsn parameter
                 $error = 'Database configuration specifies method "dsn", but is missing dsn parameter';
                 throw new sfDatabaseException($error);
             }
             break;
     }
     try {
         // Make sure we pass non-PEAR style DSNs as an array
         if (!strpos($dsn, '://')) {
             $dsn = array($dsn, $this->getParameter('username'), $this->getParameter('password'));
         }
         $this->doctrineConnection = Doctrine_Manager::connection($dsn, $name);
         // figure out the encoding
         $encoding = $this->getParameter('encoding', 'UTF8');
         // set up the connection parameters from the doctrine.yml config file
         foreach ($this->getParameter('attributes') as $k => $v) {
             $this->doctrineConnection->setAttribute(constant('Doctrine::' . $k), $v);
         }
         // we add the listener that sets up encoding and date formats
         $eventListener = new sfDoctrineConnectionListener($this->doctrineConnection, $encoding);
         $this->doctrineConnection->addListener($eventListener);
         // add the query logger
         if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
             $this->doctrineConnection->addListener(new sfDoctrineQueryLogger());
         }
     } catch (PDOException $e) {
         throw new sfDatabaseException($e->getMessage());
     }
 }
 public function initialize($parameters = array())
 {
     parent::initialize($parameters);
     $factoryParam = $this->getParameter('factory');
     $factoryClass = $factoryParam['class'] . 'Factory';
     $factory = new $factoryClass();
     $params = $factoryParam['param'];
     $this->delegate = $factory->createDatabase($params);
 }
 public function initialize($parameters = array())
 {
     parent::initialize($parameters);
     $schema = $this->getParameter('schema');
     $connectionName = $this->getParameter('name');
     $connectionOptions = $this->getParameter('options');
     $plugins = (array) $this->getParameter('plugins');
     $config = new \Doctrine\ORM\Configuration();
     $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     $configuration = sfProjectConfiguration::getActive();
     $paths = array();
     if ($schema) {
         $paths[] = $schema;
     }
     $paths[] = realpath(__DIR__ . '/../config/doctrine');
     $paths[] = realpath(sfConfig::get('sf_config_dir') . '/doctrine');
     $enabledPlugins = $configuration->getPlugins();
     foreach ($configuration->getAllPluginPaths() as $plugin => $path) {
         if (!in_array($plugin, $enabledPlugins) || !in_array($plugin, $plugins)) {
             continue;
         }
         $paths[] = $path . '/config/doctrine';
     }
     $paths = array_unique($paths);
     $config->setMetadataDriverImpl(new YamlDriver($paths));
     $config->setProxyDir(sfConfig::get('sf_lib_dir') . '/Proxies');
     $config->setProxyNamespace('Proxies');
     $configuration = sfProjectConfiguration::getActive();
     if (sfConfig::get('sf_debug')) {
         $config->setSqlLogger(new sfDoctrineSqlLogger($configuration->getEventDispatcher()));
     }
     $method = sprintf('configureDoctrineConnection%s', $connectionName);
     $methodExists = method_exists($configuration, $method);
     if (method_exists($configuration, 'configureDoctrineConnection') && !$methodExists) {
         $configuration->configureDoctrineConnection($config);
     } else {
         if ($methodExists) {
             $configuration->{$method}($config);
         }
     }
     $this->em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
     if (method_exists($configuration, 'configureEntityManager')) {
         $configuration->configureEntityManager($this->em);
     }
     ActiveEntity::setEntityManager($this->em);
     // ODM MongoDB
     $config = new Doctrine\ODM\MongoDB\Configuration();
     $config->setProxyDir(sfConfig::get('sf_lib_dir') . '/Proxies');
     $config->setProxyNamespace('Proxies');
     $reader = new Doctrine\Common\Annotations\AnnotationReader();
     $reader->setDefaultAnnotationNamespace('Doctrine\\ODM\\MongoDB\\Mapping\\');
     $config->setMetadataDriverImpl(new Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver($reader, sfConfig::get('sf_lib_dir') . DIRECTORY_SEPARATOR . 'Documents'));
     $this->dm = Doctrine\ODM\MongoDB\DocumentManager::create(new \Doctrine\ODM\MongoDB\Mongo(), $config);
 }
 /**
  * Initialize a sfDoctrineDatabase connection with the given parameters.
  *
  * <code>
  * $parameters = array(
  *    'name'       => 'doctrine',
  *    'dsn'        => 'sqlite:////path/to/sqlite/db');
  *
  * $p = new sfDoctrineDatabase($parameters);
  * </code>
  *
  * @param array $parameters  Array of parameters used to initialize the database connection
  * @return void
  */
 public function initialize($parameters = array())
 {
     parent::initialize($parameters);
     if (null !== $this->_doctrineConnection) {
         return;
     }
     $dsn = $this->getParameter('dsn');
     $name = $this->getParameter('name');
     // Make sure we pass non-PEAR style DSNs as an array
     if (!strpos($dsn, '://')) {
         $dsn = array($dsn, $this->getParameter('username'), $this->getParameter('password'));
     }
     // Make the Doctrine connection for $dsn and $name
     $configuration = sfProjectConfiguration::getActive();
     $dispatcher = $configuration->getEventDispatcher();
     $manager = Doctrine_Manager::getInstance();
     $this->_doctrineConnection = $manager->openConnection($dsn, $name);
     $attributes = $this->getParameter('attributes', array());
     foreach ($attributes as $name => $value) {
         if (is_string($name)) {
             $stringName = $name;
             $name = constant('Doctrine_Core::ATTR_' . strtoupper($name));
         }
         if (is_string($value)) {
             $valueConstantName = 'Doctrine_Core::' . strtoupper($stringName) . '_' . strtoupper($value);
             $value = defined($valueConstantName) ? constant($valueConstantName) : $value;
         }
         $this->_doctrineConnection->setAttribute($name, $value);
     }
     $encoding = $this->getParameter('encoding', 'UTF8');
     $eventListener = new sfDoctrineConnectionListener($this->_doctrineConnection, $encoding);
     $this->_doctrineConnection->addListener($eventListener);
     // Load Query Profiler
     if ($this->getParameter('profiler', sfConfig::get('sf_debug'))) {
         $this->profiler = new sfDoctrineConnectionProfiler($dispatcher, array('logging' => $this->getParameter('logging', sfConfig::get('sf_logging_enabled'))));
         $this->_doctrineConnection->addListener($this->profiler, 'symfony_profiler');
     }
     // Invoke the configuration methods for the connection if they exist (deprecated in favor of the "doctrine.configure_connection" event)
     $method = sprintf('configureDoctrineConnection%s', ucwords($this->_doctrineConnection->getName()));
     if (method_exists($configuration, 'configureDoctrineConnection') && !method_exists($configuration, $method)) {
         $configuration->configureDoctrineConnection($this->_doctrineConnection);
     }
     if (method_exists($configuration, $method)) {
         $configuration->{$method}($this->_doctrineConnection);
     }
     $dispatcher->notify(new sfEvent($manager, 'doctrine.configure_connection', array('connection' => $this->_doctrineConnection, 'database' => $this)));
 }
 /**
  * @see sfDatabase
  */
 public function initialize($parameters = array())
 {
     parent::initialize($parameters);
     // server
     if (!$this->hasParameter('server')) {
         throw new RuntimeException(sprintf('Connection "%s" without server".', $this->getParameter('name')));
     }
     $server = $this->getParameter('server');
     // database
     if (!$this->hasParameter('database')) {
         throw new RuntimeException(sprintf('Connection "%s" without database.', $this->getParameter('name')));
     }
     $database = $this->getParameter('database');
     // options
     $options = array();
     if ($this->hasParameter('persist')) {
         $options['persist'] = $this->getParameter('persist');
     }
     $this->mondongoConnection = new Mondongo\Connection($server, $database, $options);
 }
 /**
  * initialize
  *
  * @param array $parameters
  * @return void
  */
 public function initialize($parameters = array())
 {
     if (!$parameters) {
         return;
     }
     parent::initialize($parameters);
     // Load default database connection to load if specified
     if ($defaultDatabase = sfConfig::get('sf_default_database')) {
         if ($parameters['name'] != $defaultDatabase) {
             return;
         }
     }
     // Load the doctrine configuration
     require sfProjectConfiguration::getActive()->getConfigCache()->checkConfig('config/doctrine.yml');
     // Load config in to parameter
     $this->setParameter('config', $config);
     // Load schemas information for connection binding
     if ($schemas = sfProjectConfiguration::getActive()->getConfigCache()->checkConfig('config/schemas.yml', true)) {
         require_once $schemas;
     }
     $this->loadConnections();
     $this->loadAttributes($parameters['name']);
     $this->loadListeners();
 }