Skip to content

Commit

Permalink
Add comments to getInstance and factory methods in PackageInjector
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
koriym committed Jun 4, 2024
1 parent 483e717 commit dcfde84
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Injector/PackageInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';
Expand Down

0 comments on commit dcfde84

Please sign in to comment.