How to have doctrine dbal in symfony?

For some reasons I don’t want my users to edit /app/config/config.php to add the database credentials, but in a separate file they add them as an array and my /app/config/config.php is php, not yaml nor xml, so how can I tell /app/config/config.php to get database credentials as an array from another file?

I did look at an application that works like that and I see they use:

$container->loadFromExtension('doctrine', array(
 'orm' => array(
  'auto_generate_proxy_classes' => false,
  'default_entity_manager' => 'default',
  'entity_managers' => array(
   'default' => array('mappings' => array('MyApp' => array('type' => 'staticphp')), 'class_metadata_factory_name' => 'Doctrine\\ORM\\Mapping\\StaticClassMetadataFactory')
  )
 ),
 'dbal' => array(
  'default_connection' => 'default',
  'connections' => array(
   'default' => array('host' => 'from_user_config.db', 'logging' => true),
   'read' => array('host' => 'from_user_config.db_read', 'logging' => true)
  )
 )
));

Since it is not documentated, I appreciate if you clarify how can I do this the way I described?

'dbal' => require 'separate_file_with_credentials_as_array.php'

That file will need to return the array. I know a lot of people don’t realize that about PHP - you can issue a return statement in an include outside the body of a function. If you do the parsing of that include halts at the return and the value becomes the return of the require statement.

Thanks but in my doctrine bootstrap I still have:

$config = new Configuration;
$config->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');    
$config->setSQLLogger(new Doctrine\DBAL\Logging\EchoSQLLogger());
$evm = new EventManager;
$evm->addEventListener(Events::loadClassMetadata, new DoctrineExtensions\TablePrefix($db_prefix));
$em = EntityManager::create($dbParams, $config, $evm);
$platform = $em->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
$platform->registerDoctrineTypeMapping('set', 'string');

I guess this should be possible to tell /app/config/config.php about this bootstrap by implementing:
class ConnectionFactory extends \Symfony\Bundle\DoctrineBundle\ConnectionFactory implements ContainerAwareInterface
{

right? but then how should I tell config.php to care about this file? I guess another possibility is get dbal container from a kernel or controller class and add these configs into it? but nothing is documented. please advice how can I do this all?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.