/** * Create an instance of the bound type, will NOT create or re-use a scoped proxy. * * @param Binding $binding * @param InjectionPointInterface $point * @return object */ public function createInstance(Binding $binding, InjectionPointInterface $point = NULL) { switch ($binding->getOptions() & BindingInterface::MASK_TYPE) { case BindingInterface::TYPE_ALIAS: return $this->get($binding->getTarget(), $point); case BindingInterface::TYPE_FACTORY: case BindingInterface::TYPE_FACTORY_ALIAS: return $this->createObjectUsingFactory($binding, $point); default: return $this->createObject($binding->getTarget(), $binding->getResolvers(), $binding->getInitializers(), $binding->getMarkers(SetterInjection::class)); } }
/** * Compiles PHP code for the given binding. * * @param Binding $binding * @return string */ protected function compileBinding(Binding $binding) { $prop = str_replace('\\', '_', $binding->getTypeName()); $code = "\tpublic function binding_" . $prop . "() {\n\n"; $code .= "\t\t\t\$binding = new DelegateBinding(" . var_export($binding->getTypeName(), true); $code .= ', ' . var_export($binding->getScope(), true); $code .= ', ' . var_export($binding->getOptions(), true) . ', function(InjectionPointInterface $point = NULL) {' . "\n"; switch ($binding->getOptions() & BindingInterface::MASK_TYPE) { case BindingInterface::TYPE_ALIAS: $code .= "return \$this->get(" . var_export($binding->getTarget(), true) . ", \$point);\n"; break; case BindingInterface::TYPE_IMPLEMENTATION: $code .= $this->compileImplementationBinding($binding); break; case BindingInterface::TYPE_FACTORY_ALIAS: $code .= $this->compileFactoryBinding($binding); break; case BindingInterface::TYPE_FACTORY: $code .= $this->compileInlineFactoryBinding($binding); } $code .= "});\n"; $code .= "\t\treturn \$binding;\n"; $code .= "\t}\n\n"; return $code; }