@@ -26,27 +26,12 @@ interface UserInterface
26
26
*/
27
27
public function getIdentity() : string;
28
28
29
- /**
30
- * Set the user identity
31
- */
32
- public function setIdentity(string $identity) : void
33
- {
34
- $this->identity = $identity;
35
- }
36
-
37
29
/**
38
30
* Get all user roles
39
31
*
40
32
* @return string[]
41
33
*/
42
34
public function getRoles() : array;
43
-
44
- /**
45
- * Set the user's roles
46
- *
47
- * @param string[] $roles
48
- */
49
- public function setRoles(array $roles) : void;
50
35
}
51
36
```
52
37
@@ -57,10 +42,18 @@ authorization level of a user (for this scope, it is consumed by
57
42
58
43
## Default User class
59
44
60
- We provided a default user class, implemented by ` Zend\Authentication\DefaultUser ` .
61
- This class is a basic implementation of ` UserInterface ` . This default class
62
- can be changed by configuration, using the service alias ` Zend\Authentication\UserInterface ` .
63
- By default, the alias points to ` DefaultUser ` in the ConfigProvider class.
45
+ We provide a default implementation of ` UserInterface ` via the class ` Zend\Expressive\Authentication\DefaultUser ` .
46
+ This class is a basic implementation of ` UserInterface ` . This class is final and
47
+ it's immutable, that means you cannot change it state at runtime.
48
+ In order to set the identity and the user's role we provided a default factory
49
+ class that generates a ` UserInterface ` object. This factory is
50
+ ` Zend\Expressive\Authentication\UserInterfaceFactory ` . This class uses a ` generate `
51
+ function to create a ` UserInterface ` instance passing the identity and the roles
52
+ (if any) of the user.
53
+
54
+ If you want, you can customize the ` UserInterfaceFactory ` using your custom
55
+ ` UserInterface ` implementation. You need to change the service configuration as
56
+ follows:
64
57
65
58
``` php
66
59
// src/ConfigProvider.php
@@ -69,19 +62,15 @@ By default, the alias points to `DefaultUser` in the ConfigProvider class.
69
62
{
70
63
return [
71
64
// ...
72
- 'aliases ' => [
73
- // ...
74
- UserInterface::class => DefaultUser ::class
65
+ 'factories ' => [
66
+ // here change the UserInterfaceFactory::class with your class
67
+ UserInterface::class => UserInterfaceFactory ::class
75
68
]
76
69
];
77
70
}
78
71
// ...
79
72
```
80
73
81
- You can change it using a custom ` UserInterface ` implementation or extending
82
- the ` DefaultUser ` class if you will.
83
-
84
-
85
74
## Usage in the route
86
75
87
76
The ` AuthenticationMiddleware ` can be used to authenticate a route. You just
0 commit comments