首页 > 非laravel项目 使用Illuminate 怎么注册服务提供者?!

非laravel项目 使用Illuminate 怎么注册服务提供者?!

非laravel项目 使用Illuminate 怎么注册服务提供者?!


可以参考laravel的实现:

Illuminate\Foundation\Application

class Example
{
    public function say()
    {
        echo 'hello';
    }
}


$app = new Illuminate\Container\Container;
$app->instance('Illuminate\Container\Container',$app);  //共享容器对象

//注册一个服务
$app->bind('example',function(){
    return new Example();
});


$app->make('example')->say();       //hello


$app2 = new Illuminate\Container\Container; //获得共享的容器对象,即$app

$app2->make('example')->say();      //hello

找到ServiceProvider注册的类,直接实例化这个类来用。

【热门文章】
【热门文章】