concrete = $concrete; $this->container = $container; } /** * Define the abstract target that depends on the context. * * @param string $abstract * @return $this */ public function needs($abstract) { $this->needs = $abstract; return $this; } /** * Define the implementation for the contextual binding. * * @param \Closure|string|array $implementation * @return void */ public function give($implementation) { foreach (Util::arrayWrap($this->concrete) as $concrete) { $this->container->addContextualBinding($concrete, $this->needs, $implementation); } } /** * Define tagged services to be used as the implementation for the contextual binding. * * @param string $tag * @return void */ public function giveTagged($tag) { $this->give(function ($container) use ($tag) { $taggedServices = $container->tagged($tag); return is_array($taggedServices) ? $taggedServices : iterator_to_array($taggedServices); }); } }