/**
  * @test
  */
 public function namedConstructorInjectionWithMultipleParamAndOneNamedConstantParam()
 {
     $binder = new Binder();
     $binder->bindConstant('boss')->to('role:boss');
     $binder->bind(Employee::class)->to(TeamMember::class);
     $injector = $binder->getInjector();
     $group = $injector->getInstance(DevelopersMultipleConstructorParamsWithConstant::class);
     assert($group, equals(new DevelopersMultipleConstructorParamsWithConstant(new TeamMember(), 'role:boss')));
 }
 /**
  * @since  2.1.0
  * @test
  * @group  issue_31
  */
 public function injectConstantViaClosure()
 {
     $binder = new Binder();
     $binder->bindConstant('answer')->toClosure(function () {
         return 42;
     });
     $this->assertConstantInjection($binder->getInjector());
 }
 /**
  * @test
  */
 public function mixedAnnotations()
 {
     $plugin = NewInstance::of(Plugin::class);
     $binder = new Binder();
     $binder->bindList('listConfig');
     $binder->bindMap('mapConfig');
     $binder->bind(Plugin::class)->named('foo')->toInstance($plugin);
     $binder->bindConstant('foo')->to(42);
     $binder->bindList('aList')->withValue(313);
     $binder->bindMap('aMap')->withEntry('tb', 303);
     assert($this->createPluginHandler($binder)->getArgs(), equals(['std' => $plugin, 'answer' => 42, 'list' => [313], 'map' => ['tb' => 303]]));
 }
Example #4
0
 /**
  * configure the binder
  *
  * @param  \stubbles\ioc\Binder  $binder
  * @param  string                $projectPath  optional  project base path
  */
 public function configure(Binder $binder, string $projectPath = null)
 {
     $this->environment->registerErrorHandler($projectPath);
     $this->environment->registerExceptionHandler($projectPath);
     $binder->setEnvironment($this->environment->name())->bind(Environment::class)->toInstance($this->environment);
     if (file_exists($this->propertiesFile($projectPath))) {
         $binder->bindPropertiesFromFile($this->propertiesFile($projectPath), $this->environment->name());
     }
     $binder->bindConstant('stubbles.project.path')->to($projectPath);
     foreach ($this->buildPathes($projectPath) as $name => $value) {
         $binder->bindConstant($name)->to($value);
     }
 }