<commit_before><?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
namespace BaseX\Symfony\Security;


use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use BaseX\Symfony\Security\UsersDocument;

/**
 * Description of UserProvider
 *
 * @author alxarch
 */
class UserProvider implements UserProviderInterface
{
  /**
   *
   * @var \Symfony\Component\Security\BaseX\UsersDocument
   */
  private $users;
  
  public function __construct(UsersDocument $users) 
  {
    $this->users = $users;
  }
  
  public function loadUserByUsername($username) {
    $user = $this->users->getUser($username);

    if(null === $user)
    {
      throw new UsernameNotFoundException("Username '$username' not found.");
    }
    
    return $user;
    
  }

  public function refreshUser(UserInterface $user){
    if(!$this->supportsClass(get_class($user)))
    {
      throw new UnsupportedUserException("Unsupported user class.");
    }
    
    return $this->loadUserByUsername($user->getUsername());
  }
  
  public function supportsClass($class) {
    return $class === '\BaseX\Symfony\Security\User';
  }
}<commit_msg>Fix class name<commit_after><?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
namespace BaseX\Symfony\Security;


use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use BaseX\Symfony\Security\UsersDocument;

/**
 * Description of UserProvider
 *
 * @author alxarch
 */
class UserProvider implements UserProviderInterface
{
  /**
   *
   * @var \Symfony\Component\Security\BaseX\UsersDocument
   */
  private $users;
  
  public function __construct(UsersDocument $users) 
  {
    $this->users = $users;
  }
  
  public function loadUserByUsername($username) {
    $user = $this->users->getUser($username);

    if(null === $user)
    {
      throw new UsernameNotFoundException("Username '$username' not found.");
    }
    
    return $user;
    
  }

  public function refreshUser(UserInterface $user){
    if(!$this->supportsClass(get_class($user)))
    {
      throw new UnsupportedUserException("Unsupported user class.");
    }
    
    return $this->loadUserByUsername($user->getUsername());
  }
  
  public function supportsClass($class) {
    return $class === 'BaseX\Symfony\Security\User';
  }
}
{'fraction_non_alphanumeric': 0.12164124909222948, 'fraction_numerical': 0.0, 'mean_word_length': 3.8503521126760565, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '359492', 'n_tokens_mistral': 807, 'n_tokens_neox': 803, 'n_words': 160}