コード例 #1
0
ファイル: Injector.php プロジェクト: tueena/core
 /**
  * @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;
 }
コード例 #2
0
ファイル: Application.php プロジェクト: tueena/core
 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);
 }
コード例 #3
0
ファイル: ServiceFactoryTest.php プロジェクト: tueena/core
 /**
  * @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));
 }