Latest release: v0.2.7

Nettrine / DBAL

Content

Installation

At first you have to setup extension.

extensions:
    dbal: Nettrine\DBAL\DI\DbalExtension
1
2

There are also some bridges as Symfony\Console. You'll known in next sections.

Configuration

Minimal configuration could looks like this.

dbal:
    debug: %debugMode%
    connection:
        host: localhost
        driver: mysqli
        dbname: nettrine
        user: root
        password: root
1
2
3
4
5
6
7
8

Full configuration options:

dbal:
    debug: %debugMode%
    configuration:
        sqlLogger: NULL
        resultCacheImpl: NULL
        filterSchemaAssetsExpression: NULL
        autoCommit: TRUE

    connection:
        url: NULL
        pdo: NULL
        memory: NULL
        driver: pdo_mysql
        driverClass: NULL
        host: NULL
        dbname: NULL
        servicename: NULL
        user: NULL
        password: NULL
        charset: UTF8
        portability: PortabilityConnection::PORTABILITY_ALL
        fetchCase: PDO::CASE_LOWER
        persistent: TRUE
        types: []
        typesMapping: []
        wrapperClass: NULL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

Types

Here is a example how to custom type. For more information, follow the official documention.

  • http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html
  • http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/custom-mapping-types.html
dbal:
    connection:
        types:
            uuid_binary_ordered_time:
                class: Ramsey\Uuid\Doctrine\UuidBinaryOrderedTimeType
                commented: falsee

        typesMapping:
            uuid_binary_ordered_time: binary
1
2
3
4
5
6
7
8
9

Events

You can use native Doctrine DBAL event system.

services:
    subscriber1:
      class: App\PostConnectSubscriber
      tags: [nettrine.subscriber]
1
2
3
4

Register and create your own subscribers. There're services, so constructor injection will works. There're also loaded lazily, don't worry about performance.

namespace App;

use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events;

final class PostConnectSubscriber implements EventSubscriber
{
	public function postConnect(ConnectionEventArgs $args): void
	{
		// Magic goes here...
	}

	public function getSubscribedEvents(): array
	{
		return [Events::postConnect];
	}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

Don't waste time to tag single service and tag them all together using decorator.

decorator:
    Doctrine\Common\EventSubscriber:
      tags: [nettrine.subscriber]
1
2
3

Bridges

Symfony\Console

This package works pretty well with Symfony/Console. Take a look at Contributte/Console tiny integration for Nette Framework.

extensions:
    # Console
    console: Contributte\Console\DI\ConsoleExtension

    # Dbal
    dbal: Nettrine\Dbal\DI\DbalExtension
    dbal.console: Nettrine\Dbal\DI\DbalConsoleExtension(%consoleMode%)
1
2
3
4
5
6
7

From this moment when you type bin/console, there'll be registered commands from Doctrine DBAL.

Commands