|
8 | 8 | use Core\Http\Exception\NotAllowedException;
|
9 | 9 | use Core\Http\Exception\NotFoundException;
|
10 | 10 | use Core\Http\Exception\StreamTerminate;
|
11 |
| -use Core\Http\Respond; |
12 | 11 | use Core\Http\Session;
|
13 |
| -use Core\Http\Stream; |
14 | 12 | use Core\Middleware\Middleware;
|
15 | 13 | use Core\Middleware\MiddlewareInterface;
|
16 | 14 | use Core\Routing\Controller;
|
@@ -78,33 +76,31 @@ private function process(array $route): mixed
|
78 | 76 |
|
79 | 77 | if ($controller) {
|
80 | 78 | $controller = $this->app->singleton($controller);
|
81 |
| - if (!($controller instanceof Controller)) { |
82 |
| - throw new Exception(sprintf('Class "%s" is not extends BaseController.', get_class($controller))); |
| 79 | + if (!($controller instanceof Controller) && !($controller instanceof Provider)) { |
| 80 | + throw new Exception(sprintf('Class "%s" is not extends Controller or Provider.', get_class($controller))); |
83 | 81 | }
|
84 | 82 | }
|
85 | 83 |
|
86 |
| - $attributeMiddleware = []; |
| 84 | + $middlewares = [ |
| 85 | + ...$this->kernel->middlewares(), |
| 86 | + ...$route['middleware'], |
| 87 | + ]; |
| 88 | + |
87 | 89 | if ($controller && $function) {
|
88 | 90 | foreach ($this->app->getAttribute($controller, $function) as $value) {
|
89 |
| - $name = $value->getName(); |
90 |
| - $object = new $name(); |
| 91 | + $object = $this->app->singleton($value->getName()); |
91 | 92 |
|
92 | 93 | if ($object instanceof MiddlewareInterface) {
|
93 |
| - $attributeMiddleware[] = $object; |
| 94 | + array_push($middlewares, $object); |
94 | 95 | }
|
95 | 96 | }
|
96 | 97 | }
|
97 | 98 |
|
98 |
| - $middleware = new Middleware([ |
99 |
| - ...$this->kernel->middlewares(), |
100 |
| - ...$route['middleware'], |
101 |
| - ...$attributeMiddleware |
102 |
| - ]); |
103 |
| - |
104 |
| - $result = $middleware->handle( |
105 |
| - $this->request, |
106 |
| - $this->coreMiddleware($controller, $function) |
107 |
| - ); |
| 99 | + $result = $this->app->make(Middleware::class, [$middlewares]) |
| 100 | + ->handle( |
| 101 | + $this->request, |
| 102 | + $this->coreMiddleware($controller, $function) |
| 103 | + ); |
108 | 104 |
|
109 | 105 | $error = error_get_last();
|
110 | 106 | if ($error !== null) {
|
|
0 commit comments