-
-
Notifications
You must be signed in to change notification settings - Fork 72
Closed
Description
Version: 3.2.1
Bug Description
The Nette\DI\Container
allows the addition of a service as a static factory. All operations can handle this except the Container::getByType
method, which fails when creating a reflection over a non-existent container method.
Steps To Reproduce
class Service {
}
$container = new Nette\DI\Container\Container();
$container->addService('fromStaticFactory', static fn(): Service => new Service());
$container->getByType(Service::class)
Expected Behavior
There should be no exception when attempting to access a non-existent method.
Possible Solution
Use reflection of the method given in $foo
Lines 261 to 262 in 9c4af52
foreach ($this->methods as $method => $foo) { | |
$methodType = (new \ReflectionMethod(static::class, $method))->getReturnType()->getName(); |
Something like this:
foreach ($this->metohds as $method) {
$methodType = \Nette\Utils\Callback::toReflection($method)->getReturnType()->getName();
if (is_a($methodType, $type, allow_string: true)) {
throw new MissingServiceException(sprintf(
"Service of type %s is not autowired or is missing in di\u{a0}›\u{a0}export\u{a0}›\u{a0}types.",
$type,
));
}
}
Metadata
Metadata
Assignees
Labels
No labels