File tree Expand file tree Collapse file tree 2 files changed +36
-13
lines changed
Expand file tree Collapse file tree 2 files changed +36
-13
lines changed Original file line number Diff line number Diff line change 22
33declare (strict_types=1 );
44
5+ use App \FrontController ;
56use Boson \Application ;
67use Boson \ApplicationCreateInfo ;
7- use Boson \Component \Http \Response ;
88use Boson \Component \Http \Static \FilesystemStaticProvider ;
99use Boson \WebView \Api \Schemes \Event \SchemeRequestReceived ;
1010use Boson \WebView \Api \WebComponents \WebComponentsExtension ;
122122 *
123123 */
124124
125- $ app ->on (static function (SchemeRequestReceived $ e ) use ($ static ): void {
126- //
127- // Install file (if exists) as response using static adapter...
128- //
129- if ($ e ->response = $ static ->findFileByRequest ($ e ->request )) {
130- $ e ->stopPropagation ();
125+ $ controller = new FrontController ($ static );
131126
132- return ;
133- }
134-
135- $ response = file_get_contents (__DIR__ . '/assets/view/layout/main.html ' );
136-
137- $ e ->response = new Response ($ response );
127+ $ app ->on (static function (SchemeRequestReceived $ e ) use ($ controller ): void {
128+ $ e ->response = $ controller ($ e ->request );
138129});
139130
140131
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace App ;
6+
7+ use Boson \Component \Http \Component \StatusCode ;
8+ use Boson \Component \Http \Response ;
9+ use Boson \Component \Http \Static \StaticProviderInterface ;
10+ use Boson \Contracts \Http \RequestInterface ;
11+ use Boson \Contracts \Http \ResponseInterface ;
12+
13+ final readonly class FrontController
14+ {
15+ public function __construct (
16+ private StaticProviderInterface $ static ,
17+ ) {}
18+
19+ public function __invoke (RequestInterface $ request ): ?ResponseInterface
20+ {
21+ $ response = $ this ->static ->findFileByRequest ($ request );
22+
23+ if ($ response !== null ) {
24+ return $ response ;
25+ }
26+
27+ return new Response (
28+ body: file_get_contents (__DIR__ . '/../assets/view/layout/main.html ' ),
29+ status: StatusCode::Ok,
30+ );
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments