当前位置:Gxlcms > PHP教程 > 非laravel项目使用Illuminate怎么注册服务提供者?!

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

时间:2021-07-01 10:21:17 帮助过:40人阅读

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

回复内容:

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

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

可以参考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

人气教程排行