Skip to content

Latest commit

 

History

History
151 lines (116 loc) · 3.4 KB

README.md

File metadata and controls

151 lines (116 loc) · 3.4 KB

Nettrine / DBAL

Content

Installation

At first you have to setup extension.

extensions:
    dbal: Nettrine\Dbal\DI\DbalExtension

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

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

Types

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

dbal:
    connection:
        types:
            uuid_binary_ordered_time:
                class: Ramsey\Uuid\Doctrine\UuidBinaryOrderedTimeType
                commented: falsee

        typesMapping:
            uuid_binary_ordered_time: binary

Events

You can use native Doctrine DBAL event system.

services:
    subscriber1:
      class: App\PostConnectSubscriber
      tags: [nettrine.subscriber]

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];
	}

}

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

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

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%)

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

Commands