22
33<show-structure for =" chapter " depth =" 2 " />
44
5- The ` Application ` is the central component of the Boson and is responsible for
6- managing the application lifecycle. It provides a single entry point for
7- creating and managing web applications using WebView.
5+ The ` Boson\Application ` is the central
6+ component of the Boson and is responsible for managing the application
7+ lifecycle. It provides a single entry point for creating and managing web
8+ applications using WebView.
89
910The application is responsible for:
1011
11- - Lifecycle management (
12- < a href = " application.md#creating-an-application " >startup</ a >,
13- < a href = " application .md#stop-application " >shutdown</ a >)
14- - < a href = " window .md" >Window</ a > creation and management
15- - < a href = " webview.md " >WebView</ a > integration for web content display
16- - < a href = " application.md#application -events" >Application</ a >, webview and window event handling
12+ - Lifecycle management ([ startup ] ( application.md#creating ) ,
13+ [ shutdown ] ( application.md#stopping ) , etc).
14+ - [ Window ] ( window .md) creation and management.
15+ - [ WebView ] ( webview .md) integration for web content display.
16+ - [ Application ] ( application-events.md ) , [ WebView ] ( webview-events .md ) and
17+ [ Window ] ( webview -events.md ) event handling.
1718
1819...and more
1920
@@ -23,53 +24,53 @@ two "layers":
2324- Facades over methods and properties of descendants for quick access to the
2425 main internal components of the core.
2526
27+ ## Creating
2628
27- ## Creating an Application
29+ To create an application, simply create a new ` Boson\Application ` object.
30+ This will be sufficient for the vast majority of cases.
2831
29- To create an application, simply create a new <code >Boson\Application</code >
30- object. This will be sufficient for the vast majority of cases.
31-
32- <code-block lang =" PHP " >
32+ ``` php
3333$app = new Boson\Application();
34- </ code-block >
34+ ```
3535
3636The application constructor also contains several optional arguments that you
3737can pass explicitly if you wish.
3838
39- The first optional argument is responsible for the < code > Boson\ApplicationCreateInfo</ code >
39+ The first optional argument is responsible for the ` Boson\ApplicationCreateInfo `
4040application settings and allows you to fine-tune the application's operation.
4141
4242<tip >
4343More details about the application configuration are written on the
44- <a href =" configuration.md#application " >corresponding documentation pages</a >.
44+ <a href =" application- configuration.md" >corresponding documentation pages</a >.
4545</tip >
4646
47- < code-block lang = " PHP " >
47+ ``` php
4848$config = new Boson\ApplicationCreateInfo(
4949 // application configuration options
5050);
5151
5252$app = new Boson\Application(info: $config);
53- </ code-block >
53+ ```
5454
5555The remaining optional parameters are responsible for passing external
5656dependencies.
5757
5858For example, the second argument takes an optional reference to an external
59- < code > Psr\EventDispatcher\EventDispatcherInterface</ code > event dispatcher
59+ ` Psr\EventDispatcher\EventDispatcherInterface ` event dispatcher
6060to which all events within the application can be delegated.
6161
62- < code-block lang = " PHP " >
62+ ``` php
6363$dispatcher = new Any\Vendor\PsrEventDispatcher();
6464
6565$app = new Boson\Application(dispatcher: $dispatcher);
66- </ code-block >
66+ ```
6767
6868After creating the application, you will have access to the API to work with
6969it, and after the necessary actions, the application will automatically start,
70- <a href =" configuration.md#autorun " >unless otherwise specified</a >.
70+ <a href =" application- configuration.md#autorun" >unless otherwise specified</a >.
7171
72- ## Launching an Application
72+ ## Launching
73+ <secondary-label ref =" blocking " />
7374
7475The application can be started manually using the <code >run()</code > method.
7576
@@ -95,7 +96,7 @@ echo 'Application WAS stopped'; // The code will be executed ONLY
9596</warning >
9697
9798
98- ## Stop Application
99+ ## Stopping
99100
100101The application can be stopped at any time using the ` quit() ` method:
101102
@@ -109,11 +110,9 @@ event subscription
109110<code-block lang =" PHP " >
110111$app = new Boson\Application();
111112
112- $app->events->addEventListener(SomeEvent::class,
113- function() use ($app): void {
114- $app->quit();
115- }
116- );
113+ $app->on(function (SomeEvent $e) use ($app): void {
114+ $app->quit();
115+ });
117116
118117$app->run();
119118</code-block >
@@ -134,17 +133,22 @@ if ($app->isRunning === false) {
134133</code-block >
135134
136135
137- ## Application Identifier
136+ ## Identifier
137+ <secondary-label ref =" read-only " />
138138
139- The < code > Boson\ApplicationId</ code > is a unique identifier for each application
139+ The ` Boson\ApplicationId ` is a unique identifier for each application
140140instance. The identifier is needed to compare different applications
141141for their equivalence.
142142
143- <warning >
144- The <code >ApplicationId</code > property is read-only and cannot be changed.
145- </warning >
143+ To get application identifier use the ` Application::$id ` property.
144+
145+ ``` php
146+ $app = new Boson\Application();
146147
147- The <code >ApplicationId</code > identifier is a value object and contains methods
148+ echo 'ID: ' . $app->id;
149+ ```
150+
151+ An identifier is a value object and contains methods
148152for comparison and conversion to scalars.
149153
150154<code-block lang =" PHP " >
@@ -153,83 +157,3 @@ if ($app1->id->equals($app2->id)) {
153157}
154158</code-block >
155159
156-
157- ## Application Events
158- <primary-label ref =" events " />
159-
160- The application will automatically emit the following events (and intentions)
161- during its lifecycle.
162-
163- To subscribe to events, you can use direct access to the
164- <a href =" events.md#event-listener " >event listener</a >, using
165- ` Application::$events ` property.
166-
167- ``` php
168- $app->events->addEventListener(Event::class, function(Event $e) {
169- var_dump($e);
170- });
171- ```
172-
173- The application instance also supports a more convenient and simple way of
174- registering events using the ` on() ` method.
175-
176- ``` php
177- $app->on(function(Event $event): void {
178- var_dump($event);
179- });
180- ```
181-
182- <note >
183- More information about events can be found in the <a href =" events.md " >events
184- documentation</a >.
185- </note >
186-
187-
188-
189- ### Starting Intention
190- <secondary-label ref =" intention " />
191-
192- An ` Boson\Event\ApplicationStarting ` intention to start the application.
193-
194- ``` php
195- class ApplicationStarting<Application >
196- ```
197-
198- <tip >
199- If it is cancelled, the application will not be launched.
200- </tip >
201-
202- ### Started Event
203- <secondary-label ref =" event " />
204-
205- An ` Boson\Event\ApplicationStarted ` event fired after the application has been
206- launched and the ` Boson\Event\ApplicationStarting ` intention has not been
207- cancelled.
208-
209- ``` php
210- class ApplicationStarted<Application >
211- ```
212-
213- ### Stopping Intention
214- <secondary-label ref =" intention " />
215-
216- An ` Boson\Event\ApplicationStopping ` intention to stop the application.
217-
218- ``` php
219- class ApplicationStopping<Application >
220- ```
221-
222- <tip >
223- If it is cancelled, the application will not be stopped.
224- </tip >
225-
226- ### Stopped Event
227- <secondary-label ref =" event " />
228-
229- An ` Boson\Event\ApplicationStopped ` event fired after the application has been
230- stopped and the ` Boson\Event\ApplicationStopping ` intention has not been
231- cancelled.
232-
233- ``` php
234- class ApplicationStopped<Application >
235- ```
0 commit comments