laravel 一些好的设计 - (sunznx) 振翅飞翔
03 September 2019

暴露最小化可修改的代码

laravel 框架是围绕着 Contracts(即 interface) 来设计的: 如 Bus, Cache, Config, Console, Container, Cookie, Database, Events, Http
代码在 laravel/framework/src/Illuminate/Contracts 里面,意思是只要实现了这些 interface,你就可以自己实现一个 laravel

什么叫 暴露最小化可修改的代码 ,这是我瞎起的。以 Illuminate/Contracts/Http/Kernel.php 为例, 实际上 Illuminate/Foundation/Http/Kernel.php 这个文件已经 implementKernel Interface 了,laravel 的高明之处是还提供了 app/Http/Kernel.php 这个可以定制化的文件

app/Http/Kernel.php 很简单,只是继承了 Illuminate/Foundation/Http/Kernel

Illuminate/Foundation/Http/Kernel.php

use Illuminate\Contracts\Http\Kernel as KernelContract;

class Kernel implements KernelContract
{

}

app/Http/Kernel.php

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{

}