-
-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Attributes #194
Support Attributes #194
Changes from 12 commits
0af63e7
de26704
dec5e5f
5ff5574
9004eea
e721bec
a48bbf4
ae68876
bae323a
84f6a0f
8c1e27c
704e02e
35ec329
628d0f2
f0164db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
'corsMiddleware', | ||
'items', | ||
'middlewareDefinitions', | ||
'hasDispatcher', | ||
'hasCorsMiddleware' | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,6 @@ | |
'methods', | ||
'override', | ||
'defaults', | ||
'dispatcherWithMiddlewares', | ||
'hasDispatcher', | ||
'hasMiddlewares' | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -97,18 +97,29 @@ public function route(): Route | |||||||
|
||||||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||||||||
{ | ||||||||
if (!$this->isSuccess()) { | ||||||||
return $handler->handle($request); | ||||||||
if ($this->isSuccess() && $this->dispatcher !== null) { | ||||||||
return $this | ||||||||
->buildDispatcher($this->dispatcher, $this->route) | ||||||||
->dispatch($request, $handler); | ||||||||
} | ||||||||
|
||||||||
// Inject dispatcher only if we have not previously injected. | ||||||||
return $handler->handle($request); | ||||||||
} | ||||||||
|
||||||||
private function buildDispatcher( | ||||||||
?MiddlewareDispatcher $dispatcher, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The dispatcher is nullable |
||||||||
Route $route, | ||||||||
): MiddlewareDispatcher { | ||||||||
if ($dispatcher === null) { | ||||||||
throw new RuntimeException(sprintf('There is no dispatcher in the route %s.', $route->getData('name'))); | ||||||||
} | ||||||||
|
||||||||
Comment on lines
+113
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||||||||
// Don't add middlewares to dispatcher if we did it earlier. | ||||||||
// This improves performance in event-loop applications. | ||||||||
if ($this->dispatcher !== null && !$this->route->getData('hasDispatcher')) { | ||||||||
$this->route->injectDispatcher($this->dispatcher); | ||||||||
if ($dispatcher->hasMiddlewares()) { | ||||||||
return $dispatcher; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand what you are saying |
||||||||
} | ||||||||
|
||||||||
return $this->route | ||||||||
->getData('dispatcherWithMiddlewares') | ||||||||
->dispatch($request, $handler); | ||||||||
return $dispatcher->withMiddlewares($route->getMiddlewares()); | ||||||||
} | ||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to link to the guide on how to achieve colleccting attributes or to describe it right here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have any attributes collectors. I'll add it later if we merge this example