bshaffer / oauth2-server-php

A library for implementing an OAuth2 Server in php
http://bshaffer.github.io/oauth2-server-php-docs
MIT License
3.26k stars 951 forks source link

Request object not compatible with Yii2 request interface #1009

Open spiro-stathakis opened 3 years ago

spiro-stathakis commented 3 years ago

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 commented 3 years ago

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