From fca3d05d0b9c06e4fec8a39bb12ecfd94575285c Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Thu, 30 Nov 2023 09:03:26 -0500 Subject: [PATCH] Add generics Adds generics so `$container->get(Foo::class)` returns a `Foo` instance --- framework/di/Container.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/framework/di/Container.php b/framework/di/Container.php index 25626c54751..5b63ca4f9d4 100644 --- a/framework/di/Container.php +++ b/framework/di/Container.php @@ -145,7 +145,8 @@ class Container extends Component * In this case, the constructor parameters and object configurations will be used * only if the class is instantiated the first time. * - * @param string|Instance $class the class Instance, name, or an alias name (e.g. `foo`) that was previously + * @template T + * @param class-string|Instance $class the class Instance, name, or an alias name (e.g. `foo`) that was previously * registered via [[set()]] or [[setSingleton()]]. * @param array $params a list of constructor parameter values. Use one of two definitions: * - Parameters as name-value pairs, for example: `['posts' => PostRepository::class]`. @@ -154,7 +155,7 @@ class Container extends Component * parameter list. * Dependencies indexed by name and by position in the same array are not allowed. * @param array $config a list of name-value pairs that will be used to initialize the object properties. - * @return object an instance of the requested class. + * @return T an instance of the requested class. * @throws InvalidConfigException if the class cannot be recognized or correspond to an invalid definition * @throws NotInstantiableException If resolved to an abstract class or an interface (since 2.0.9) */