Laravel / Lumen核心应用中的覆盖方法

Is it possible to override a function defined in the Laravel/Lumen Application class?

For example, this is the definition of isDownForMaintenance in the Lumen Application class:

public function isDownForMaintenance() : bool
{
    return false;
}

I would like to override this with my own implementation like so:

public function isDownForMaintenance() : bool
{
    // Do something…
}

I have tried…

AppServiceProvider.php

$this->app->extend(‘app’, function () {
    return new Application; // Extension of Laravel/Lumen/Application
});

Application.php

class Application extends BaseApplication
{
    public function isDownForMaintenance() : bool
    {
        // Do Something…
    }
}

After exploring throughout the web, I have managed to stumble upon an article that outlines exactly what I was looking for. For the purposes of simplicity, I will outline how to extend Laravel's & Lumen's core Application class, but for those of you who wish to see a more in depth description, please see here:

https://mattstauffer.com/blog/extending-laravels-application/

This is surprisingly, extremely easy... First, we find the place where Application is created i.e. /bootstrap/app.php

Then, we find the following line:

Laravel

$app = new Illuminate\Foundation\Application(
    realpath(__DIR__.'/../')
);

Lumen

$app = new Laravel\Lumen\Application(
    realpath(__DIR__.'/../')
);

And then quite simply change to this:

$app = new Custom\Application(
    realpath(__DIR__.'/../')
);

You can then do whatever you like with `Custom\Application', for instance;

class Application extends BaseApplication
{
    // Override the maintenance mode detection...
    public function isDownForMaintenance() : bool
    {
        // Do Something…
    }

    // Override the default storage path...
    public function storagePath()
    {
        return $this->basePath.'/custom/storage';
    }
}