Php 不在对象上下文中时使用$this的Lumen passport

Php 不在对象上下文中时使用$this的Lumen passport,php,laravel,lumen,Php,Laravel,Lumen,嗨,我是Lumen的新手,我想用oauth2构建一个restful应用程序。 所以我安装了lumen passport。 其中一个步骤是添加 Dusterio\LumenPassport\LumenPassport::routes($this->app); 在app.php中 稍后,当我运行php artisan list或任何其他cmd时,它会显示以下错误: In app.php line 97: Using $this when not in object context

嗨,我是Lumen的新手,我想用oauth2构建一个restful应用程序。 所以我安装了lumen passport。 其中一个步骤是添加

Dusterio\LumenPassport\LumenPassport::routes($this->app);
在app.php中 稍后,当我运行php artisan list或任何其他cmd时,它会显示以下错误:

In app.php line 97:

  Using $this when not in object context  
有人能告诉我怎么解决这个问题吗。 以下是我所追求的文件的链接:

这是我的应用程序文件:

<?php

require_once __DIR__.'/../vendor/autoload.php';

try {
    (new Dotenv\Dotenv(__DIR__.'/../'))->load();
} catch (Dotenv\Exception\InvalidPathException $e) {
    //
}

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/

$app = new Laravel\Lumen\Application(
    realpath(__DIR__.'/../')
);
// Enable Facades
$app->withFacades();
// Enable Eloquent
$app->withEloquent();



/*
|--------------------------------------------------------------------------
| Register Container Bindings
|--------------------------------------------------------------------------
|
| Now we will register a few bindings in the service container. We will
| register the exception handler and the console kernel. You may add
| your own bindings here if you like or you can make another file.
|
*/

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

$app->singleton(
    Illuminate\Contracts\Console\Kernel::class,
    App\Console\Kernel::class
);

/** Add auth for passport**/
$app->configure('auth');

/*
|--------------------------------------------------------------------------
| Register Middleware
|--------------------------------------------------------------------------
|
| Next, we will register the middleware with the application. These can
| be global middleware that run before and after each request into a
| route or middleware that'll be assigned to some specific routes.
|
*/

// $app->middleware([
//    App\Http\Middleware\ExampleMiddleware::class
// ]);

// Enable auth middleware (shipped with Lumen)
 $app->routeMiddleware([
    'auth' => App\Http\Middleware\Authenticate::class,
]);

/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/
$app->register(App\Providers\AppServiceProvider::class);
 $app->register(App\Providers\AuthServiceProvider::class);
 $app->register(App\Providers\EventServiceProvider::class);
//added for passport
$app->configure('auth');

// added for flipbox to generate controller and model in lumen
$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);
//for lumen passport
$app->register(Laravel\Passport\PassportServiceProvider::class);
$app->register(Dusterio\LumenPassport\PassportServiceProvider::class);
Dusterio\LumenPassport\LumenPassport::routes($this->app);

/*
|--------------------------------------------------------------------------
| Load The Application Routes
|--------------------------------------------------------------------------
|
| Next we will include the routes file so that they can all be added to
| the application. This will provide all of the URLs the application
| can respond to, as well as the controllers that may handle them.
|
*/

$app->router->group([
    'namespace' => 'App\Http\Controllers',
], function ($router) {
    require __DIR__.'/../routes/web.php';
});

return $app;

正如错误所说:
$this
只能在实例方法内部访问。 要获取应用程序对象,可以调用
app()
函数

就你而言:

Dusterio\LumenPassport\LumenPassport::routes(app());

这将起作用,尽管它可以是
Dusterio\LumenPassport\LumenPassport::routes($app)非常非常好,它一次又一次地完美工作