36
36
*/
37
37
class App
38
38
{
39
- /**
40
- * @var ContainerInterface
41
- */
42
- protected $ container ;
43
-
44
39
/**
45
40
* @var ConfigInterface
46
41
*/
@@ -56,11 +51,10 @@ class App
56
51
*/
57
52
protected $ bound ;
58
53
59
- private $ serverName = 'http ' ;
54
+ private string $ serverName = 'http ' ;
60
55
61
- public function __construct (ContainerInterface $ container )
56
+ public function __construct (protected ContainerInterface $ container )
62
57
{
63
- $ this ->container = $ container ;
64
58
$ this ->config = $ this ->container ->get (ConfigInterface::class);
65
59
$ this ->dispatcherFactory = $ this ->container ->get (DispatcherFactory::class);
66
60
$ this ->bound = $ this ->container ->has (BoundInterface::class)
@@ -108,7 +102,7 @@ public function getContainer(): ContainerInterface
108
102
* Add a middleware globally.
109
103
* @param callable|MiddlewareInterface|string $middleware
110
104
*/
111
- public function addMiddleware ($ middleware )
105
+ public function addMiddleware (callable | MiddlewareInterface | string $ middleware )
112
106
{
113
107
if ($ middleware instanceof MiddlewareInterface || is_string ($ middleware )) {
114
108
$ this ->appendConfig ('middlewares. ' . $ this ->serverName , $ middleware );
@@ -127,7 +121,7 @@ public function addMiddleware($middleware)
127
121
* Add an exception handler globally.
128
122
* @param callable|string $exceptionHandler
129
123
*/
130
- public function addExceptionHandler ($ exceptionHandler )
124
+ public function addExceptionHandler (callable | string $ exceptionHandler )
131
125
{
132
126
if (is_string ($ exceptionHandler )) {
133
127
$ this ->appendConfig ('exceptions.handler. ' . $ this ->serverName , $ exceptionHandler );
@@ -168,15 +162,14 @@ public function addListener(string $event, $listener = null, int $priority = 1)
168
162
169
163
/**
170
164
* Add a route group.
171
- * @param array|string $prefix
172
165
*/
173
- public function addGroup ($ prefix , callable $ callback , array $ options = [])
166
+ public function addGroup (array | string $ prefix , callable $ callback , array $ options = []): void
174
167
{
175
168
$ router = $ this ->dispatcherFactory ->getRouter ($ this ->serverName );
176
169
if (isset ($ options ['middleware ' ])) {
177
170
$ this ->convertClosureToMiddleware ($ options ['middleware ' ]);
178
171
}
179
- return $ router ->addGroup ($ prefix , $ callback , $ options );
172
+ $ router ->addGroup ($ prefix , $ callback , $ options );
180
173
}
181
174
182
175
/**
@@ -216,7 +209,7 @@ function ($handler) {
216
209
* Add a new crontab.
217
210
* @param callable|string $crontab
218
211
*/
219
- public function addCrontab (string $ rule , $ crontab ): Crontab
212
+ public function addCrontab (string $ rule , callable | string $ crontab ): Crontab
220
213
{
221
214
$ this ->config ->set ('crontab.enable ' , true );
222
215
$ this ->ensureConfigHasValue ('processes ' , CrontabDispatcherProcess::class);
@@ -251,7 +244,7 @@ function ($crontab) {
251
244
* Add a new process.
252
245
* @param callable|string $process
253
246
*/
254
- public function addProcess ($ process )
247
+ public function addProcess (callable | string $ process )
255
248
{
256
249
if (is_string ($ process )) {
257
250
$ this ->appendConfig ('processes ' , $ process );
@@ -275,7 +268,7 @@ public function addProcess($process)
275
268
* @param mixed $httpMethod
276
269
* @param mixed $handler
277
270
*/
278
- public function addRoute ($ httpMethod , string $ route , $ handler , array $ options = [])
271
+ public function addRoute ($ httpMethod , string $ route , $ handler , array $ options = []): void
279
272
{
280
273
$ router = $ this ->dispatcherFactory ->getRouter ($ this ->serverName );
281
274
if (isset ($ options ['middleware ' ])) {
@@ -284,7 +277,7 @@ public function addRoute($httpMethod, string $route, $handler, array $options =
284
277
if ($ handler instanceof \Closure) {
285
278
$ handler = $ handler ->bindTo ($ this ->bound , $ this ->bound );
286
279
}
287
- return $ router ->addRoute ($ httpMethod , $ route , $ handler , $ options );
280
+ $ router ->addRoute ($ httpMethod , $ route , $ handler , $ options );
288
281
}
289
282
290
283
/**
0 commit comments