|
15 | 15 | */ |
16 | 16 | // This processes github webhooks |
17 | 17 | Flight::route( |
18 | | - 'POST /update-stuff', |
19 | | - [DocsController::class, 'updateStuffPost'], |
20 | | - false, |
21 | | - 'update_stuff' |
| 18 | + pattern: 'POST /update-stuff', |
| 19 | + callback: [DocsController::class, 'updateStuffPost'], |
| 20 | + alias: 'update_stuff' |
22 | 21 | ); |
23 | 22 |
|
24 | 23 | /* |
25 | 24 | * Redirects |
26 | 25 | */ |
27 | | - // if theres no language or version in the url, redirect and default to en and v3 |
| 26 | + // if theres no language or version in the url, redirect and default to en |
| 27 | + // and v3 |
28 | 28 | Flight::route('/', static function (): void { |
29 | 29 | // pull out the default language by the accept header |
30 | 30 | $language = Translator::getLanguageFromRequest(); |
31 | | - Flight::redirect('/' . $language . '/v3/'); |
| 31 | + |
| 32 | + Flight::redirect("/$language/v3/"); |
32 | 33 | }); |
33 | 34 |
|
34 | 35 | // If the route only defines a language (ex: /en) redirect with a version |
35 | | - Flight::route('/@language:[a-z0-9]{2}', static function (string $language): void { |
36 | | - // if there's a number in it, it's actually probably the version so we'll need to pull the language out and consider this a version |
37 | | - if (preg_match('/\d/', $language) === 1) { |
38 | | - $version = $language; |
39 | | - $language = Translator::getLanguageFromRequest(); |
40 | | - Flight::redirect("/en/$language/"); |
41 | | - } else { |
42 | | - $version = 'v3'; |
| 36 | + Flight::route( |
| 37 | + '/@language:[a-z0-9]{2}', |
| 38 | + static function (string $language): void { |
| 39 | + // if there's a number in it, it's actually probably the version so |
| 40 | + // we'll need to pull the language out and consider this a version |
| 41 | + $version = preg_match('/\d/', $language) ? $language : 'v3'; |
| 42 | + |
| 43 | + if (preg_match('/\d/', $language)) { |
| 44 | + $language = Translator::getLanguageFromRequest(); |
| 45 | + Flight::redirect("/en/$language/"); |
| 46 | + } |
| 47 | + |
| 48 | + Flight::redirect("/$language/$version/"); |
43 | 49 | } |
44 | | - Flight::redirect("/$language/$version/"); |
45 | | - }); |
| 50 | + ); |
46 | 51 |
|
47 | 52 | // Pick up old routes that didn't use to have a language and version header |
48 | | - Flight::route('/@section:[\w\-]{3,}(/@sub_section:[\w\-]{3,})', function (string $section, ?string $sub_section = ''): void { |
49 | | - $language = Translator::getLanguageFromRequest(); |
50 | | - Flight::redirect("/{$language}/v3/$section/$sub_section/"); |
51 | | - }); |
| 53 | + Flight::route( |
| 54 | + '/@section:[\w\-]{3,}(/@sub_section:[\w\-]{3,})', |
| 55 | + static function (string $section, ?string $sub_section = ''): void { |
| 56 | + $language = Translator::getLanguageFromRequest(); |
| 57 | + |
| 58 | + Flight::redirect("/$language/v3/$section/$sub_section/"); |
| 59 | + } |
| 60 | + ); |
52 | 61 |
|
53 | 62 | /* |
54 | 63 | * Core routes |
55 | 64 | */ |
56 | | - Flight::group('/@language:[a-z]{2}/@version:[a-z0-9]{2}', static function (): void { |
57 | | - Flight::route('GET /', [DocsController::class, 'aboutGet'], false, 'about'); |
58 | | - Flight::route('GET /single-page', [DocsController::class, 'singlePageGet'], false, 'single_page'); |
59 | | - Flight::route('GET /about', [DocsController::class, 'aboutGet']); |
60 | | - Flight::route('GET /install', [DocsController::class, 'installGet'], false, 'install'); |
61 | | - |
62 | | - // Unique URL workaround because this is the only 'single page' with a scrollspy for the time being. |
63 | | - Flight::route('GET /install/install', static function (): void { |
64 | | - Flight::redirect(Flight::getUrl('install')); |
65 | | - }); |
66 | | - |
67 | | - Flight::route('GET /license', [DocsController::class, 'licenseGet'], false, 'license'); |
68 | | - Flight::route('GET /examples', [DocsController::class, 'examplesGet'], false, 'examples'); |
69 | | - Flight::route('GET /media', [DocsController::class, 'mediaGet'], false, 'media'); |
70 | | - Flight::route('GET /search', [DocsController::class, 'searchGet'], false, 'search'); |
71 | | - |
72 | | - Flight::group('/learn', static function (): void { |
73 | | - Flight::route('GET ', [DocsController::class, 'learnGet'], false, 'learn'); |
74 | | - Flight::route('GET /@section_name', [DocsController::class, 'learnSectionsGet']); |
75 | | - }); |
76 | | - |
77 | | - Flight::group('/guides', static function (): void { |
78 | | - Flight::route('GET ', [DocsController::class, 'guidesGet'], false, 'guides'); |
79 | | - Flight::route('GET /@section_name', [DocsController::class, 'guidesSectionsGet']); |
80 | | - }); |
81 | | - |
82 | | - Flight::group('/awesome-plugins', static function (): void { |
83 | | - Flight::route('GET ', [DocsController::class, 'awesomePluginsGet'], false, 'awesome_plugins'); |
84 | | - Flight::route('GET /@plugin_name', [DocsController::class, 'pluginGet'], false, 'plugin'); |
85 | | - }); |
86 | | - }); |
| 65 | + Flight::group( |
| 66 | + '/@language:[a-z]{2}/@version:[a-z0-9]{2}', |
| 67 | + static function (): void { |
| 68 | + Flight::route( |
| 69 | + pattern: 'GET /', |
| 70 | + callback: [DocsController::class, 'aboutGet'], |
| 71 | + alias: 'about' |
| 72 | + ); |
| 73 | + |
| 74 | + Flight::route( |
| 75 | + pattern: 'GET /single-page', |
| 76 | + callback: [DocsController::class, 'singlePageGet'], |
| 77 | + alias: 'single_page' |
| 78 | + ); |
| 79 | + |
| 80 | + Flight::route('GET /about', [DocsController::class, 'aboutGet']); |
| 81 | + |
| 82 | + Flight::route( |
| 83 | + pattern: 'GET /install', |
| 84 | + callback: [DocsController::class, 'installGet'], |
| 85 | + alias: 'install' |
| 86 | + ); |
| 87 | + |
| 88 | + // Unique URL workaround because this is the only 'single page' |
| 89 | + // with a scrollspy for the time being. |
| 90 | + Flight::route('GET /install/install', static function (): void { |
| 91 | + Flight::redirect(Flight::getUrl('install')); |
| 92 | + }); |
| 93 | + |
| 94 | + Flight::route( |
| 95 | + pattern: 'GET /license', |
| 96 | + callback: [DocsController::class, 'licenseGet'], |
| 97 | + alias: 'license' |
| 98 | + ); |
| 99 | + |
| 100 | + Flight::route( |
| 101 | + pattern: 'GET /examples', |
| 102 | + callback: [DocsController::class, 'examplesGet'], |
| 103 | + alias: 'examples' |
| 104 | + ); |
| 105 | + |
| 106 | + Flight::route( |
| 107 | + pattern: 'GET /media', |
| 108 | + callback: [DocsController::class, 'mediaGet'], |
| 109 | + alias: 'media' |
| 110 | + ); |
| 111 | + |
| 112 | + Flight::route( |
| 113 | + pattern: 'GET /search', |
| 114 | + callback: [DocsController::class, 'searchGet'], |
| 115 | + alias: 'search' |
| 116 | + ); |
| 117 | + |
| 118 | + Flight::group('/learn', static function (): void { |
| 119 | + Flight::route( |
| 120 | + pattern: 'GET ', |
| 121 | + callback: [DocsController::class, 'learnGet'], |
| 122 | + alias: 'learn' |
| 123 | + ); |
| 124 | + |
| 125 | + Flight::route( |
| 126 | + 'GET /@section_name', |
| 127 | + [DocsController::class, 'learnSectionsGet'] |
| 128 | + ); |
| 129 | + }); |
| 130 | + |
| 131 | + Flight::group('/guides', static function (): void { |
| 132 | + Flight::route( |
| 133 | + pattern: 'GET /', |
| 134 | + callback: [DocsController::class, 'guidesGet'], |
| 135 | + alias: 'guides' |
| 136 | + ); |
| 137 | + |
| 138 | + Flight::route( |
| 139 | + 'GET /@section_name', |
| 140 | + [DocsController::class, 'guidesSectionsGet'] |
| 141 | + ); |
| 142 | + }); |
| 143 | + |
| 144 | + Flight::group('/awesome-plugins', static function (): void { |
| 145 | + Flight::route( |
| 146 | + pattern: 'GET /', |
| 147 | + callback: [DocsController::class, 'awesomePluginsGet'], |
| 148 | + alias: 'awesome_plugins' |
| 149 | + ); |
| 150 | + |
| 151 | + Flight::route( |
| 152 | + pattern: 'GET /@plugin_name', |
| 153 | + callback: [DocsController::class, 'pluginGet'], |
| 154 | + alias: 'plugin' |
| 155 | + ); |
| 156 | + }); |
| 157 | + } |
| 158 | + ); |
87 | 159 | }, [HeaderSecurityMiddleware::class]); |
88 | 160 |
|
89 | 161 | /* |
|
95 | 167 |
|
96 | 168 | // pull the version out of the URL |
97 | 169 | $url = Flight::request()->url; |
98 | | - $version = preg_match('~/(v\d)/~', $url, $matches) === 1 ? $matches[1] : 'v3'; |
| 170 | + $version = preg_match('~/(v\d)/~', $url, $matches) ? $matches[1] : 'v3'; |
99 | 171 |
|
100 | 172 | (new Container)->get(DocsLogic::class)->renderPage('not_found.latte', [ |
101 | 173 | 'title' => '404 Not Found', |
102 | 174 | 'version' => $version |
103 | 175 | ]); |
104 | 176 |
|
105 | 177 | Flight::response()->send(); |
106 | | - |
107 | | - exit; |
108 | 178 | }); |
0 commit comments