dependency component version up
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