data = new BindingData(); $this->binder = new Binder($this->data); } /** * Bind an interface to an implementation. * * @param string $key An interface or interface with a parameter name (`Interface $name`). * @param string $implementationClassName An implementation class name. */ public function bindImplementation(string $key, string $implementationClassName): self { $this->binder->bindImplementation($key, $implementationClassName); return $this; } /** * Bind an interface to a specific service. * * @param string $key An interface or interface with a parameter name (`Interface $name`). * @param string $serviceName A service name. */ public function bindService(string $key, string $serviceName): self { $this->binder->bindService($key, $serviceName); return $this; } /** * Bind an interface to a callback. * * @param string $key An interface or interface with a parameter name (`Interface $name`). * @param callable $callback A callback that will resolve a dependency. */ public function bindCallback(string $key, callable $callback): self { $this->binder->bindCallback($key, $callback); return $this; } /** * Bind an interface to a specific instance. * * @param string $key An interface or interface with a parameter name (`Interface $name`). * @param object $instance An instance. */ public function bindInstance(string $key, object $instance): self { $this->binder->bindInstance($key, $instance); return $this; } /** * Bind an interface to a factory. * * @param string $key An interface or interface with a parameter name (`Interface $name`). * @param string $factoryClassName A factory class name. */ public function bindFactory(string $key, string $factoryClassName): self { $this->binder->bindFactory($key, $factoryClassName); return $this; } /** * Creates a contextual binder and pass it as an argument of a callback. * * @param string $className A context. * @param Closure(ContextualBinder): void $callback A callback with a `ContextualBinder` argument. */ public function inContext(string $className, Closure $callback): self { $contextualBinder = new ContextualBinder($this->data, $className); $callback($contextualBinder); return $this; } /** * Build. */ public function build(): BindingContainer { return new BindingContainer($this->data); } /** * Create an instance. */ public static function create(): self { return new self(); } }