Integrating Doctrine with Laminas

Is there a typical site that integrates Laminas and Doctrine?
Currently I have an application that works with ZF3 and doctrine and I would like to upgrade it to Laminas.

Hello and welcome to our forums! :smiley:

You can use psr-container-doctrine which provides ready-to-use factories and examples for integration in a laminas-mvc based application, Mezzio and other applications with PSR-11 container support.

Another option is the doctrine-module and the doctrine-orm-module:

Hi @froschdesign,

Can you list the command to use migrations? The below command is not working.

./vendor/bin/doctrine 

Below is the code for cli-config.php

<?php

use Laminas\ServiceManager\ServiceManager;
use Roave\PsrContainerDoctrine\EntityManagerFactory;

// Standard config keys
$container = new ServiceManager([
    'factories' => [
        'doctrine.entity_manager.orm_default' => EntityManagerFactory::class,
    ],
]);


return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet(
    $container->get('doctrine.entity_manager.orm_default')
);

In doctrine.global.php

return [
    //...
    'dependencies' => [
        'factories' => [
            'doctrine.entity_manager.orm_default' => \Roave\PsrContainerDoctrine\EntityManagerFactory::class,
            Command\CurrentCommand::class => CommandFactory::class,
            Command\DiffCommand::class => CommandFactory::class,
            Command\DumpSchemaCommand::class => CommandFactory::class,
            Command\ExecuteCommand::class => CommandFactory::class,
            Command\GenerateCommand::class => CommandFactory::class,
            Command\LatestCommand::class => CommandFactory::class,
            Command\ListCommand::class => CommandFactory::class,
            Command\MigrateCommand::class => CommandFactory::class,
            Command\RollupCommand::class => CommandFactory::class,
            Command\SyncMetadataCommand::class => CommandFactory::class,
            Command\StatusCommand::class => CommandFactory::class,
            Command\UpToDateCommand::class => CommandFactory::class,
            Command\VersionCommand::class => CommandFactory::class,
            
            DependencyFactory::class => DependencyFactoryFactory::class,
            // Below class doesn't exists
//             ConfigurationLoader::class => ConfigurationLoaderFactory::class,
        ],
    ],
];

Thanks!

For me, migration worked by downloading doctrine migration for PHP 7.4 and adding the configuration below. Also, change the execution file.

./vendor/bin/doctrine-module
[
    'doctrine' => [
        ...
        'eventmanager' => [
            'orm_default' => [
                'subscribers' => [
                    // pick any listeners you need
                ],
            ],
        ],
        'migrations_configuration' => [
            'orm_default' => [
                'table_storage' => [
                    'table_name' => 'migrations_executed',
                    'version_column_name' => 'version',
                    'version_column_length' => 255,
                    'executed_at_column_name' => 'executed_at',
                    'execution_time_column_name' => 'execution_time',
                ],
                'migrations_paths' => ['My\Migrations' => getcwd() .  '/scripts/orm/migrations'],
            ],
        ],
    ],
]

Last but not least getting the doctrine entity manager via factory class.

class MyFactory extends \Laminas\ServiceManager\Factory\FactoryInterface {
  public function __invoke($container, $requestedName, array $options = null){
    return new SomeController($container->get('doctrine.entitymanager.orm_default'));
  }
}

Thanks!