doctrine_alura>vendor\bin\doctrine.bat orm:info
In MappingException.php line 50:
File mapping drivers must have a valid directory path, however the given path [C:\Users\jeiso\OneDrive\De
sktop\doctrine_alura\src\Helper/../src] seems to be incorrect!
orm:info [--em EM]
Aluno.php
<?php
namespace Alura\Doctrine\Entity;
/**
* @Entity
*/
class Aluno
{
/**
* @Id
* @GeneratedValue
* @Column(type="integer")
*/
private $id;
/**
* @Column(type="string")
*/
private $nome;
public function getId()
{
return $this->id;
}
public function getNome():string
{
return $this->nome;
}
public function setNome(string $nome) :self
{
$this->nome = $nome;
return $this;
}
}
EntityManagerFactory.php
<?php
namespace Alura\Doctrine\Helper;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\Setup;
class EntityManagerFactory
{
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);
}
}
cli-config.php
<?php
use Alura\Doctrine\Helper\EntityManagerFactory;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
require_once __DIR__ . '/vendor/autoload.php';
$entityManagerFactory = new EntityManagerFactory();
$entityManager = $entityManagerFactory->GetEntityManager();
return ConsoleRunner::createHelperSet($entityManager);
Teste.php
<?php
use Alura\Doctrine\Helper\EntityManagerFactory;
require_once __DIR__ . '/vendor/autoload.php';
$entityManagerFactory = new EntityManagerFactory();
$entityManager = $entityManagerFactory-> getEntityManager();
var_dump($entityManager->getConnection());
composer.json
{
"require": {
"doctrine/orm": "^2.9"
},
"autoload": {
"psr-4": {
"Alura\\Doctrine\\": "src/"
}
}
}