public function addToInjector(Injector $injector) { foreach ($this->shares as $share) { $injector->share($share); } foreach ($this->aliases as $original => $alias) { $injector->alias($original, $alias); } foreach ($this->definitions as $name => $args) { $injector->define($name, $args); } foreach ($this->params as $param => $value) { $injector->defineParam($param, $value); } foreach ($this->delegates as $param => $callable) { $injector->delegate($param, $callable); } foreach ($this->prepares as $class => $callable) { $injector->prepare($class, $callable); } }
function createControl(PageInfo $pageInfo, Injector $injector) { list($controlClassname, $params) = CategoryInfo::getDIInfo($pageInfo); foreach ($params as $name => $value) { $injector->defineParam($name, $value); } $control = $injector->make($controlClassname); $params = $control->getFullParams(); foreach ($params as $name => $value) { $injector->defineParam($name, $value); } return $control; }
/** * @param \Auryn\Injector $injector * @param $customImageFunction * @param \ImagickDemo\Example $exampleController * @param \ImagickDemo\Control $control * @return mixed * @throws \Exception */ function getCustomImageResponse(CategoryNav $categoryNav, \Auryn\Injector $injector, $customImageFunction, \ImagickDemo\Example $exampleController, \ImagickDemo\Control $control) { $injector->defineParam('imageFunction', $customImageFunction); $params = $control->getFullParams($exampleController->getCustomImageParams()); $defaultCustomParams = array('customImage' => true); $params = array_merge($defaultCustomParams, $params); return $this->getImageResponseInternal($categoryNav, $injector, $params); }
/** * */ public function execute() { //Figure out what Command was requested. try { $parsedCommand = $this->console->parseCommandLine(); } catch (ConfiguratorException $ce) { echo "Problem running configuration: " . $ce->getMessage(); exit(-1); } catch (\Exception $e) { //@TODO change to just catch parseException when that's implemented $output = new BufferedOutput(); $this->console->renderException($e, $output); echo $output->fetch(); exit(-1); } //Run the command requested, or the help callable if no command was input try { $output = $parsedCommand->getOutput(); $formatter = $output->getFormatter(); $formatter->setStyle('question', new OutputFormatterStyle('blue')); $formatter->setStyle('info', new OutputFormatterStyle('blue')); $questionHelper = new QuestionHelper(); $questionHelper->setHelperSet($this->console->getHelperSet()); // We currently have no config, so fine to create this directly. $injector = new Injector(); $injector->alias('Configurator\\Writer', 'Configurator\\Writer\\FileWriter'); $injector->defineParam('originalArgs', $this->originalArgs); foreach ($parsedCommand->getParams() as $key => $value) { $injector->defineParam($key, $value); } $injector->execute($parsedCommand->getCallable()); } catch (ConfiguratorException $ce) { echo "Error running task: \n"; echo $ce->getMessage(); exit(-1); } catch (\Exception $e) { echo "Unexpected exception of type " . get_class($e) . " running configurator`: " . $e->getMessage() . PHP_EOL; echo $e->getTraceAsString(); exit(-2); } }
public function testTypelessDefineForAliasedDependency() { $injector = new Injector(); $injector->defineParam('val', 42); $injector->alias('Auryn\\Test\\TestNoExplicitDefine', 'Auryn\\Test\\ProviderTestCtorParamWithNoTypehintOrDefault'); $obj = $injector->make('Auryn\\Test\\ProviderTestCtorParamWithNoTypehintOrDefaultDependent'); }
function addInjectionParams(Injector $injector, Tier $tier) { $injectionParams = $tier->getInjectionParams(); if (!$injectionParams) { return; } foreach ($injectionParams->getAliases() as $original => $alias) { $injector->alias($original, $alias); } foreach ($injectionParams->getShares() as $share) { $injector->share($share); } foreach ($injectionParams->getParams() as $paramName => $value) { $injector->defineParam($paramName, $value); } foreach ($injectionParams->getDelegates() as $className => $callable) { $injector->delegate($className, $callable); } }