有人使用过 Dingo/API 管理 API 的组件么,求各路大神帮忙看看啥情况,求围观,求开脑洞

## Dingo/api 运行报错

> 本人最近在做的项目,涉及到给手机app提供api,想尝试下 https://github.com/dingo/api/ 来管理api,按照github上的wiki一路next,结果还没深入就报错,不知道哪里出问题,请各位路过的一起帮忙看看。
>

开发环境

- php 5.6
- nginx 1.7

composer 配置

"require": {
"php" : ">=5.5.9",
"laravel/framework" : "5.1.",
"lucadegasperi/oauth2-server-laravel" : "4.1.x@dev",
"tymon/jwt-auth" : "0.5.
",
"dingo/api" : "0.9.*@dev"
},

要是按照wiki上的 "dingo/api": "0.9.*" 根本找不到包的版本,所以我加上@dev 总算可以下载

增加providers

php
'providers' => [
Dingo\Api\Provider\LaravelServiceProvider::class
]

生成api配置文件

php
php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"

扩展验证方法

按照wiki原文增加验证扩展提供者,结果一加上去就报错
Authentication Providers
By default only basic authentication is enabled. Authentication is covered in more detail in a later chapter.
You must configure this in a published configuration file or in your bootstrap file.
php
$app['Dingo\Api\Auth\Auth']->extend('oauth', function ($app) {
return new Dingo\Api\Auth\Provider\JWT($app['Tymon\JWTAuth\JWTAuth']);
});


按照wiki,我在bootstrap/app.php 内增加了上面的代码,不知道是加错地方呢,还是版本有问题,访问首页直接报错

报错结果

<code>
Fatal error: Uncaught exception 'Illuminate\Contracts\Container\BindingResolutionException' with message 'Target [Dingo\Api\Contract\Routing\Adapter] is not instantiable.' in E:\site\project\vendor\laravel\framework\src\Illuminate\Container\Container.php:744 Stack trace: #0 E:\site\project\vendor\laravel\framework\src\Illuminate\Container\Container.php(626): Illuminate\Container\Container->build('Dingo\Api\Contr...', Array) #1 E:\site\project\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(674): Illuminate\Container\Container->make('Dingo\Api\Contr...', Array) #2 E:\site\project\vendor\laravel\framework\src\Illuminate\Container\Container.php(837): Illuminate\Foundation\Application->make('Dingo\Api\Contr...') #3 E:\site\project\vendor\laravel\framework\src\Illuminate\Container\Container.php(800): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter)) #4 E:\site\project\vendor\laravel\framework\src\Illuminate\Container\Container.php(771): Illuminate\Contain in E:\site\project\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 744
</code>
从报错信息来看,提示 Dingo\Api\Contract\Routing\Adapter 不能 实例化,但是wiki上这么描述,实际却行不通,难道是我打开方式不对?还是姿势不多,坑啊,谁能告诉我咩,咋回事
已邀请:

wind930

赞同来自: sun

@sun

jasonlewis commented on 21 May

Register the package in your config/app.php. You're using Laravel 5 you don't need to register it in the bootstrap file. That's probably my bad, but the demo I posted in my OP was for Lumen.
You'll also need to get the router instance in your routes.php file and not the bootstrap file.

Sorry I should've noted that.
这个是作者关于上述问题的回答,对于laravel 5 不需要注册这些,文档和代码有很多错误,或者不是明确的地方,请大家一定要注意,另外作者也没有太多时间去维护这个库,虽然作者近期计划修正下文档和增加相关特性,但是还是需要时间。下面是作者的一段回复:
jasonlewis commented on 21 May
Sorry I don't have time to write a complex example for you nor should I be required too. I'm working on documentation but you must realize that I do this in my free time and as such I'm not able to get it done in a couple of days.
So I ask that you be patient. Honestly, there's not a whole lot to this package and the older documentation on the Wiki is still somewhat relevant. Most differences are class names have changed and some methods may be different. My advice is to read over the old documentation, have a play with the package and flick through the source code.
(dinggo/api issuses/412)[https://github.com/dingo/api/issues/412]

温柔特洛伊

赞同来自:

wiki 好像不对
我是这样用的 在routes.php中
// API Routes
$api = app('api.router');
$api->version('v1', function ($api) {
$api->get('users/{id}', 'App\Http\Controllers\UserController@show');
});

sun

赞同来自:

hi,我根据wiki的配置也遇到了相同的问题,怎么解决的?

要回复问题请先登录注册