Skip to content

dependency component version up

Compare
Choose a tag to compare
@ytake ytake released this 31 Oct 17:22
· 24 commits to master since this release
5a7bfce

usage

Dependency Injection

set parameters

$container->parameters(string className, 'parameter name', function ($container) {
  return 'parameter value';
});

sample class

final class MessageClass {
  public function __construct(protected string $message) {
  }
  public function message(): string {
    return $this->message;
  }
}

final class MessageClient {
  public function __construct(protected MessageClass $message) {

  }
  public function message(): MessageClass {
    return $this->message;
  }
}

Inject

$container = new \Headacke\FactoryContainer();
$container->set('message.class', function ($container) {
  return new MessageClass('testing');
});
$container->parameters(MessageClient::class, 'message', function ($container) {
  return $container->get('message.class');
});
$instance = $container->get(MessageClient::class);

not supported auto wiring