68publishers/doctrine-bridge

Bridges between integrations of Doctrine ORM and '68publishers bundles.

v0.1.1 2020-12-10 04:16 UTC

This package is auto-updated.

Last update: 2021-11-10 06:11:46 UTC


README

Build Status Quality Score Coverage Status Total Downloads Latest Version on Packagist

A package contains bridges for the most used integrations of doctrine/orm into Nette Framework:

Bridges for this integrations will be implemented in the future:

  • Kdyby (missing support for Nette 3)

Why? Because we want to keep our bundles independent from specific integrations so applications can use any of the integrations mentioned above and will be still compatible with our bundles.

Installation

The best way to install 68publishers/doctrine-bridge is using Composer:

$ composer require 68publishers/doctrine-bridge

Configuration

extensions:
    # if you are using Nettrine:
    doctrine_bridge: SixtyEightPublishers\DoctrineBridge\Bridge\Nettrine\DI\DoctrineBridgeExtension

Usage

Database Type Provider

<?php

use Nette\DI\CompilerExtension;
use SixtyEightPublishers\DoctrineBridge\DI\DatabaseType;
use SixtyEightPublishers\DoctrineBridge\DI\DatabaseTypeProviderInterface;
use Ramsey\Uuid\Doctrine\UuidBinaryOrderedTimeType;

class FooExtension extends CompilerExtension implements DatabaseTypeProviderInterface
{
    public function getDatabaseTypes() : array
    {
        return [
            new DatabaseType('uuid_binary_ordered_time', Ramsey\Uuid\Doctrine\UuidBinaryOrderedTimeType::class, 'binary'),
            new DatabaseType('my_custom_type', MyCustomType::class),
        ];
    }
}

Services in Doctrine Types

Doctrine DBAL types don't have access to services by default. With this extension, you can receive DI Container in your custom types when the Connection is created.

<?php

use Nette\DI\Container;
use Doctrine\DBAL\Types\StringType;
use SixtyEightPublishers\DoctrineBridge\Type\ContainerAwareTypeInterface;

final class CustomType extends StringType implements ContainerAwareTypeInterface
{
    private $service;

    public function setContainer(Container $container) : void
    {
        $this->service = $container->getByType(MyService::class);
    }
}

Entity Mapping Provider

<?php

use Nette\DI\CompilerExtension;
use SixtyEightPublishers\DoctrineBridge\DI\EntityMapping;
use SixtyEightPublishers\DoctrineBridge\DI\EntityMappingProviderInterface;

class FooExtension extends CompilerExtension implements EntityMappingProviderInterface
{
    public function getEntityMappings() : array
    {
        return [
            new EntityMapping(EntityMapping::DRIVER_ANNOTATIONS, 'App\\Entity', __DIR__ . '/../Entity'),
            new EntityMapping(EntityMapping::DRIVER_YAML, 'App\\Entity', __DIR__ . '/../Entity/yaml'),
            new EntityMapping(EntityMapping::DRIVER_ANNOTATIONS, 'App\\Entity', __DIR__ . '/../Entity/xml'),
        ];
    }
}

Target Entity Provider

<?php

use Nette\DI\CompilerExtension;
use SixtyEightPublishers\DoctrineBridge\DI\TargetEntity;
use SixtyEightPublishers\DoctrineBridge\DI\TargetEntityProviderInterface;

class FooExtension extends CompilerExtension implements TargetEntityProviderInterface
{
    public function getTargetEntities() : array
    {
        return [
            new TargetEntity(ProductInterface::class, ProductEntity::class),
        ];
    }
}

Contributing

Before committing any changes, don't forget to run

$ vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v --dry-run

and

$ composer run tests