Estou tentando executar os primeiros passos, mas estou recebendo um erro que diz não encontrar umas das classes.
PHP Fatal error: Uncaught Error: Class 'Alura\Doctrine\Helper\EntityManagerFactory' not found in /home/ramos/PhpstormProjects/Estudos/estudoDoctrine/teste.php:7
Stack trace:
#0 {main}
thrown in /home/ramos/PhpstormProjects/Estudos/estudoDoctrine/teste.php on line 7
Quando executo o dump-autoload tudo acontece normal.
Esses são meus arquivos.
composer
{
"require": {
"doctrine/orm": "^2.6"
},
"autoload": {
"psr-4": {
"Alura\\Doctrine\\": "src/"
}
}
}
Classe localizada dentro da pasta helper, que fica dentro da pasta src
<?php
namespace Alura\Doctrine\Helper;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\Tools\Setup;
class EntityManagerFactory
{
/**
* @throws ORMException
*/
public function getEntityManager(): EntityManagerInterface
{
$rootDir = __DIR__ . '/../..';
$config = Setup::createAnnotationMetadataConfiguration([$rootDir . '/src'], true);
$connection = [
'driver' => 'pdo_sqlite',
'path' => $rootDir . '/var/data/banco.sqlite'
];
return EntityManager::create($connection, $config);
}
}
meu arquivo de teste
<?php
use Alura\Doctrine\Helper\EntityManagerFactory;
require_once __DIR__ . '/vendor/autoload.php';
$entityManagerFactory = new EntityManagerFactory();
$entityManager = $entityManagerFactory->getEntityManager();
var_dump($entityManager-> getConnection());