2

I'm receiving error The Doctrine repository "Doctrine\ORM\EntityRepository" must implement Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface.

This is done mostly following symfony own login and databases and doctrine examples, thought with some customization.

Customer.php: `

// src/AppBundle/Entity/Customer.php

namespace AppBundle\Entity;

 use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Security\Core\User\UserInterface;
 use Symfony\Component\Security\Core\User\AdvancedUserInterface;

  /**
   * @ORM\Entity(repositoryClass="AppBundle\Entity\CustomerRepository")
   */

 class Customer implements AdvancedUserInterface, \Serializable
 {

 /**
 * @var integer
 */
private $id;

/**
 * @var string
 */
private $customer_firstname;

/**
 * @var string
 */
private $customer_lastname;

/**
 * @var string
 */
private $customer_email;

/**
 * @var string
 */
private $customer_password;

/**
 * @var string
 */
private $customer_salt;

/**
 * @var string
 */
private $customer_notes;

/**
 * @var integer
 */
private $customer_server_id;

/**
 * @var string
 */
private $customer_panel_account;

/**
 * @var integer
 */
private $customer_invoicing_account;

/**
 * @var integer
 */
private $customer_is_active;


/**
 * Set id
 *
 * @param integer $id
 *
 * @return Customer
 */
public function setId($id)
{
    $this->id = $id;

    return $this;
}

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

/**
 * Set customerFirstname
 *
 * @param string $customerFirstname
 *
 * @return Customer
 */
public function setCustomerFirstname($customerFirstname)
{
    $this->customer_firstname = $customerFirstname;

    return $this;
}

/**
 * Get customerFirstname
 *
 * @return string
 */
public function getCustomerFirstname()
{
    return $this->customer_firstname;
}

/**
 * Set customerLastname
 *
 * @param string $customerLastname
 *
 * @return Customer
 */
public function setCustomerLastname($customerLastname)
{
    $this->customer_lastname = $customerLastname;

    return $this;
}

/**
 * Get customerLastname
 *
 * @return string
 */
public function getCustomerLastname()
{
    return $this->customer_lastname;
}

/**
 * Set customerEmail
 *
 * @param string $customerEmail
 *
 * @return Customer
 */
public function setCustomerEmail($customerEmail)
{
    $this->customer_email = $customerEmail;

    return $this;
}

/**
 * Get customerEmail
 *
 * @return string
 */
public function getCustomerEmail()
{
    return $this->customer_email;
}

/**
 * Set customerPassword
 *
 * @param string $customerPassword
 *
 * @return Customer
 */
public function setCustomerPassword($customerPassword)
{
    $this->customer_password = $customerPassword;

    return $this;
}

/**
 * Get customerPassword
 *
 * @return string
 */
public function getCustomerPassword()
{
    return $this->customer_password;
}

/**
 * Set customerSalt
 *
 * @param string $customerSalt
 *
 * @return Customer
 */
public function setCustomerSalt($customerSalt)
{
    $this->customer_salt = $customerSalt;

    return $this;
}

/**
 * Get customerSalt
 *
 * @return string
 */
public function getCustomerSalt()
{
    return $this->customer_salt;
}

/**
 * Set customerNotes
 *
 * @param string $customerNotes
 *
 * @return Customer
 */
public function setCustomerNotes($customerNotes)
{
    $this->customer_notes = $customerNotes;

    return $this;
}

/**
 * Get customerNotes
 *
 * @return string
 */
public function getCustomerNotes()
{
    return $this->customer_notes;
}

/**
 * Set customerServerId
 *
 * @param integer $customerServerId
 *
 * @return Customer
 */
public function setCustomerServerId($customerServerId)
{
    $this->customer_server_id = $customerServerId;

    return $this;
}

/**
 * Get customerServerId
 *
 * @return integer
 */
public function getCustomerServerId()
{
    return $this->customer_server_id;
}

/**
 * Set customerPanelAccount
 *
 * @param string $customerPanelAccount
 *
 * @return Customer
 */
public function setCustomerPanelAccount($customerPanelAccount)
{
    $this->customer_panel_account = $customerPanelAccount;

    return $this;
}

/**
 * Get customerPanelAccount
 *
 * @return string
 */
public function getCustomerPanelAccount()
{
    return $this->customer_panel_account;
}

/**
 * Set customerInvoicingAccount
 *
 * @param integer $customerInvoicingAccount
 *
 * @return Customer
 */
public function setCustomerInvoicingAccount($customerInvoicingAccount)
{
    $this->customer_invoicing_account = $customerInvoicingAccount;

    return $this;
}

/**
 * Get customerInvoicingAccount
 *
 * @return integer
 */
public function getCustomerInvoicingAccount()
{
    return $this->customer_invoicing_account;
}

public function isAccountNonExpired()
{
  return true;
}

public function isAccountNonLocked()
{
  return true;
}

public function isCredentialsNonExpired()
{
  return true;
}

/**
 * Check if customer accoutn is activate
 *
 */

 public function isEnabled()
 {
   return $this->customer_is_active;
 }

/**
 * Set customerIsActive
 *
 * @param integer $customerIsActive
 *
 * @return Customer
 */
public function setCustomerIsActive($customerIsActive)
{
    $this->customer_is_active = $customerIsActive;

    return $this;
}

/**
 * Get customerIsActive
 *
 * @return integer
 */
public function getCustomerIsActive()
{
    return $this->customer_is_active;
}

/** Added these functions because of the security controller */

/**
 * Get username
 *
 * @return string
 */
 public function getUsername()
 {
   return $this->customer_email;
 }

 public function getPassword()
 {
   return $this->customer_password;
 }

 public function getSalt()
 {
   return $this->customer_salt;
 }

 public function getRoles()
 {
   return array('ROLE_USER');
 }

 public function eraseCredentials()
 {

 }

 public function serialize()
 {
    return serialize(array(
      $this->id,
      $this->customer_email,
      $this->customer_password,
      $this->customer_is_active
    ));
 }

 public function unserialize($serialized)
 {
   list (
    $this->id,
    $this->customer_email,
    $this->customer_password,
    $this->customer_is_active
   ) = unserialize($serialized);
 }
}

CustomerRepository.php:

<?php

 //src/AppBundle/Entity/CustomerRepository.php

use Symfony\Bridge\Doctrine\Security\User\UserloadInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Doctrine\ORM\EntityRepository;

class CustomerRepository extends EntityRepository implements   UserLoaderInterface
{

public function loadUserByUsername($email)
  {
  $user = $this->createQueryBuilder('c')
    ->where('c.customer_email = :email')
    ->setParameter('email', $email)
    ->getQuery()
    ->getOneOrNullResult();

    if(null === $user)
    {
      $message = sprintf(
        'Unable to find an active user AppBundle:User object identified by "%s".',
        $email
      );
      throw new UsernameNotFoundException($message);

    }

    return $user;
}
}

I have found one similar question in here (stack overflow) from last year, thought it is for version 2.5* and it did not help me. I'm using symfony3. Link to the question: The Doctrine repository "Doctrine\ORM\EntityRepository" must implement UserProviderInterface in symfony2

5
  • Try to verify that the repository belongs to that entity. Looking at EntityUserProvider, its fetching the repository in the same way you would from a controller. Try to test that. Commented Jan 28, 2016 at 12:57
  • You cannot mix annotations and yaml/xml mappings which means that the default repository class is being retrieved instead of your custom class. Add the repository class line to your mapping file under Resources/config/doctrine. Commented Jan 28, 2016 at 13:59
  • I could not find with fast search how to add repository class in yml. I have Customer.orm.yml file, I need to remove /** * @ORM\Entity(repositoryClass="AppBundle\Entity\CustomerRepository") */ and add to yml instead ? Commented Jan 28, 2016 at 14:06
  • I found how to add repository class to yml but now I get error: The autoloader expected class "AppBundle\Entity\CustomerRepository" to be defined in file "/Users/Mika/Documents/HTML Projectit/tietorauta secure/src/AppBundle/Entity/CustomerRepository.php". The file was found but the class was not in it, the class name or namespace probably has a typo. Commented Jan 28, 2016 at 16:06
  • I was missing namespace AppBundle\Entity; from repository file. Cerad, can you please post your as answer and I can accept it, it was "simple" dummy mistake, U can't mix annotations and xml/yml mappings :) Commented Jan 28, 2016 at 16:38

1 Answer 1

2

You cannot mix annotations and yaml/xml mappings which means that the default repository class is being retrieved instead of your custom class. Add the repository class line to your mapping file under Resources/config/doctrine.

# customer.orm.yml
AppBundle\Entity\Game:
  type:  entity
  table: customers
  repositoryClass: AppBundle\Entity\CustomerRepository
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.