@@ -22,24 +22,24 @@ namespace Zend\Expressive\Authentication;
22
22
interface UserInterface
23
23
{
24
24
/**
25
- * Get the unique user identity (id, username, email address or ...)
25
+ * Get the unique user identity (id, username, email address, etc.).
26
26
*/
27
27
public function getIdentity() : string;
28
28
29
29
/**
30
- * Get all user roles
30
+ * Get all user roles.
31
31
*
32
32
* @return string[]
33
33
*/
34
34
public function getRoles() : array;
35
35
36
36
/**
37
- * Get a detail $name if present, $default otherwise
37
+ * Get the detail named $name if present; return $default otherwise.
38
38
*/
39
39
public function getDetail(string $name, $default = null);
40
40
41
41
/**
42
- * Get all the details, if any
42
+ * Get all additional user details, if any.
43
43
*/
44
44
public function getDetails() : array;
45
45
}
@@ -52,28 +52,40 @@ authorization level of a user (for this scope, it is consumed by
52
52
53
53
## Default User class
54
54
55
- We provide a default implementation of ` UserInterface ` via the class ` Zend\Expressive\Authentication\DefaultUser ` .
56
- The class is final and immutable, in order to prevent runtime changes.
57
- We provide a factory class for generating ` DefaultUser ` instances via
58
- ` Zend\Expressive\Authentication\DefaultUserFactory ` .
55
+ We provide a default implementation of ` UserInterface ` via the class
56
+ ` Zend\Expressive\Authentication\DefaultUser ` . The class is final and immutable,
57
+ in order to prevent runtime changes.
59
58
60
- In order to set the identity and the user's role we provided a default factory
61
- class that generates a ` UserInterface ` object. This factory is
62
- ` Zend\Expressive\Authentication\UserInterfaceFactory ` . This class uses a ` generate `
63
- function to create a ` UserInterface ` instance passing the identity and the roles
64
- (if any) of the user.
59
+ Repositories will fetch user information based on the identity, including any
60
+ associated roles, and optionally any additional details (full name, email,
61
+ profile information, etc.). Often, user data and the objects representing them
62
+ are unique to the application. As such, the default repository implementations
63
+ we provide allow you to inject a _ factory_ for producing the user. This factory
64
+ should be a PHP callable with the following signature:
65
65
66
- If you want, you can customize the ` UserInterfaceFactory ` using your custom
67
- ` UserInterface ` implementation. You need to change the service configuration as
68
- follows:
66
+ ``` php
67
+ function (string $identity, array $roles = [], array $details = []) : UserInterface
68
+ ```
69
+
70
+ In order to notify the package to use your custom factory, you will need to
71
+ create a service factory that returns it, and map it to the
72
+ ` Zend\Expressive\Authentication\UserInterface ` service.
73
+
74
+ We provide a service factory named ` Zend\Expressive\Authentication\DefaultUserFactory `
75
+ that returns a user factory that produces a ` DefaultUser ` instance from the
76
+ arguments provided. This is mapped as follows in the service configuration:
69
77
70
78
``` php
79
+ use Zend\Expressive\Authentication\DefaultUserFactory;
80
+ use Zend\Expressive\Authentication\UserInterface;
81
+
71
82
return [
72
83
// ...
73
84
'dependencies' => [
74
85
'factories' => [
75
86
// ...
76
- // change the DefaultUserFactory::class with your custom factory
87
+ // Change the DefaultUserFactory::class with your custom service
88
+ // factory that produces a user factory:
77
89
UserInterface::class => DefaultUserFactory::class
78
90
]
79
91
]
@@ -113,6 +125,11 @@ Basic Access Authentication* adapter and the *htpasswd* file as the user
113
125
repository.
114
126
115
127
``` php
128
+ use Zend\Expressive\Authentication\AuthenticationInterface;
129
+ use Zend\Expressive\Authentication\Basic;
130
+ use Zend\Expressive\Authentication\UserRepository;
131
+ use Zend\Expressive\Authentication\UserRepositoryInterface;
132
+
116
133
return [
117
134
// ...
118
135
'dependencies' => [
0 commit comments