Reputation: 10012
I have the following function inside one of my Controller classes:
public function postToken(){
$bridgedRequest = OAuth2\HttpFoundationBridge\Request::createFromRequest(Request::instance());
$bridgedResponse = new OAuth2\HttpFoundationBridge\Response();
$bridgedResponse = App::make('oauth2')->handleTokenRequest($bridgedRequest, $bridgedResponse);
return $bridgedResponse;
}
It's being called fine, but I'm getting a whole pile of "Class not found" errors...
e.g.:
<span class="exception_message">Class 'OAuth2' not found</span>
<span class="exception_message">Class 'App\Http\Controllers\Request' not found</span>
<span class="exception_message">Class 'App\Http\Controllers\OAuth2\HttpFoundationBridge\Request' not found</span>
How do I import these classes correctly? I have them in my composer.json file and I already performed composer update
...
Here's my composer.json file:
"require": {
"laravel/framework": "5.0.*",
"bshaffer/oauth2-server-php": "^1.7",
"bshaffer/oauth2-server-httpfoundation-bridge": "^1.1"
}
I'm new to Laravel so I'm still getting used to how things work...
I think this is just a simple use
import statement, but I'm afraid I'm very stuck...
Upvotes: 0
Views: 152
Reputation: 2828
With PHP namespaces you occasionally have to use absolute namespaces in order to the class loader to work properly.
Replace OAuth2\HttpFoundationBridge\Request
with \OAuth2\HttpFoundationBridge\Request
and see how it goes.
You can also import classes, interfaces and so on with the use
statement.
namespace App\Http\Controllers;
use OAuth2\HttpFoundationBridge\Request as OAuth2Request;
class YourController { ... }
Now the Request
from the OAuth2
vendor is available inside YourController
directly by using OAuth2Request
.
Regarding Request::instance()
, you need to somehow get the request object for use in the method postToken
. You can use method injection as you are working inside a Controller:
public function postToken(\Namespace\To\Request $request)
{
$request->instance();
}
Upvotes: 2