-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
148 lines (127 loc) · 4.28 KB
/
index.php
File metadata and controls
148 lines (127 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
declare(strict_types=1);
use App\FrontController;
use Boson\Application;
use Boson\ApplicationCreateInfo;
use Boson\Component\Http\Static\FilesystemStaticProvider;
use Boson\WebView\Api\Schemes\Event\SchemeRequestReceive;
use Boson\WebView\Api\WebComponents\WebComponentsExtension;
use Boson\WebView\WebViewCreateInfo;
use Boson\Window\WindowCreateInfo;
use Boson\Window\WindowDecoration;
require __DIR__ . '/vendor/autoload.php';
/**
* -----------------------------------------------------------------------------
* Boson Application
* -----------------------------------------------------------------------------
*
* Creates a new Boson Application.
*
* Don't be afraid to modify the configuration!
*
*/
$app = new Application(new ApplicationCreateInfo(
/**
* @link https://bosonphp.com/doc/master/schemes-api#registration
*/
schemes: [ 'boson' ],
/**
* @link https://bosonphp.com/doc/master/application-configuration#debug-mode
*/
debug: true || (bool) filter_var(getenv('BOSON_DEBUG'), \FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE),
/**
* @link https://bosonphp.com/doc/master/window-configuration
*/
window: new WindowCreateInfo(
/**
* @link https://bosonphp.com/doc/master/window-configuration#window-size-width-and-height
*/
width: 800,
/**
* @link https://bosonphp.com/doc/master/window-configuration#window-size-width-and-height
*/
height: 600,
/**
* @link https://bosonphp.com/doc/master/window-configuration#window-decorations
*/
decoration: WindowDecoration::Full,
webview: new WebViewCreateInfo(
devTools: false,
extensions: [
/**
* Load default webview extensions.
*/
...WebViewCreateInfo::DEFAULT_WEBVIEW_EXTENSIONS,
/**
* Extend by the `WebComponentsExtensionProvider` from
* "boson-php/webview-ext-web-components" dependency.
*/
new WebComponentsExtension(),
],
),
),
));
/**
* -----------------------------------------------------------------------------
* Add WebView Components
* -----------------------------------------------------------------------------
*
* Adds support for the specified custom tags.
*
* @link https://bosonphp.com/doc/master/web-components-api
*
*/
$app->webview->components->add('app-logo', \App\Components\Logo::class);
$app->webview->components->add('app-headlines', \App\Components\Headlines::class);
/**
* -----------------------------------------------------------------------------
* FS Static Provider
* -----------------------------------------------------------------------------
*
* Provides functionality for accessing files on the local
* file system based on HTTP requests.
*
* You may also create an `override` directory next to the compiled binary to
* override all assets.
*
* For example:
* - build/windows/amd64/app.exe
* - build/windows/amd64/assets/xxx
*
* Directory and file mounting rules settings are located in the `mount`
* section of the `boson.json` config.
*
*/
$static = new FilesystemStaticProvider([
__DIR__ . '/assets/private',
__DIR__ . '/assets/public',
]);
/**
* -----------------------------------------------------------------------------
* Request Handler
* -----------------------------------------------------------------------------
*
* Process all "request" events from Boson Application.
*
* @link https://bosonphp.com/doc/master/schemes-api#requests-interception
*
*/
$controller = new FrontController($static);
$app->on(static function (SchemeRequestReceive $e) use ($controller): void {
$e->response = $controller($e->request);
});
$app->on(static function (\Boson\WebView\Event\WebViewMessageReceived $e) {
dump($e->message);
});
/**
* -----------------------------------------------------------------------------
* Fire Request
* -----------------------------------------------------------------------------
*
* Go to the specified address, which in turn initializes the
* first event of the incoming request.
*
* @link https://bosonphp.com/doc/master/webview#url-navigation
*
*/
$app->webview->url = 'boson://index';