1<?php 2 3/* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Symfony\Component\Security\Core\User; 13 14use Symfony\Component\Security\Core\Role\Role; 15 16/** 17 * Represents the interface that all user classes must implement. 18 * 19 * This interface is useful because the authentication layer can deal with 20 * the object through its lifecycle, using the object to get the encoded 21 * password (for checking against a submitted password), assigning roles 22 * and so on. 23 * 24 * Regardless of how your users are loaded or where they come from (a database, 25 * configuration, web service, etc.), you will have a class that implements 26 * this interface. Objects that implement this interface are created and 27 * loaded by different objects that implement UserProviderInterface. 28 * 29 * @see UserProviderInterface 30 * @see AdvancedUserInterface 31 * 32 * @author Fabien Potencier <fabien@symfony.com> 33 */ 34interface UserInterface 35{ 36 /** 37 * Returns the roles granted to the user. 38 * 39 * public function getRoles() 40 * { 41 * return ['ROLE_USER']; 42 * } 43 * 44 * Alternatively, the roles might be stored on a ``roles`` property, 45 * and populated in any number of different ways when the user object 46 * is created. 47 * 48 * @return (Role|string)[] The user roles 49 */ 50 public function getRoles(); 51 52 /** 53 * Returns the password used to authenticate the user. 54 * 55 * This should be the encoded password. On authentication, a plain-text 56 * password will be salted, encoded, and then compared to this value. 57 * 58 * @return string|null The encoded password if any 59 */ 60 public function getPassword(); 61 62 /** 63 * Returns the salt that was originally used to encode the password. 64 * 65 * This can return null if the password was not encoded using a salt. 66 * 67 * @return string|null The salt 68 */ 69 public function getSalt(); 70 71 /** 72 * Returns the username used to authenticate the user. 73 * 74 * @return string The username 75 */ 76 public function getUsername(); 77 78 /** 79 * Removes sensitive data from the user. 80 * 81 * This is important if, at any given point, sensitive information like 82 * the plain-text password is stored on this object. 83 */ 84 public function eraseCredentials(); 85} 86