PHP code example of 68publishers / doctrine-bridge

1. Go to this page and download the library: Download 68publishers/doctrine-bridge library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

68publishers / doctrine-bridge example snippets


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

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

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

final class MyExtension extends StringType implements ContainerAwareTypeInterface
{
    private MyService $service;

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

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

class MyExtension extends CompilerExtension implements EntityMappingProviderInterface
{
    public function getEntityMappings() : array
    {
        return [
            new EntityMapping(EntityMapping::DRIVER_ANNOTATION, 'App\\Entity', __DIR__ . '/../Entity'),
            new EntityMapping(EntityMapping::DRIVER_ATTRIBUTE, 'App\\Entity', __DIR__ . '/../Entity'),
            new EntityMapping(EntityMapping::DRIVER_XML, 'App\\Entity', __DIR__ . '/../Mapping/xml'),
            # or
            new EntityMapping(EntityMapping::DRIVER_SIMPLIFIED_XML, 'App\\Entity', __DIR__ . '/../Mapping/xml'),
        ];
    }
}

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

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

use Nette\DI\CompilerExtension;
use SixtyEightPublishers\DoctrineBridge\Bridge\Nette\DI\TargetEntity;
use SixtyEightPublishers\DoctrineBridge\Bridge\Nette\DI\MigrationsDirectoriesProviderInterface;

class MyExtension extends CompilerExtension implements MigrationsDirectoriesProviderInterface
{
    public function getMigrationsDirectories() : array
    {
        return [
            new MigrationsDirectory('App\\Bundle\\MyBundle\\Migrations', __DIR__ . '/../Migrations'),
        ];
    }
}