PDO 会话配置中未定义 parameters.php 中定义的 Symfony 3.2 参数

Symfony 3.2 parameter defined into parameters.php is not defined in PDO session configuration

我正在使用 symfony 3.2,我想要一个动态数据库连接,所以我要在我的 config.yml 文件中导入一个文件 parameters.php :

imports:
    - { resource: parameters.php }
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }

在 parameters.php 中我定义 database_name :

$container->setParameter('database_name', $dbName);

这适用于本机文件会话,但是当我按照 symfony 示例使用 pdo 会话时:

services:
    session.handler.pdo:
        class:     Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
        public:    false
        arguments:
           - 'mysql:host=%database_host%;port=%database_port%;dbname=%database_name%'
           - { db_username: '%database_user%', db_password: '%database_password%' }

我在编译时遇到错误:

 [Symfony\Component\DependencyInjection\Exception\RuntimeException]
  A string value must be composed of strings and/or numbers, but found parameter "database_name" of type boolean inside string value "mysql:host=%database_host%;port=%database_port%;dbname=%database_name%".

好像 symfony 不知道参数 "database_name"。

谁能帮帮我?

好吧,这好像不是办法... 最后我创建了一个 Custom ConnectionFactory

use Doctrine\Bundle\DoctrineBundle\ConnectionFactory;

class MyConnectionFactory extends ConnectionFactory {

    public function createConnection(array $params, \Doctrine\DBAL\Configuration $config = null, \Doctrine\Common\EventManager $eventManager = null, array $mappingTypes = array()) {



      // Determine here params ....

        $params['dbname'] = $dbName;
        $params['host'] = $dbHost
        $params['user'] = $dbUser
        $params['password'] = $dbCode;

        return parent::createConnection($params, $config, $eventManager, $mappingTypes);
    }

成功了!