Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request object not compatible with Yii2 request interface #1009

Open
spiro-stathakis opened this issue Sep 23, 2021 · 1 comment
Open

Request object not compatible with Yii2 request interface #1009

spiro-stathakis opened this issue Sep 23, 2021 · 1 comment

Comments

@spiro-stathakis
Copy link

spiro-stathakis commented Sep 23, 2021

Since version Yii2 v. 2.0.36 the base controller class have these directives inside the init method:

public function init()
    {
        parent::init();
        $this->request = Instance::ensure($this->request, Request::className());
        $this->response = Instance::ensure($this->response, Response::className());
    }

So any code in downstream classes that call parent::init() before their own installation will receive an error. This means the following init logic no longer works:

$request = OAuth2\Request::createFromGlobals();

Yii2 is also not PSR compliant so these is not possible:

// use HttpFoundation Requests instead, for Symfony / Twig / Laravel 4 / Drupal 8 / etc!
$symfony_request = Symfony\Component\HttpFoundation\Request::createFromGlobals();
$request = OAuth2\HttpFoundationBridge\Request::createFromRequest($symfony_request)

Is there anything I can do? I can avoid the error by not calling parent::init() in the child classes but this is something of anti-pattern.

@bshaffer
Copy link
Owner

You could make your own bridge, similar to the HttpFoundationBridge for Yii requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants