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

后端 未结 6 1865
误落风尘
误落风尘 2021-02-09 10:56

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 :

<         


        
6条回答
  •  清酒与你
    2021-02-09 11:13

    Symfony configuration via yaml (and possibly xml), doesn't allow the keys to be dynamically set, which means you can't use the constants. To get around this, you can create an extra PHP config file that just handles making a key out of the constants.

    The solution in a Gist is here: https://gist.github.com/samsch/d5243de3924a8ad10df2

    The two major features that this utilizes are that a PHP config file can use any string value for the key, including variables, constants; and that you can use parameters as values for other parameters (something I didn't know until I tried it recently.)

    So, you add the PHP config file in config.yml:

    imports:
        - { resource: parameters.yml }
        - { resource: pdo-constants.php }
    

    pdo-constants.php is this:

    setParameter("pdo_options", [
        PDO::MYSQL_ATTR_SSL_CA => "%pdo_ca_file%",
    ]);
    

    Add any other constants you need as well.

    Then in parameters.yml, you just need the values for your constants:

    parameters:
    #...
        pdo_ca_file: /pathtocerts/certs/mysql-ca.pem
    

    Now, I'm guessing that working with another DB system which uses PDO constants would be similar, but I've only used this MySQL.

提交回复
热议问题