68 lines
1.9 KiB
PHP
68 lines
1.9 KiB
PHP
|
<?php
|
||
|
namespace EmotionHero\Models;
|
||
|
|
||
|
use Doctrine\ORM\EntityRepository;
|
||
|
use Symfony\Component\Security\Core\User\UserProviderInterface;
|
||
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||
|
|
||
|
class UserRepository extends EntityRepository implements UserProviderInterface
|
||
|
{
|
||
|
|
||
|
/**
|
||
|
* Loads the user for the given username.
|
||
|
*
|
||
|
* This method must throw UsernameNotFoundException if the user is not
|
||
|
* found.
|
||
|
*
|
||
|
* @param string $username The username
|
||
|
*
|
||
|
* @return UserInterface
|
||
|
*
|
||
|
* @throws UsernameNotFoundException if the user is not found
|
||
|
*/
|
||
|
public function loadUserByUsername($username) {
|
||
|
$user = $this->find($username); // username == $id field
|
||
|
if(!$user) {
|
||
|
throw new \Symfony\Component\Security\Core\Exception\UsernameNotFoundException("Invalid username");
|
||
|
}
|
||
|
return $user;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Refreshes the user for the account interface.
|
||
|
*
|
||
|
* It is up to the implementation to decide if the user data should be
|
||
|
* totally reloaded (e.g. from the database), or if the UserInterface
|
||
|
* object can just be merged into some internal array of users / identity
|
||
|
* map.
|
||
|
*
|
||
|
* @param UserInterface $user
|
||
|
*
|
||
|
* @return UserInterface
|
||
|
*
|
||
|
* @throws UnsupportedUserException if the account is not supported
|
||
|
*/
|
||
|
public function refreshUser(UserInterface $user) {
|
||
|
$this->_em->refresh($user);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Whether this provider supports the given user class.
|
||
|
*
|
||
|
* @param string $class
|
||
|
* @todo Extending User should be possible
|
||
|
* @return bool
|
||
|
*/
|
||
|
public function supportsClass($class) {
|
||
|
return $class == User::class;
|
||
|
}
|
||
|
|
||
|
// $query = $this->_em->createQuery(
|
||
|
// 'SELECT ri FROM ...::class ri WHERE ri.result = :result AND ri.hitAt IS NULL ORDER BY ri.usedPosition ASC'
|
||
|
// )
|
||
|
// ->setParameters([
|
||
|
// 'result' => $result,
|
||
|
// ])
|
||
|
// ->setMaxResults($limit);
|
||
|
// $resultItems = $query->getResult();
|
||
|
}
|