There is no problem in having the name of the desired properties, as long as you return correctly what the interface
implemented requires.
An interface in PHP "force" that the class has the methods that are set in it.
So what do you use the interface Symfony\Component\Security\Core\User\UserInterface
, what you need to do is return $senha
for the method getPassword
and usuario
for the method getUsername
.
There are also other methods that need to be implemented from this interface
Recommended readings:
Example taken from the Symfony
:
namespace AppBundle\Security\User;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\EquatableInterface;
class WebserviceUser implements UserInterface, EquatableInterface
{
private $usuario;
private $senha;
private $salt;
private $roles;
public function __construct($usuario, $senha, $salt, array $roles)
{
$this->usuario = $usuario;
$this->senha = $senha;
$this->salt = $salt;
$this->roles = $roles;
}
public function getRoles()
{
return $this->roles;
}
public function getPassword()
{
return $this->senha;
}
public function getSalt()
{
return $this->salt;
}
public function getUsername()
{
return $this->usuario;
}
public function eraseCredentials()
{
}
public function isEqualTo(UserInterface $user)
{
if (!$user instanceof WebserviceUser) {
return false;
}
if ($this->senha !== $user->getPassword()) {
return false;
}
if ($this->salt !== $user->getSalt()) {
return false;
}
if ($this->usuario !== $user->getUsername()) {
return false;
}
return true;
}
}