first(); } public static function getMorphClass(string $morphType): ?string { return Relation::$morphMap[$morphType] ?? null; } /** * 验证评论类型是否存在 * * @param string $morphType * @return void * @throws BusinessException */ public static function checkMorphType(string $morphType) { if (is_null(self::getMorphClass($morphType))) { throw new BusinessException('Morph type error!'); } } public static function instanceOf(string $morphType, $instance): bool { return get_class($instance) === self::getMorphClass($morphType); } public static function getMorphTypeOfInstance(object $instance): string { return self::getMorphType(get_class($instance)); } public static function getMorphType(string $class): string { $morphMap = Relation::$morphMap; $morphMap = array_flip($morphMap); return $morphMap[$class] ?? ''; } }