> */ protected static $providers = []; public static function init() : void{ self::addProvider(Anvil::class); self::addProvider(McRegion::class); self::addProvider(PMAnvil::class); self::addProvider(LevelDB::class); } /** * @phpstan-param class-string $class * * @return void * @throws \InvalidArgumentException */ public static function addProvider(string $class){ 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"); } self::$providers[strtolower($class::getProviderName())] = $class; } /** * Returns a LevelProvider class for this path, or null * * @return string|null * @phpstan-return class-string|null */ public static function getProvider(string $path){ foreach(self::$providers as $provider){ /** @phpstan-var class-string $provider */ if($provider::isValid($path)){ return $provider; } } return null; } /** * Returns a LevelProvider by name, or null if not found * * @return string|null * @phpstan-return class-string|null */ public static function getProviderByName(string $name){ return self::$providers[trim(strtolower($name))] ?? null; } }