11
11
12
12
use Nette ;
13
13
use Nette \Routing \Router ;
14
+ use Nette \Utils \Arrays ;
14
15
15
16
16
17
/**
@@ -30,22 +31,22 @@ class Application
30
31
public $ errorPresenter ;
31
32
32
33
/** @var callable[]&(callable(Application $sender): void)[]; Occurs before the application loads presenter */
33
- public $ onStartup ;
34
+ public $ onStartup = [] ;
34
35
35
36
/** @var callable[]&(callable(Application $sender, \Throwable $e = null): void)[]; Occurs before the application shuts down */
36
- public $ onShutdown ;
37
+ public $ onShutdown = [] ;
37
38
38
39
/** @var callable[]&(callable(Application $sender, Request $request): void)[]; Occurs when a new request is received */
39
- public $ onRequest ;
40
+ public $ onRequest = [] ;
40
41
41
42
/** @var callable[]&(callable(Application $sender, IPresenter $presenter): void)[]; Occurs when a presenter is created */
42
- public $ onPresenter ;
43
+ public $ onPresenter = [] ;
43
44
44
45
/** @var callable[]&(callable(Application $sender, Response $response): void)[]; Occurs when a new response is ready for dispatch */
45
- public $ onResponse ;
46
+ public $ onResponse = [] ;
46
47
47
48
/** @var callable[]&(callable(Application $sender, \Throwable $e): void)[]; Occurs when an unhandled exception occurs in the application */
48
- public $ onError ;
49
+ public $ onError = [] ;
49
50
50
51
/** @var Request[] */
51
52
private $ requests = [];
@@ -85,23 +86,23 @@ public function __construct(
85
86
public function run (): void
86
87
{
87
88
try {
88
- $ this ->onStartup ( $ this );
89
+ Arrays:: invoke ( $ this ->onStartup , $ this );
89
90
$ this ->processRequest ($ this ->createInitialRequest ());
90
- $ this ->onShutdown ( $ this );
91
+ Arrays:: invoke ( $ this ->onShutdown , $ this );
91
92
92
93
} catch (\Throwable $ e ) {
93
- $ this ->onError ( $ this , $ e );
94
+ Arrays:: invoke ( $ this ->onError , $ this , $ e );
94
95
if ($ this ->catchExceptions && $ this ->errorPresenter ) {
95
96
try {
96
97
$ this ->processException ($ e );
97
- $ this ->onShutdown ( $ this , $ e );
98
+ Arrays:: invoke ( $ this ->onShutdown , $ this , $ e );
98
99
return ;
99
100
100
101
} catch (\Throwable $ e ) {
101
- $ this ->onError ( $ this , $ e );
102
+ Arrays:: invoke ( $ this ->onError , $ this , $ e );
102
103
}
103
104
}
104
- $ this ->onShutdown ( $ this , $ e );
105
+ Arrays:: invoke ( $ this ->onShutdown , $ this , $ e );
105
106
throw $ e ;
106
107
}
107
108
}
@@ -140,7 +141,7 @@ public function processRequest(Request $request): void
140
141
}
141
142
142
143
$ this ->requests [] = $ request ;
143
- $ this ->onRequest ( $ this , $ request );
144
+ Arrays:: invoke ( $ this ->onRequest , $ this , $ request );
144
145
145
146
if (
146
147
!$ request ->isMethod ($ request ::FORWARD )
@@ -156,15 +157,15 @@ public function processRequest(Request $request): void
156
157
? $ e
157
158
: new BadRequestException ($ e ->getMessage (), 0 , $ e );
158
159
}
159
- $ this ->onPresenter ( $ this , $ this ->presenter );
160
+ Arrays:: invoke ( $ this ->onPresenter , $ this , $ this ->presenter );
160
161
$ response = $ this ->presenter ->run (clone $ request );
161
162
162
163
if ($ response instanceof Responses \ForwardResponse) {
163
164
$ request = $ response ->getRequest ();
164
165
goto process;
165
166
}
166
167
167
- $ this ->onResponse ( $ this , $ response );
168
+ Arrays:: invoke ( $ this ->onResponse , $ this , $ response );
168
169
$ response ->send ($ this ->httpRequest , $ this ->httpResponse );
169
170
}
170
171
0 commit comments