Symfony 5 pb with Repository

  repository, symfony

I have the following error:
DefinitionErrorExceptionPass.php line 54:
Cannot autowire service “AppRepositoryEmployeeRepository”: argument “$entityClass” of method “DoctrineBundleDoctrineBundleRepositoryServiceEntityRepository::__construct()” has no type-hint, you should configure its value
explicitly.

My classes:

<?php
namespace AppEntity;

use DoctrineORMMapping as ORM;

/**
 * @ORMEntity(repositoryClass="AppRepositoryEmployeeRepository")
 */
class Employee extends User
{

}

<?php

namespace AppController;


use AppEntityEmployee;
use AppEntityEmployeeBoss;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingAnnotationRoute;

class EmployeeController extends AbstractController
{
    /**
     * @return Response
     * @Route('/employees')
     */
    public function getEmployees(): Response
    {
        $employees = $this->getDoctrine()->getRepository(Employee::class)->findAll();

        if(!$employees){
            return new Response(null);
        }

        $formatted = [];
        foreach ($employees as $employee){
            $formatted[] = $this->getDoctrine()->getRepository(Employee::class)->getDetails($employee);
        }

        return new Response($formatted);
    }

<?php

namespace AppRepository;

use AppEntityEmployee;
use DoctrineBundleDoctrineBundleRepositoryServiceEntityRepository;

class EmployeeRepository extends ServiceEntityRepository
{
    public function getDetails(Employee $employee)
    {
        return [
            'id'        => $employee->getId(),
            'firstname' => $employee->getFirstname(),
            'lastname'  => $employee->getLastname(),
            'email'     => $employee->getEmail(),
            'password'  => $employee->getPassword(),
            'startDate' => $employee->getStartDate(),
            'endDate'   => $employee->getEndDate(),
        ];
    }
}

<?php
namespace AppEntity;

use DoctrineORMMappingMappedSuperclass;
use DoctrineORMMapping as ORM;
use DateTime;

/**
 * @MappedSuperclass
 */
class User
{
    /**
     * @ORMId()
     * @ORMColumn(type="integer")
     * @ORMGeneratedValue()
     */
    private $id;

    /**
     * @ORMColumn(type="string")
     */
    private $firstname;

    /**
     * @ORMColumn(type="string")
     */
    private $lastname;

    /**
     * @ORMColumn(type="string")
     */
    private $email;

    /**
     * @ORMColumn(type="string")
     */
    private $password;

    /**
     * @ORMColumn(type="datetime")
     */
    private $startDate;

    /**
     * @ORMColumn(type="datetime", nullable=true)
     */
    private $endDate;

    /**
     * @param int $id
     */
    public function setId(int $id)
    {
        $this->id = $id;
    }

    /**
     * @return int
     */
    public function getId(): int
    {
        return $this->id;
    }

    /**
     * @param string $email
     */
    public function setEmail(string $email)
    {
        $this->email = $email;
    }

    /**
     * @return string
     */
    public function getPassword(): string
    {
        return $this->password;
    }

    /**
     * @return string
     */
    public function getEmail(): string
    {
        return $this->email;
    }

    /**
     * @return string
     */
    public function getLastname():string
    {
        return $this->lastname;
    }

    /**
     * @return string
     */
    public function getFirstname(): string
    {
        return $this->firstname;
    }

    /**
     * @param string $password
     */
    public function setPassword(string $password)
    {
        $this->password = $password;
    }

    /**
     * @param string $lastname
     */
    public function setLastname(string $lastname)
    {
        $this->lastname = $lastname;
    }

    /**
     * @param string $firstname
     */
    public function setFirstname(string $firstname)
    {
        $this->firstname = $firstname;
    }

    /**
     * @return DateTime
     */
    public function getEndDate(): ?DateTime
    {
        return $this->endDate;
    }

    /**
     * @return DateTime
     */
    public function getStartDate(): DateTime
    {
        return $this->startDate;
    }

    /**
     * @param DateTime $endDate
     */
    public function setEndDate(?DateTime $endDate)
    {
        $this->endDate = $endDate;
    }

    /**
     * @param DateTime $startDate
     */
    public function setStartDate(DateTime $startDate)
    {
        $this->startDate = $startDate;
    }
}

Source: Symfony Questions

LEAVE A COMMENT