Exemplo n.º 1
0
 /**
  * @param BaseInjectionTarget $InjectionTarget
  * @return object[]
  */
 private function getServicesToInject(IInjectionTarget $InjectionTarget)
 {
     $requiredTypes = $InjectionTarget->getRequiredTypes();
     $servicesToInject = [];
     foreach ($requiredTypes as $parameterName => $requestedType) {
         try {
             $Service = $this->ServiceFactory->getService($requestedType, $this);
         } catch (ServiceNotDefined $Exception) {
             throw new TypeHintIsNotADefinedService($InjectionTarget, $parameterName, $requestedType);
         }
         $servicesToInject[] = $Service;
     }
     return $servicesToInject;
 }
Exemplo n.º 2
0
 public function run()
 {
     // Call the Loader configurator.
     $Loader = new Loader();
     $LoaderConfigurator = $this->LoaderConfigurator;
     $LoaderConfigurator($Loader);
     // Build the service definitions collection.
     $ServiceDefinitions = new ServiceDefinitions();
     // Call the service definer.
     $ServiceDefiner = $this->ServiceDefiner;
     $ServiceDefiner($ServiceDefinitions);
     // Build the service factory and the injector.
     $ServiceFactory = new ServiceFactory($ServiceDefinitions);
     $Injector = new Injector($ServiceFactory);
     // Register the Injector and the Loader as services.
     $ServiceFactory->addService(IdentifyingType::is(Type::fromName('tueena\\core\\services\\IInjector')), $Injector)->addService(IdentifyingType::is(Type::fromName('tueena\\core\\ILoader')), $Loader);
     // Call the main function.
     $MainFunction = new InjectionTargetClosure($this->MainFunction);
     $Injector->resolve($MainFunction);
 }
Exemplo n.º 3
0
 /**
  * @test
  */
 public function A_servcie_instance_can_be_added()
 {
     // given
     $ServiceDefinitions = new ServiceDefinitions();
     $Target = new ServiceFactory($ServiceDefinitions);
     // when
     $A = new A();
     $Target->addService(IdentifyingType::is(Type::fromName('tueena\\spec\\core\\stubs\\A')), $A);
     $Injector = new Injector($Target);
     // then
     $this->assertSame($A, $Target->getService(Type::fromName('tueena\\spec\\core\\stubs\\A'), $Injector));
 }