0
respostas

Doctrine ORM 3.x mudou a forma de criar o EntityManager

As perguntas feitas anteriormente são porque agora estamos em Dorctrine ORM 3.x e o curso (ao menos nessa aula) está em Doctrine ORM 2.x

Na prática o que muda No Doctrine ORM 2.x: EntityManager::create($conn, $config) para No Doctrine ORM 3.x: new EntityManager($conn, $config)

No arquivo EntityManagerCreator.php fica assim

<?php

namespace Alura\Doctrine\Helper;

use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\EntityManager;
use Doctrine\DBAL\DriverManager;

require_once "vendor/autoload.php";

class EntityManagerCreator 
{
    public static function createEntityManager()
    {
        // Create a simple "default" Doctrine ORM configuration for Attributes
        $config = ORMSetup::createAttributeMetadataConfiguration(
            paths: [__DIR__ . '/../Entity'],
            isDevMode: true,
        );
        // configuring the database connection
        $connection = DriverManager::getConnection([
            'driver' => 'pdo_sqlite',
            'path' => __DIR__ . '/../../db.sqlite',
        ], $config);

        return new EntityManager($connection, $config);
        
    }
}