连接包装类中的symfony 4.2加载原则服务

时间:2019-04-13 09:57:23

标签: symfony containers symfony4

我是symfony的新手,并基于4.2创建了一些项目,因为我必须动态切换数据库,并且此版本中似乎存在一个错误,我按照一些说明设置了用于连接数据库的包装器类,因此可以正常工作精细。但是,iam努力在这里使用doctrince方法getConnections()进行工作,以便能够针对我的数据库配置再次检查发送的参数。我通过将学说初始化为服务容器等尝试的所有方法均不起作用。

希望有人能给我一个提示,也是我的第一篇文章,所以请不要恨(:

问候

doctrine:
    dbal:
        default_connection: db_name
        connections:
            my_connection:
                wrapper_class: App\Doctrine\DynamicConnection
                url: '%env(DATABASE_URL)%'
                driver: 'pdo_mysql'
                server_version: '5.7'
                charset: utf8mb4
services:
    # default configuration for services in *this* file
    _defaults:
        public: false
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

    App\Doctrine\:
        resource: '../src/Doctrine'
        tags: ['doctrine.service_arguments']

    doctrine.entity_manager:
        public: true
        class: App\Doctrine\DynamicConnection
        arguments: [ '@doctrine.orm.entity_manager' ]
namespace App\Doctrine;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerBuilder;


class DynamicConnection extends Connection
{

    public function __construct(array $params = array(), Driver $driver = null, $config = null, $eventManager = null)
    {
        #$request = Request::createFromGlobals();
        #$dbname = $request->query->get('db_name');

        $containerBuilder = new ContainerBuilder();

        var_dump($containerBuilder->getServiceIds());

        $doctrine = $containerBuilder->get('doctrine.entity_manager');

0 个答案:

没有答案