Utils: fixed testValidInstance() not accepting the same valid class for both className and baseName

this caused problems in PlayerCreationEvent because plugins set the base class and then set the player class to the same thing.
This commit is contained in:
Dylan K. Taylor
2021-10-26 00:31:30 +01:00
parent 94f4ef5862
commit 4178c81209

View File

@@ -519,12 +519,10 @@ final class Utils{
if(!class_exists($className)){ if(!class_exists($className)){
throw new \InvalidArgumentException("Class $className does not exist"); throw new \InvalidArgumentException("Class $className does not exist");
} }
$base = new \ReflectionClass($baseName); if(!is_a($className, $baseName, true)){
$class = new \ReflectionClass($className); throw new \InvalidArgumentException("Class $className does not extend or implement $baseName");
if(!$class->isSubclassOf($baseName)){
throw new \InvalidArgumentException("Class $className does not " . ($base->isInterface() ? "implement" : "extend") . " " . $baseName);
} }
$class = new \ReflectionClass($className);
if(!$class->isInstantiable()){ if(!$class->isInstantiable()){
throw new \InvalidArgumentException("Class $className cannot be constructed"); throw new \InvalidArgumentException("Class $className cannot be constructed");
} }