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

每天laravel-20160805| Container -8

2016-05-13 09:11 316 查看
/**
* Assign a set of tags to a given binding.
*
* @param  array|string  $abstracts
* @param  array|mixed   ...$tags
* @return void
*/
public function tag($abstracts, $tags)
{// Assign a set of tags to a given binding.
$tags = is_array($tags) ? $tags : array_slice(func_get_args(), 1);
// get the first args
foreach ($tags as $tag) {// foreach $tags to $tag
if (! isset($this->tags[$tag])) {
$this->tags[$tag] = [];
}// check it is set, so set it  like init it.

foreach ((array) $abstracts as $abstract) {
$this->tags[$tag][] = $this->normalize($abstract);
}// if the abstracts is array, we  ge we want insert into the array.
}
}// the function has two parameter one is tag another is abstracts
// so last we set the $this->tags, bay tags and abstracts

/**
* Resolve all of the bindings for a given tag.
*
* @param  string  $tag
* @return array
*/
public function tagged($tag)// like get all the callback binding for a given tag.
{
$results = [];// set a store by array

if (isset($this->tags[$tag])) {// i know why set the tag by tag function
foreach ($this->tags[$tag] as $abstract) {// get the abstract
$results[] = $this->make($abstract);// this->make the function like function.
}
}

return $results;// return store array
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: