Estava seguindo os passos do instrutor e acabei dando de cara com um erro informando que argumentos do construct não foram enviador
PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function Doctrine\ORM\EntityRepository::__construct(), 0 passed in /home/ramos/PhpstormProjects/Estudos/estudoDoctrine/commands/relatorio-aluno-repository.php on line 14 and exactly 2 expected in /home/ramos/PhpstormProjects/Estudos/estudoDoctrine/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php:72
Stack trace:
#0 /home/ramos/PhpstormProjects/Estudos/estudoDoctrine/commands/relatorio-aluno-repository.php(14): Doctrine\ORM\EntityRepository->__construct()
#1 {main}
thrown in /home/ramos/PhpstormProjects/Estudos/estudoDoctrine/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php on line 72
AlunoRepository:
<?php
namespace Ramos\estudoDoctrine\Repository;
use Doctrine\ORM\EntityRepository;
use Ramos\estudoDoctrine\Entity\Aluno;
class AlunoRepository extends EntityRepository
{
public function buscaCursosPorAluno()
{
$entityManager = $this->getEntityManager();
$classeAluno = Aluno::class;
$dql = "SELECT aluno, telefones, cursos FROM $classeAluno aluno JOIN aluno.telefones telefones JOIN aluno.cursos cursos";
$query = $entityManager->createQuery($dql);
return $query->getResult();
}
}
Arquivo de teste:
<?php
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Logging\DebugStack;
use Ramos\estudoDoctrine\Entity\Aluno;
use Ramos\estudoDoctrine\Entity\Telefone;
use Ramos\estudoDoctrine\Helper\EntityManagerFactory;
use Ramos\estudoDoctrine\Repository\AlunoRepository;
require_once __DIR__ . '/../vendor/autoload.php';
$debugStack = new DebugStack();
$entityManagerFactory = new EntityManagerFactory();
$repository = new AlunoRepository();
$entityManager = $entityManagerFactory->getEntityManager();
$entityManager->getConfiguration()->setSQLLogger($debugStack);
/*
*@var Aluno[] $alunos
*/
$alunos = $repository->buscaCursosPorAluno();
foreach ($alunos as $aluno){
$telefones = $aluno->getTelefones() ->map(function (Telefone $telefone){
return $telefone->getNumero();
}) -> toArray();
/**
* @return Collection
*/
$cursos = $aluno->getCurso();
echo "ID: {$aluno->getId()}\n";
echo "Nome: {$aluno->getNome()}\n";
echo "Telefones:" . implode(",", $telefones) . " \n";
foreach ($cursos as $curso){
echo "\tID: {$curso->getId()}\n";
echo "\tNome: {$curso->getNome()}\n";
echo "\t \n";
}
}
print_r($debugStack);