Home > Backend Development > PHP Tutorial > How to register a service provider using Illuminate for non-Laravel projects?!

How to register a service provider using Illuminate for non-Laravel projects?!

WBOY
Release: 2016-08-04 09:20:38
Original
1069 people have browsed it

How to register a service provider using Illuminate for non-Laravel projects?!

Reply content:

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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template