1 | <?php |
||
23 | class UserProvider implements UserProviderInterface { |
||
24 | |||
25 | /** |
||
26 | * The Entity fieldname of the username. |
||
27 | */ |
||
28 | protected $usernameField; |
||
29 | |||
30 | /** |
||
31 | * The fieldname of the password (hash). |
||
32 | */ |
||
33 | protected $passwordField; |
||
34 | |||
35 | /** |
||
36 | * The fieldname of the password hash salt. |
||
37 | */ |
||
38 | protected $saltField; |
||
39 | |||
40 | /** |
||
41 | * Holds the AbstractData instance to grab the user data from. |
||
42 | */ |
||
43 | protected $userData; |
||
44 | |||
45 | /** |
||
46 | * Holds the AbstractData instance or the field of the many-to-many relationship to grab the user role data from. |
||
47 | */ |
||
48 | protected $userRoleData; |
||
49 | |||
50 | /** |
||
51 | * Holds the AbstractData instance or the field of the many-to-many relationship to grab the user role data from. |
||
52 | */ |
||
53 | protected $userRoleIdentifier; |
||
54 | |||
55 | /** |
||
56 | * Loads the roles of an user via an AbstractData instance. |
||
57 | * |
||
58 | * @param mixed $userId |
||
59 | * the id of the user |
||
60 | * |
||
61 | * @return string[] |
||
62 | * the roles of the user |
||
63 | */ |
||
64 | protected function loadUserRolesViaData($userId) { |
||
76 | |||
77 | /** |
||
78 | * Loads the roles of an user via a many-to-many relationship |
||
79 | * |
||
80 | * @param Entity $user |
||
81 | * the id of the user |
||
82 | * |
||
83 | * @return string[] |
||
84 | * the roles of the user |
||
85 | */ |
||
86 | protected function loadUserRolesViaManyToMany($user) { |
||
93 | |||
94 | /** |
||
95 | * Constructor for data structures connecting users and roles via a many-to-many relationship on the user. |
||
96 | * |
||
97 | * @param AbstractData $userData |
||
98 | * the AbstractData instance to grab the user data from |
||
99 | * |
||
100 | * @param string|AbstractData $userRoleIdentifier |
||
101 | * the field of the many-to-many relationship to grab the user role data from or the AbstractData if its an own entity |
||
102 | * |
||
103 | * @param string $usernameField |
||
104 | * the Entity fieldname of the username |
||
105 | * |
||
106 | * @param string $passwordField |
||
107 | * the Entity fieldname of the password hash |
||
108 | * |
||
109 | * @param string $saltField |
||
110 | * the Entity fieldname of the password hash salt |
||
111 | */ |
||
112 | public function __construct(AbstractData $userData, $userRoleIdentifier = 'roles', $usernameField = 'username', $passwordField = 'password', $saltField = 'salt') { |
||
119 | |||
120 | /** |
||
121 | * Loads and returns an user by username. |
||
122 | * Throws an UsernameNotFoundException on not existing username. |
||
123 | * |
||
124 | * @param string $username |
||
125 | * the username |
||
126 | * |
||
127 | * @return User |
||
128 | * the loaded user |
||
129 | */ |
||
130 | public function loadUserByUsername($username) { |
||
143 | |||
144 | /** |
||
145 | * Reloads and returns the given user. |
||
146 | * Throws an UsernameNotFoundException if the user ceased to exist meanwhile. |
||
147 | * |
||
148 | * @param UserInterface $user |
||
149 | * the user to reload |
||
150 | * |
||
151 | * @return User |
||
152 | * the reloaded user |
||
153 | */ |
||
154 | public function refreshUser(UserInterface $user) { |
||
158 | |||
159 | /** |
||
160 | * Tests whether the given user class is supported by this UserProvider. |
||
161 | * |
||
162 | * @param string $class |
||
163 | * the user class name to test |
||
164 | * |
||
165 | * @return boolean |
||
166 | * true if the class is "CRUDlex\User" |
||
167 | */ |
||
168 | public function supportsClass($class) { |
||
171 | |||
172 | } |
||
173 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.