/**
* 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
}
每天laravel-20160805| Container -8
最新推荐文章于 2022-05-14 14:26:58 发布