container = $container; $this->resolver = $resolver; } /** * Returns the correct builder for a value. * * @param string|class-string|mixed $id The string id to provide a builder for, or a value. * @param mixed $implementation The implementation to build the builder for. * @param string[]|null $afterBuildMethods A list of methods that should be called on the built * instance after it's been built. * @param mixed ...$buildArgs A set of arguments to pass that should be used to build * the instance, if any. * * @return BuilderInterface A builder instance. * * @throws NotFoundException If a builder cannot find its implementation target. */ public function getBuilder($id, $implementation = null, ?array $afterBuildMethods = null, ...$buildArgs) { if ($implementation === null) { $implementation = $id; } if (is_string($implementation) && is_string($id)) { if (class_exists($implementation)) { return new ClassBuilder($id, $this->resolver, $implementation, $afterBuildMethods, ...$buildArgs); } return new ValueBuilder($implementation); } if ($implementation instanceof BuilderInterface) { return $implementation; } if ($implementation instanceof Closure) { return new ClosureBuilder($this->container, $implementation); } if (is_callable($implementation)) { return new CallableBuilder($this->container, $implementation); } return new ValueBuilder($implementation); } /** * Sets the container the builder should use. * * @since TBD * * @param Container $container The container to bind. * * @return void */ public function setContainer(Container $container) { $this->container = $container; } /** * Sets the resolver the container should use. * * @since TBD * * @param Resolver $resolver The resolver the container should use. * * @return void */ public function setResolver(Resolver $resolver) { $this->resolver = $resolver; } }