Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 2da5809

Browse files
committed
Changed the doc with the latest code change
1 parent a732243 commit 2da5809

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

docs/book/v1/intro.md

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,12 @@ interface UserInterface
2626
*/
2727
public function getIdentity() : string;
2828

29-
/**
30-
* Set the user identity
31-
*/
32-
public function setIdentity(string $identity) : void
33-
{
34-
$this->identity = $identity;
35-
}
36-
3729
/**
3830
* Get all user roles
3931
*
4032
* @return string[]
4133
*/
4234
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;
5035
}
5136
```
5237

@@ -57,10 +42,18 @@ authorization level of a user (for this scope, it is consumed by
5742

5843
## Default User class
5944

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:
6457

6558
```php
6659
// src/ConfigProvider.php
@@ -69,19 +62,15 @@ By default, the alias points to `DefaultUser` in the ConfigProvider class.
6962
{
7063
return [
7164
// ...
72-
'aliases' => [
73-
// ...
74-
UserInterface::class => DefaultUser::class
65+
'factories' => [
66+
// here change the UserInterfaceFactory::class with your class
67+
UserInterface::class => UserInterfaceFactory::class
7568
]
7669
];
7770
}
7871
// ...
7972
```
8073

81-
You can change it using a custom `UserInterface` implementation or extending
82-
the `DefaultUser` class if you will.
83-
84-
8574
## Usage in the route
8675

8776
The `AuthenticationMiddleware` can be used to authenticate a route. You just

0 commit comments

Comments
 (0)