Releases: ytake/hh-container
Releases · ytake/hh-container
for hhvm3.28
fixed type
Merge pull request #12 from ytake/feature/patch-1 oops
fixed unbound name for HHVM3.26
Merge pull request #9 from ytake/fixed/hhvm3.26-unbound-name-patch fixed unbound names
0.5.1
changed async function
Merge pull request #8 from ytake/feature/added-async-resolver changed imp
added method "callable", bugfixed
callable
returns the value of a callable with parameters supplied at calltime.
final class TestingInvokable {
public function __invoke(FactoryContainer $container): int {
return 1;
}
}
$container = new \Ytake\HHContainer\FactoryContainer();
$container->set(TestingInvokable::class, $container ==>
$container->callable(
new \Ytake\HHContainer\Invokable(
new TestingInvokable(), '__invoke', $container
)
)
);
for zend expressive, and more
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