oauth2-server-php icon indicating copy to clipboard operation
oauth2-server-php copied to clipboard

Request object not compatible with Yii2 request interface

Open spiro-stathakis opened this issue 4 years ago • 1 comments

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.

spiro-stathakis avatar Sep 23 '21 10:09 spiro-stathakis

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

bshaffer avatar Sep 23 '21 19:09 bshaffer