Изучаю symfony3
Пытаюсь реализовать
symfony.com/doc/current/security/entity_provider.h...
Но при попытки входа в приложение получаю - The Doctrine repository "Doctrine\ORM\EntityRepository" must implement Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface.
<?php
//zenaku/AppBundle/Entity/Repository/UsersRepository.php
namespace zenaku\AppBundle\Entity\Repository;
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping AS ORM;
class UsersRepository extends EntityRepository implements UserLoaderInterface
{
public function loadUserByUsername($username)
{
return $this->createQueryBuilder('u')
->where('u.username = :username OR u.email = :email')
->setParameter('username', $username)
->setParameter('email', $username)
->getQuery()
->getOneOrNullResult();
}
}
<?php
//zenaku/AppBundle/Entity/Users.php
namespace zenaku\AppBundle\Entity;
use Doctrine\ORM\Mapping AS ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
/**
* Users
*
* @ORM\Entity(repositoryClass="zenaku\AppBundle\Entity\Repository\UsersRepository")
* @ORM\Table(name="users", uniqueConstraints={@ORM\UniqueConstraint(name="username_UNIQUE", columns={"username"}), @ORM\UniqueConstraint(name="id_UNIQUE", columns={"id"}), @ORM\UniqueConstraint(name="email_UNIQUE", columns={"email"})}, indexes={@ORM\Index(name="fk_users_privileges_idx", columns={"privileges"})})
* @ORM\Entity
*/
class Users implements UserInterface, AdvancedUserInterface, \Serializable
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="username", type="string", length=16, nullable=false)
*/
private $username;
//...
}
security:
encoders:
zenaku\AppBundle\Entity\Users:
algorithm: bcrypt
encode_as_base64: true
cost: 15
providers:
db_hal:
entity:
class: zenakuAppBundle:Users
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
form_login:
login_path: login
check_path: check_login
username_parameter: username
password_parameter: password
provider: db_hal
logout: ~
anonymous: ~
switch_user: { role: ROLE_UBERADMIN, parameter: _i_other_user}
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_UBERADMIN: ROLE_ADMIN
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY}
- { path: ^/admin, roles: ROLE_ADMIN}
- { path: ^/, roles: ROLE_USER}
В интернете пишут что-то о несовместимости конфигураций в аннотациях/yml/xml. Хотя я использую лишь аннотации.
Вот к примеру