Aluno.php :
<?php
namespace Alura\ORM\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
/**
* @Entity
*/
class Aluno
{
/**
* @Id
* @GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string")
*/
private $nome;
public function getId(): int
{
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\ORM\Helper;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\Setup;
class EntityManagerFactory
{
/**
* @return EntityManagerInterface
*/
public function getEntityManager():EntityManagerInterface
{
$rootDir = __DIR__.'/..';
$config = Setup::createAnnotationMetadataConfiguration([$rootDir], true);
$connection = [
'driver' => 'pdo_sqlite', 'path' => $rootDir . '/var/data/banco.sqlite'
];
return EntityManager::create($connection, $config);
}
}