contaoblackforest/contao-doctrine-dbal
最新稳定版本:1.2.0
Composer 安装命令:
composer require contaoblackforest/contao-doctrine-dbal
包简介
Doctrine DBAL Bridge for Contao Open Source CMS
关键字:
README 文档
README
This extension provide Doctrine DBAL in the Contao Open Source CMS.
It only provide a service $container['doctrine.connection.default'] to connect the default database with Doctrine DBAL.
To use the Doctrine Connection within the Contao Database Framework, use bit3/contao-doctrine-dbal-driver.
Use the doctrine connection
class MyClass { public function myFunc() { global $container; /** @var \Doctrine\DBAL\Connection $connection */ $connection = $container['doctrine.connection.default']; $connection->query('...'); } }
Contao hooks
$GLOBALS['TL_HOOKS']['prepareDoctrineConnection'] = function(&$connectionParameters, &$config) { ... }
Called before the connection will be established.
$GLOBALS['TL_HOOKS']['doctrineConnect'] = function(&$connection) { ... }
Called after the connection is established.
Define a custom connection
We prefer to use the dependency injection container:
Write a system/config/services.php or system/modules/.../config/services.php:
$container['doctrine.connection.default'] = $container->share( function ($container) { $config = new \Doctrine\DBAL\Configuration(); $connectionParameters = array( 'dbname' => $GLOBALS['TL_CONFIG']['dbDatabase'], 'user' => $GLOBALS['TL_CONFIG']['dbUser'], 'password' => $GLOBALS['TL_CONFIG']['dbPass'], 'host' => $GLOBALS['TL_CONFIG']['dbHost'], 'port' => $GLOBALS['TL_CONFIG']['dbPort'], ); switch (strtolower($GLOBALS['TL_CONFIG']['dbDriver'])) { // reuse connection case 'doctrinemysql': return \Database::getInstance()->getConnection(); case 'mysql': case 'mysqli': $connectionParameters['driver'] = 'pdo_mysql'; $connectionParameters['charset'] = $GLOBALS['TL_CONFIG']['dbCharset']; if (!empty($GLOBALS['TL_CONFIG']['dbSocket'])) { $connectionParameters['unix_socket'] = $GLOBALS['TL_CONFIG']['dbSocket']; } break; default: throw new RuntimeException('Database driver ' . $GLOBALS['TL_CONFIG']['dbDriver'] . ' not known by doctrine.'); } if (!empty($GLOBALS['TL_CONFIG']['dbPdoDriverOptions'])) { $connectionParameters['driverOptions'] = deserialize($GLOBALS['TL_CONFIG']['dbPdoDriverOptions'], true); } return \Doctrine\DBAL\DriverManager::getConnection($connectionParameters, $config); } );
Configure caching
The caching implementation is defined in $container['doctrine.cache.impl.default'] (default: auto).
By default, the caching implementation is detected by default, try this implementations in order: APC, Xcache, memcache, Redis, Array.
Possible settings are:
| apc | use apc cache |
|---|---|
| xcache | use xcache cache |
| memcache://[:] | use memcache cache on : |
| redis://[:] | use redis cache on : |
| redis:// | use redis cache on file |
| array | use array cache |
The caching time to live is defined in $container['doctrine.cache.ttl.default'] (default: 0).
The caching key is defined in $container['doctrine.cache.key.default'] (default: contao_default_connection).
To disable caching, set $container['doctrine.cache.profile.default'] = null;.
统计信息
- 总下载量: 2.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-or-later
- 更新时间: 2015-05-28