Download the PHP package tourze/doctrine-dedicated-connection-bundle without Composer
On this page you can find all versions of the php package tourze/doctrine-dedicated-connection-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download tourze/doctrine-dedicated-connection-bundle
More information about tourze/doctrine-dedicated-connection-bundle
Files in tourze/doctrine-dedicated-connection-bundle
Download tourze/doctrine-dedicated-connection-bundle
More information about tourze/doctrine-dedicated-connection-bundle
Files in tourze/doctrine-dedicated-connection-bundle
Vendor tourze
Package doctrine-dedicated-connection-bundle
Short Description Symfony Bundle for creating dedicated database connections per service, similar to Monolog channels
License MIT
Package doctrine-dedicated-connection-bundle
Short Description Symfony Bundle for creating dedicated database connections per service, similar to Monolog channels
License MIT
Please rate this library. Is it a good library?
Informations about the package doctrine-dedicated-connection-bundle
Doctrine Dedicated Connection Bundle
这个 Bundle 提供了一种简单的方式来为 Symfony 服务创建专用的数据库连接,类似于 MonologBundle 的 WithMonologChannel
功能。专注于连接管理,不涉及 EntityManager。
功能特性
- 🔌 自动创建专用数据库连接 - 通过注解自动创建独立的数据库连接
- 🏷️ 注解支持 - 使用
#[WithDedicatedConnection]
注解标记需要专用连接的服务 - 🔧 环境变量配置 - 支持通过环境变量覆盖每个连接的配置
- 🔄 连接池管理 - 自动管理和重置连接
- 🚫 零配置 - 无需 YAML 配置文件,全部通过注解和环境变量管理
安装
使用方法
使用注解方式
使用 WithDedicatedConnection
注解标记服务:
使用标签方式
环境变量配置
每个连接支持通过环境变量覆盖配置:
如果没有设置 {CHANNEL}_DB_NAME
,将使用默认数据库名称加上 _channel
后缀。
注解参数
WithDedicatedConnection
注解只有一个参数:
- channel (必需): 连接通道名称
所有的数据库配置都通过环境变量管理,确保配置的一致性和可维护性。
高级用法
在自定义 CompilerPass 中创建连接
如果你需要在自己的 CompilerPass 中创建专用连接,可以使用 DedicatedConnectionHelper
:
直接使用工厂服务
获取特定的连接
创建的服务遵循以下命名约定:
- 连接:
doctrine.dbal.{channel}_connection
最佳实践
- 使用有意义的通道名称:使用描述性的名称如
order
、analytics
、archive
等 - 按业务领域分离数据:每个微服务或业务领域使用独立的数据库
- 配置环境变量:在生产环境中使用环境变量配置敏感信息
- 连接重用:如果多个服务需要同一个专用连接,使用相同的 channel 名称
故障排除
连接无法建立
确保:
- 环境变量配置正确
- 数据库服务器可访问
- 清除缓存:
php bin/console cache:clear
许可证
MIT
All versions of doctrine-dedicated-connection-bundle with dependencies
PHP Build Version
Package Version
Requires
php Version
^8.1
doctrine/dbal Version ^4.0
doctrine/doctrine-bundle Version ^2.13
doctrine/orm Version ^3.0
doctrine/persistence Version ^3.1 || ^4
psr/log Version ^3|^2|^1
symfony/config Version ^6.4
symfony/dependency-injection Version ^6.4
symfony/doctrine-bridge Version ^6.4
symfony/framework-bundle Version ^6.4
symfony/http-kernel Version ^6.4
symfony/yaml Version ^6.4 || ^7.1
tourze/bundle-dependency Version 0.0.*
tourze/symfony-runtime-context-bundle Version 0.0.*
doctrine/dbal Version ^4.0
doctrine/doctrine-bundle Version ^2.13
doctrine/orm Version ^3.0
doctrine/persistence Version ^3.1 || ^4
psr/log Version ^3|^2|^1
symfony/config Version ^6.4
symfony/dependency-injection Version ^6.4
symfony/doctrine-bridge Version ^6.4
symfony/framework-bundle Version ^6.4
symfony/http-kernel Version ^6.4
symfony/yaml Version ^6.4 || ^7.1
tourze/bundle-dependency Version 0.0.*
tourze/symfony-runtime-context-bundle Version 0.0.*
The package tourze/doctrine-dedicated-connection-bundle contains the following files
Loading the files please wait ....