问题
I want to try with this OAuth2-Server Example ( https://github.com/alexbilbie/oauth2-example-auth-server
) but when I want to run it gives me error " Fatal error: Interface 'OAuth2\Storage\ClientInterface' not found in /var/www/oauth2-auth-server/model_client.php on line 2 "
I think I need to add autoloader to composer.json I did it but forever it gives me this error. But I also think in oauth.php I found this line:
// Initiate the auth server with the models
$server = new \OAuth2\AuthServer(new ClientModel, new SessionModel, new ScopeModel);
But there is no any AuthServer
in the OAuth folder? Is there anybody used this example. Thanks in advance!
回答1:
Autoloading is done automatically using Composer assuming you've downloaded the dependencies from modules stated in the require
key of your composer.json
file. Just include this at the top of your PHP script to access the Classes:
require_once __DIR__.'/to/vendor/autoload.php';
If these are manually downloaded packages you'll need to point the autoloader to them and run composer update
:
"autoload": {
"psr-0": {
"Util\\": "assets/"
},
"files": ["assets/Util/init.php"]
}
The above automatically:
- appends the script at
assets/Util/init.php
to every file where the autoloader is run; - and autoloads classes from, in this example, the Util namespace (has to be in a folder called Util to meet psr-0 convention so is actually at
assets/Util/
) into any file that runs the autoloader
You may also need to manage namespace issues using the use Namespace\Class as Class;
syntax.
来源:https://stackoverflow.com/questions/21092104/oauth-2-0-example-auth-server