the browser-facing portion of osu!
at master 2.1 kB view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6namespace App\Libraries; 7 8use App\Models\BeatmapDiscussion; 9use App\Models\BeatmapDiscussionPost; 10use App\Models\Beatmapset; 11use App\Models\Build; 12use App\Models\Chat\Channel; 13use App\Models\Chat\Message; 14use App\Models\Comment; 15use App\Models\Forum; 16use App\Models\LegacyMatch; 17use App\Models\Multiplayer\ScoreLink as MultiplayerScoreLink; 18use App\Models\NewsPost; 19use App\Models\Score; 20use App\Models\Solo; 21use App\Models\User; 22 23class MorphMap 24{ 25 const MAP = [ 26 BeatmapDiscussion::class => 'beatmapset_discussion', 27 BeatmapDiscussionPost::class => 'beatmapset_discussion_post', 28 Beatmapset::class => 'beatmapset', 29 Build::class => 'build', 30 Channel::class => 'channel', 31 Comment::class => 'comment', 32 Forum\Post::class => 'forum_post', 33 Forum\Topic::class => 'forum_topic', 34 LegacyMatch\Score::class => 'legacy_match_score', 35 Message::class => 'message', 36 MultiplayerScoreLink::class => 'multiplayer_score_link', 37 NewsPost::class => 'news_post', 38 Score\Best\Fruits::class => 'score_best_fruits', 39 Score\Best\Mania::class => 'score_best_mania', 40 Score\Best\Osu::class => 'score_best_osu', 41 Score\Best\Taiko::class => 'score_best_taiko', 42 Score\Fruits::class => 'score_fruits', 43 Score\Mania::class => 'score_mania', 44 Score\Osu::class => 'score_osu', 45 Score\Taiko::class => 'score_taiko', 46 Solo\Score::class => 'solo_score', 47 User::class => 'user', 48 ]; 49 50 public static function getType($class) 51 { 52 if (is_object($class)) { 53 $class = get_class($class); 54 } 55 56 return static::MAP[$class] ?? null; 57 } 58 59 public static function getClass($type) 60 { 61 return static::flippedMap()[$type] ?? null; 62 } 63 64 public static function flippedMap() 65 { 66 static $ret; 67 68 return $ret ??= array_flip(static::MAP); 69 } 70}