Symfony:如何在 Doctrine DBAL 配置(YAML)中设置 SSL 参数? [英] Symfony : how to set SSL parameters in Doctrine DBAL configuration (YAML)?

查看:21
本文介绍了Symfony:如何在 Doctrine DBAL 配置(YAML)中设置 SSL 参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的 SSL 证书和密钥文件添加到 Doctrine DBAL 配置中,但我不知道如何实现.

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

在 PHP 中,我只需要编写类似的内容:

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'
    )
);

我知道有一个 自定义驱动程序选项 driverOptions,我看到了 这个答案 但我不确定如何将其翻译成 YAML.

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'

但是双冒号并不能真正取悦 YAML...

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

推荐答案

自从 Symfony 3.2 这变得容易多了:

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%

这篇关于Symfony:如何在 Doctrine DBAL 配置(YAML)中设置 SSL 参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆