/** * Generates an argument array ready to be used in running the * callback from the given DependencyList instance and the * {@see $args} class property. * * Loops through {@see $args} class property and changes each * instance of Reference into an instantiated dependency instance * retrieved from the provided DependencyList. * * @param DependencyList $dependencyList * @return array Arguments array ready to be used for running the * callback. * */ protected function generateCallbackArguments(DependencyList $dependencyList) { $callbackArgs = array(); foreach ($this->args as $value) { if ($value instanceof Reference) { $callbackArgs[] = $dependencyList->getInstantiatedDependency($value); continue; } $callbackArgs[] = $value; } return $callbackArgs; }
/** * Wire the dependencies provided to the object, returning the * instantiated object. * * Get the provider instance from the dependency list and run the * {@see ProviderInterface::get()} method. * * @throws RuntimeException When the provider instance doesn't * implement ProviderInterface, also when the provider * doesn't return the appropriate class. * @param DependencyList $dependencyList The dependency list of * this class, with all dependencies fulfilled. * @return mixed The object that this injector is supposed to * instantiate. * */ public function inject(DependencyList $dependencyList) { $provider = $dependencyList->getInstantiatedDependency($this->providerReference); if ($provider instanceof ProviderInterface == FALSE) { $id = $this->reference->getID(); throw new RuntimeException("ProviderClassInjector error when trying to instantiate '{$id}'. The provider object does not implement Carrot\\DependencyInjection\\Injector\\ProviderInterface."); } $object = $provider->get(); return $object; }
/** * Wire the dependencies provided to the object, returning the * instantiated object. * * @param DependencyList $dependencyList The dependency list of * this class, with all dependencies fulfilled. * @return mixed The object that this injector is supposed to * instantiate. * */ public function inject(DependencyList $dependencyList) { return $dependencyList->getInstantiatedDependency($this->referredReference); }