mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
LevelProviderManager: tighten up checks on registering
This commit is contained in:
parent
5d769147ca
commit
ad1cf38c21
@ -44,9 +44,18 @@ abstract class LevelProviderManager{
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function addProvider(string $class){
|
||||
if(!is_subclass_of($class, LevelProvider::class)){
|
||||
throw new \InvalidArgumentException("Class is not a subclass of LevelProvider");
|
||||
try{
|
||||
$reflection = new \ReflectionClass($class);
|
||||
}catch(\ReflectionException $e){
|
||||
throw new \InvalidArgumentException("Class $class does not exist");
|
||||
}
|
||||
if(!$reflection->implementsInterface(LevelProvider::class)){
|
||||
throw new \InvalidArgumentException("Class $class does not implement " . LevelProvider::class);
|
||||
}
|
||||
if(!$reflection->isInstantiable()){
|
||||
throw new \InvalidArgumentException("Class $class cannot be constructed");
|
||||
}
|
||||
|
||||
/** @var LevelProvider $class */
|
||||
self::$providers[strtolower($class::getProviderName())] = $class;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user