yiisoft / demo

Yii 3 demo application
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
318 stars 134 forks source link

CurrentRequest is valid #607

Closed hiscaler closed 11 months ago

hiscaler commented 11 months ago

public function update(#[RouteArgument('id')] int $id, EditThirdPartyAccountRequest $editThirdPartyAccountRequest, UserRequest $userRequest): Response

$userRequest is invalid

object(App\User\UserRequest)[559] private App\User\User 'user' => uninitialized

this is my config

return [
    IdentityRepositoryInterface::class => UserRepository::class,
    IdentityWithTokenRepositoryInterface::class => UserRepository::class,
    AuthenticationMethodInterface::class => HttpHeader::class,
    Authentication::class => [
        'class' => Authentication::class,
        '__construct()' => [
            'authenticationFailureHandler' => Reference::to(PassportRequestErrorHandler::class),
        ],
    ],
];

What's setting todo?

vjik commented 11 months ago

What is "CurrentRequest" from issue theme?

Is problem with "UserRequest"? Please, show code of this class.

hiscaler commented 11 months ago

UserRequest class

<?php

declare(strict_types=1);

namespace App\User;

use Yiisoft\Auth\Middleware\Authentication;
use Yiisoft\Input\Http\Attribute\Parameter\Request;
use Yiisoft\Input\Http\RequestInputInterface;

final class UserRequest implements RequestInputInterface
{

    #[Request(Authentication::class)]
    private User $user;

    public function getUser(): User
    {
        return $this->user;
    }

}
vjik commented 11 months ago

Seems, you need to use request catcher. There are to make it two ways.

1) Use RequestCatcherParametersResolver in middleware dispatcher. Example here: https://github.com/yiisoft/demo/blob/master/blog-api/config/web/di/middleware-dispatcher.php#L12

2) Add RequestCatcherMiddleware to list of your middlewares

hiscaler commented 11 months ago

I already use first way, but invalid

hiscaler commented 11 months ago

Is setting error?

vjik commented 11 months ago

Hm. Does it work before release Yii User 2.1?

hiscaler commented 11 months ago

i used 2.0, i upgrade reference blog example. It was okay before

vjik commented 11 months ago

I tested demo, everything is working correctly.

May be you don't configure hydrator: https://github.com/yiisoft/demo/blob/master/blog-api/config/common/di/hydrator.php ?

PR with demo adaptation: https://github.com/yiisoft/demo/pull/599. May be it help you...

hiscaler commented 11 months ago

Have been configured

hiscaler commented 11 months ago

I rollback it, Wait till I have time to test

A lot of things have not been officially released, and there are still a lot of questions. Of course, it has something to do with my unfamiliarity.

hiscaler commented 11 months ago

When are you ready to release Yii3?

vjik commented 11 months ago

When are you ready to release Yii3?

I hope that soon. Currently we hard work with code (hydrator and forms almost ready), then planned create/improve docs.

I rollback it, Wait till I have time to test

I moved tihs issue to demo repo.

hiscaler commented 11 months ago

Sorry , i don't add auth middleware to rule. so can't get it. Very very sorry!