From 80078fc959ef79b17706205b51e806e386ef3cad Mon Sep 17 00:00:00 2001 From: klsoft-web Date: Wed, 21 Jan 2026 09:21:56 +0300 Subject: [PATCH 1/3] The 'Using Yiisoft\User\CurrentUser' section has been refactored --- src/guide/security/authentication.md | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/guide/security/authentication.md b/src/guide/security/authentication.md index ad103e45..f7fc1050 100644 --- a/src/guide/security/authentication.md +++ b/src/guide/security/authentication.md @@ -132,25 +132,31 @@ final readonly class IdentityRepository implements IdentityRepositoryInterface } ``` -## Using `\Yiisoft\User\CurrentUser` +## Using `Yiisoft\User\CurrentUser` -You can use `\Yiisoft\User\CurrentUser` service to get current user identity. +You can use `Yiisoft\User\CurrentUser` service to get current user identity. As any service, it could be auto-wired in either action handler constructor or method: ```php -use \Psr\Http\Message\ServerRequestInterface; -use \Yiisoft\User\CurrentUser; +use Psr\Http\Message\ServerRequestInterface; +use Yiisoft\User\CurrentUser; final readonly class SiteController { - public function actionIndex(ServerRequestInterface $request, CurrentUser $user) - { - if ($user->isGuest()) { + public function __construct( + private ServerRequestInterface $request, + private CurrentUser $user) + { + } + + public function index() + { + if ($this->user->isGuest()) { // user is guest } else { - $identity = $user->getIdentity(); + $identity = $this->user->getIdentity(); // do something based on identity - } + } } } ``` From 109cc0f189e18453f5881663fd41accfd9e15966 Mon Sep 17 00:00:00 2001 From: klsoft-web Date: Wed, 21 Jan 2026 16:35:39 +0300 Subject: [PATCH 2/3] Update src/guide/security/authentication.md Co-authored-by: Sergei Predvoditelev --- src/guide/security/authentication.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/guide/security/authentication.md b/src/guide/security/authentication.md index f7fc1050..7dea893c 100644 --- a/src/guide/security/authentication.md +++ b/src/guide/security/authentication.md @@ -145,9 +145,8 @@ final readonly class SiteController { public function __construct( private ServerRequestInterface $request, - private CurrentUser $user) - { - } + private CurrentUser $user, + ) {} public function index() { From 67a13cc255645f09230b951a778c5b7f07fd640e Mon Sep 17 00:00:00 2001 From: klsoft-web Date: Wed, 21 Jan 2026 16:35:46 +0300 Subject: [PATCH 3/3] Update src/guide/security/authentication.md Co-authored-by: Sergei Predvoditelev --- src/guide/security/authentication.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/guide/security/authentication.md b/src/guide/security/authentication.md index 7dea893c..dc077fbb 100644 --- a/src/guide/security/authentication.md +++ b/src/guide/security/authentication.md @@ -148,7 +148,7 @@ final readonly class SiteController private CurrentUser $user, ) {} - public function index() + public function index(): ResponseInterface { if ($this->user->isGuest()) { // user is guest