Commit 4bc4fb02 authored by Mathias Brodala's avatar Mathias Brodala Committed by Georg Ringer
Browse files

[TASK] Let GeneralUtility::makeInstance() throw exception on unknown class

Change-Id: I9e5a04c3ef0ee8fed53d22df4d6ea472266145e7
Resolves: #82131
Releases: master, 8.7
Reviewed-on: https://review.typo3.org/53731

Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: default avatarDaniel Goerz <ervaude@gmail.com>
Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
parent c384ce07
......@@ -3487,6 +3487,9 @@ class GeneralUtility
) {
return array_shift(self::$nonSingletonInstances[$finalClassName]);
}
if (!class_exists($finalClassName)) {
throw new \InvalidArgumentException('Class "' . $className . '" not found', 1503060454);
}
// Create new instance and call constructor with parameters
$instance = new $finalClassName(...$constructorArguments);
// Register new singleton instance
......
......@@ -3771,6 +3771,31 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
GeneralUtility::makeInstance(['foo']);
}
/**
* @test
*/
public function makeInstanceWithUnknownClassThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionCode(1503060454);
GeneralUtility::makeInstance('UnknownClass' . time());
}
/**
* @test
*/
public function makeInstanceWithUnknownClassImplementationThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionCode(1503060454);
GeneralUtilityFixture::resetFinalClassNameCache();
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][OriginalClassFixture::class] = ['className' => 'UnknownClass' . time()];
GeneralUtility::makeInstance(OriginalClassFixture::class);
}
/**
* @test
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment