Skip to content

Commit

Permalink
Merge pull request #8744 from kenjis/fix-Factories-cannot-get-defined…
Browse files Browse the repository at this point in the history
…-class

fix: Factories::get() cannot get defined classes
  • Loading branch information
kenjis authored Apr 11, 2024
2 parents e14e145 + ca66cb7 commit 48be4ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion system/Config/Factories.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ public static function get(string $component, string $alias): ?object
if (isset(self::$aliases[$component][$alias])) {
$class = self::$aliases[$component][$alias];

return self::$instances[$component][$class];
if (isset(self::$instances[$component][$class])) {
return self::$instances[$component][$class];
}
}

return self::__callStatic($component, [$alias]);
Expand Down
13 changes: 13 additions & 0 deletions tests/system/Config/FactoriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,19 @@ public function testDefineAndLoad(): void
$this->assertInstanceOf(EntityModel::class, $model);
}

public function testDefineAndGet(): void
{
Factories::define(
'models',
UserModel::class,
EntityModel::class
);

$model = Factories::get('models', UserModel::class);

$this->assertInstanceOf(EntityModel::class, $model);
}

public function testGetComponentInstances()
{
Factories::config('App');
Expand Down

0 comments on commit 48be4ac

Please sign in to comment.