您的位置:首页 > 编程语言 > PHP开发

[李景山php]每天laravel[031]-laravel 基础知识 --- 服务容器

2017-04-06 09:39 681 查看
1 Service 容器: 利用了 反射服务。

2 使用 $this->app->bind(); 方法进行绑定,然后利用匿名函数执行。

function($app){return new HelpSpot\API('$app['HttpClient']');}


3 利用 this−>app−>singleton();方法进行绑定。4利用this->app->instance();方式进行 绑定一个 instances 实例。

5 绑定接口到组件

$this->app->bind('App\Contracts\EventPusher','App\Services\RedisEventPusher');
进行

6 支持上下文绑定

$this->app->when('App\Handler\Commands\CreateOrderHandler')
->needs('App\Contracts\EventPusher')
->give('App\Services\PubNubEventPuseher');


// 或者可以使用匿名函数

->give(function(){
//TODO
});


7 支持绑定后标签定义,跟别名应该差不多。

8
$this->app->tag(['SpeedReport',''],'reports');


9 解决方案$this->app->make(‘FooBar’);

10 容器事件,添加监听事件。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php 函数 api singleton
相关文章推荐