How to register a service provider using Illuminate for non-Laravel projects?!
How to register a service provider using Illuminate for non-Laravel projects?!
Find the class registered by ServiceProvider and instantiate this class directly for use.
You can refer to laravel’s implementation:
IlluminateFoundationApplication
<code>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 </code>