|
4 | 4 | use app\middleware\HeaderSecurityMiddleware; |
5 | 5 | use app\utils\DocsLogic; |
6 | 6 | use app\utils\Translator; |
7 | | -use app\utils\CustomEngine; |
| 7 | +use flight\Container; |
8 | 8 | use flight\net\Router; |
9 | 9 |
|
10 | | -/** @var CustomEngine $app */ |
11 | | -/** @var Router $router */ |
12 | | - |
13 | 10 | Flight::route('GET /api/status', static fn() => Flight::json(['status' => 'ok'])); |
14 | 11 |
|
15 | 12 | // This acts like a global middleware |
16 | | -$router->group('', function (Router $router) use ($app) { |
17 | | - |
| 13 | +Flight::group('', static function (): void { |
18 | 14 | /* |
19 | 15 | * Specific routes |
20 | 16 | */ |
21 | 17 | // This processes github webhooks |
22 | | - $router->post('/update-stuff', [DocsController::class, 'updateStuffPost'], false, 'update_stuff'); |
| 18 | + Flight::route( |
| 19 | + 'POST /update-stuff', |
| 20 | + [DocsController::class, 'updateStuffPost'], |
| 21 | + false, |
| 22 | + 'update_stuff' |
| 23 | + ); |
23 | 24 |
|
24 | 25 | /* |
25 | 26 | * Redirects |
26 | 27 | */ |
27 | 28 | // if theres no language or version in the url, redirect and default to en and v3 |
28 | | - $app->route('/', function () use ($app) { |
| 29 | + Flight::route('/', static function (): void { |
29 | 30 | // pull out the default language by the accept header |
30 | 31 | $language = Translator::getLanguageFromRequest(); |
31 | | - $app->redirect('/'.$language.'/v3/'); |
| 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 | | - $app->route('/@language:[a-z0-9]{2}', function (string $language) use ($app): void { |
| 36 | + Flight::route('/@language:[a-z0-9]{2}', static function (string $language): void { |
36 | 37 | // 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 | 38 | if (preg_match('/\d/', $language) === 1) { |
38 | 39 | $version = $language; |
39 | 40 | $language = Translator::getLanguageFromRequest(); |
40 | | - $app->redirect("/en/$language/"); |
| 41 | + Flight::redirect("/en/$language/"); |
41 | 42 | } else { |
42 | 43 | $version = 'v3'; |
43 | 44 | } |
44 | | - $app->redirect("/$language/$version/"); |
| 45 | + Flight::redirect("/$language/$version/"); |
45 | 46 | }); |
46 | 47 |
|
47 | 48 | // Pick up old routes that didn't use to have a language and version header |
48 | | - $app->route('/@section:[\w\-]{3,}(/@sub_section:[\w\-]{3,})', function (string $section, ?string $sub_section = '') use ($app): void { |
| 49 | + Flight::route('/@section:[\w\-]{3,}(/@sub_section:[\w\-]{3,})', function (string $section, ?string $sub_section = ''): void { |
49 | 50 | $language = Translator::getLanguageFromRequest(); |
50 | | - $app->redirect("/{$language}/v3/$section/$sub_section/"); |
| 51 | + Flight::redirect("/{$language}/v3/$section/$sub_section/"); |
51 | 52 | }); |
52 | 53 |
|
53 | 54 | /* |
54 | 55 | * Core routes |
55 | 56 | */ |
56 | | - $app->group('/@language:[a-z]{2}/@version:[a-z0-9]{2}', function (Router $router) use ($app): void { |
57 | | - $router->get('/', [DocsController::class, 'aboutGet'], false, 'about'); |
58 | | - $router->get('/single-page', [DocsController::class, 'singlePageGet'], false, 'single_page'); |
59 | | - $router->get('/about', [DocsController::class, 'aboutGet']); |
60 | | - $router->get('/install', [DocsController::class, 'installGet'], false, 'install'); |
| 57 | + Flight::group('/@language:[a-z]{2}/@version:[a-z0-9]{2}', static function (): void { |
| 58 | + Flight::route('GET /', [DocsController::class, 'aboutGet'], false, 'about'); |
| 59 | + Flight::route('GET /single-page', [DocsController::class, 'singlePageGet'], false, 'single_page'); |
| 60 | + Flight::route('GET /about', [DocsController::class, 'aboutGet']); |
| 61 | + Flight::route('GET /install', [DocsController::class, 'installGet'], false, 'install'); |
61 | 62 |
|
62 | 63 | // Unique URL workaround because this is the only 'single page' with a scrollspy for the time being. |
63 | | - $router->get('/install/install', function () use ($app): void { |
64 | | - $app->redirect($app->getUrl('install')); |
| 64 | + Flight::route('GET /install/install', static function (): void { |
| 65 | + Flight::redirect(Flight::getUrl('install')); |
65 | 66 | }); |
66 | 67 |
|
67 | | - $router->get('/license', [DocsController::class, 'licenseGet'], false, 'license'); |
68 | | - $router->get('/examples', [DocsController::class, 'examplesGet'], false, 'examples'); |
69 | | - $router->get('/media', [DocsController::class, 'mediaGet'], false, 'media'); |
70 | | - $router->get('/search', [DocsController::class, 'searchGet'], false, 'search'); |
| 68 | + Flight::route('GET /license', [DocsController::class, 'licenseGet'], false, 'license'); |
| 69 | + Flight::route('GET /examples', [DocsController::class, 'examplesGet'], false, 'examples'); |
| 70 | + Flight::route('GET /media', [DocsController::class, 'mediaGet'], false, 'media'); |
| 71 | + Flight::route('GET /search', [DocsController::class, 'searchGet'], false, 'search'); |
71 | 72 |
|
72 | | - $router->group('/learn', function (Router $router): void { |
73 | | - $router->get('', [DocsController::class, 'learnGet'], false, 'learn'); |
74 | | - $router->get('/@section_name', [DocsController::class, 'learnSectionsGet']); |
| 73 | + Flight::group('/learn', static function (): void { |
| 74 | + Flight::route('GET ', [DocsController::class, 'learnGet'], false, 'learn'); |
| 75 | + Flight::route('GET /@section_name', [DocsController::class, 'learnSectionsGet']); |
75 | 76 | }); |
76 | 77 |
|
77 | | - $router->group('/guides', function (Router $router): void { |
78 | | - $router->get('', [DocsController::class, 'guidesGet'], false, 'guides'); |
79 | | - $router->get('/@section_name', [DocsController::class, 'guidesSectionsGet']); |
| 78 | + Flight::group('/guides', static function (): void { |
| 79 | + Flight::route('GET ', [DocsController::class, 'guidesGet'], false, 'guides'); |
| 80 | + Flight::route('GET /@section_name', [DocsController::class, 'guidesSectionsGet']); |
80 | 81 | }); |
81 | 82 |
|
82 | | - $router->group('/awesome-plugins', function (Router $router): void { |
83 | | - $router->get('', [DocsController::class, 'awesomePluginsGet'], false, 'awesome_plugins'); |
84 | | - $router->get('/@plugin_name', [DocsController::class, 'pluginGet'], false, 'plugin'); |
| 83 | + Flight::group('/awesome-plugins', static function (): void { |
| 84 | + Flight::route('GET ', [DocsController::class, 'awesomePluginsGet'], false, 'awesome_plugins'); |
| 85 | + Flight::route('GET /@plugin_name', [DocsController::class, 'pluginGet'], false, 'plugin'); |
85 | 86 | }); |
86 | 87 | }); |
87 | 88 | }, [ new HeaderSecurityMiddleware() ]); |
88 | 89 |
|
89 | 90 | /* |
90 | 91 | * 404 Handler |
91 | 92 | */ |
92 | | -$app->map('notFound', function () use ($app): void { |
| 93 | +Flight::map('notFound', static function (): void { |
93 | 94 | // Clear out anything that may have been generated |
94 | | - $app->response()->clearBody()->status(404); |
| 95 | + Flight::response()->clearBody()->status(404); |
95 | 96 |
|
96 | 97 | // pull the version out of the URL |
97 | | - $url = $app->request()->url; |
| 98 | + $url = Flight::request()->url; |
98 | 99 | $version = preg_match('~/(v\d)/~', $url, $matches) === 1 ? $matches[1] : 'v3'; |
99 | 100 |
|
100 | | - (new DocsLogic($app))->renderPage('not_found.latte', [ |
| 101 | + (new Container)->get(DocsLogic::class)->renderPage('not_found.latte', [ |
101 | 102 | 'title' => '404 Not Found', |
102 | 103 | 'version' => $version |
103 | 104 | ]); |
104 | | - $app->response()->send(); |
| 105 | + |
| 106 | + Flight::response()->send(); |
| 107 | + |
105 | 108 | exit; |
106 | 109 | }); |
0 commit comments