2017 © Pedro Peláez
 

contao-module contao-doctrine-dbal

Doctrine DBAL Bridge for Contao Open Source CMS

image

contaoblackforest/contao-doctrine-dbal

Doctrine DBAL Bridge for Contao Open Source CMS

  • Wednesday, June 10, 2015
  • by baumannsven
  • Repository
  • 3 Watchers
  • 0 Stars
  • 2,100 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 3 Forks
  • 3 Open issues
  • 7 Versions
  • 4 % Grown

The README.md

Doctrine DBAL Bridge

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., (*1)

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., (*2)

$GLOBALS['TL_HOOKS']['doctrineConnect'] = function(&$connection) { ... } Called after the connection is established., (*3)

Define a custom connection

We prefer to use the dependency injection container: Write a system/config/services.php or system/modules/.../config/services.php:, (*4)

$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., (*5)

Possible settings are:, (*6)

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)., (*7)

The caching key is defined in $container['doctrine.cache.key.default'] (default: contao_default_connection)., (*8)

To disable caching, set $container['doctrine.cache.profile.default'] = null;., (*9)

The Versions

10/06 2015

dev-develop

dev-develop

Doctrine DBAL Bridge for Contao Open Source CMS

  Sources   Download

LGPL-3.0+

The Requires

 

doctrine dbal contao

30/07 2014

1.1.2

1.1.2.0

Doctrine DBAL Bridge for Contao Open Source CMS

  Sources   Download

LGPL-3.0+

The Requires

 

doctrine dbal contao

06/06 2014

1.1.1

1.1.1.0

Doctrine DBAL Bridge for Contao Open Source CMS

  Sources   Download

LGPL-3.0+

The Requires

 

doctrine dbal contao

28/04 2014

1.1

1.1.0.0

Doctrine DBAL Bridge for Contao Open Source CMS

  Sources   Download

LGPL-3.0+

The Requires

 

doctrine dbal contao