Search code examples
symfonypdodoctrine-ormyamldbal

Symfony : how to set SSL parameters in Doctrine DBAL configuration (YAML)?


I'd like to add my SSL cert and key files to Doctrine DBAL configuration but I don't see how to achieve that.

In PHP, I just have to write something like :

$databaseHandler = new \PDO(
    'mysql:host=my_host;dbname=my_db',
    'username',
    'password',
    array(
        \PDO::MYSQL_ATTR_SSL_KEY   => '.../client-key.pem',
        \PDO::MYSQL_ATTR_SSL_CERT  => '.../client-cert.pem',
        \PDO::MYSQL_ATTR_SSL_CA    => '.../ca-cert.pem'
    )
);

I understand there is a Custom Driver Option driverOptions, and I saw this answer but I'm not sure about how to translate that into YAML.

I have the feeling I should write something close to :

doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        driverOptions:
            PDO::MYSQL_ATTR_SSL_CA: '.../client-key.pem'
            PDO::MYSQL_ATTR_SSL_CERT: '.../client-cert.pem'
            PDO::MYSQL_ATTR_SSL_CA: '.../ca-cert.pem'

But double colons won't really please YAML...


Solution

  • Since Symfony 3.2 this became a lot easier:

    doctrine:
        dbal:
            <other configs>
            options:
                !php/const:PDO::MYSQL_ATTR_SSL_CA: %ca_cert%
                !php/const:PDO::MYSQL_ATTR_SSL_KEY: %private_key%
                !php/const:PDO::MYSQL_ATTR_SSL_CERT: %public_cert%