From dcfde849ce4a983bf1d97f32c546b790cd2a4d5d Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Tue, 4 Jun 2024 09:52:51 +0900 Subject: [PATCH] Add comments to `getInstance` and `factory` methods in `PackageInjector` This commit documents `getInstance` and `factory` methods in the `PackageInjector` class. The comments provide detailed information on what each method does, including its usefulness during unit testing and how instances are cached. --- src/Injector/PackageInjector.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Injector/PackageInjector.php b/src/Injector/PackageInjector.php index be90f346..b2781f4a 100644 --- a/src/Injector/PackageInjector.php +++ b/src/Injector/PackageInjector.php @@ -40,6 +40,12 @@ private function __construct() { } + /** + * Returns an instance of InjectorInterface based on the given parameters + * + * - Injector instances are cached in memory and in the cache adapter. + * - The injector is re-used in subsequent calls in the same context in the unit test. + */ public static function getInstance(AbstractAppMeta $meta, string $context, CacheInterface|null $cache): InjectorInterface { $injectorId = str_replace('\\', '_', $meta->name) . $context; @@ -60,6 +66,11 @@ public static function getInstance(AbstractAppMeta $meta, string $context, Cache return $injector; } + /** + * Return an injector instance with the given override module + * + * This is useful for testing purposes, where you want to override a module with a mock or stub + */ public static function factory(AbstractAppMeta $meta, string $context, AbstractModule|null $overrideModule = null): InjectorInterface { $scriptDir = $meta->tmpDir . '/di';