-
-
Notifications
You must be signed in to change notification settings - Fork 110
Refactor Application to return Response from processRequest #350
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
base: master
Are you sure you want to change the base?
Changes from all commits
ea75bb3
8e44912
a15b2bf
a4f2b39
4fcf653
c4dc05c
257053d
cee6954
b01244b
580e8fc
38e0368
6512dd5
9012b17
1f8b489
e22102a
990189c
36a8e10
8f90019
a4bc74f
b38ee7c
369351f
d7a5642
84ec05f
5c82f7d
f6a7af4
7e3b662
ee24f8e
0aa7f5e
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 | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -12,6 +12,7 @@ | |||||||
use Nette; | ||||||||
use Nette\Routing\Router; | ||||||||
use Nette\Utils\Arrays; | ||||||||
use function count, is_string, str_starts_with, strcasecmp; | ||||||||
|
||||||||
|
||||||||
/** | ||||||||
|
@@ -73,15 +74,15 @@ public function run(): void | |||||||
{ | ||||||||
try { | ||||||||
Arrays::invoke($this->onStartup, $this); | ||||||||
$this->processRequest($this->createInitialRequest()); | ||||||||
$this->processRequest($this->createInitialRequest())->send($this->httpRequest, $this->httpResponse); | ||||||||
Arrays::invoke($this->onShutdown, $this); | ||||||||
|
||||||||
} catch (\Throwable $e) { | ||||||||
$this->sendHttpCode($e); | ||||||||
Arrays::invoke($this->onError, $this, $e); | ||||||||
if ($this->catchExceptions && ($req = $this->createErrorRequest($e))) { | ||||||||
try { | ||||||||
$this->processRequest($req); | ||||||||
$this->processRequest($req)->send($this->httpRequest, $this->httpResponse); | ||||||||
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. [nitpick] For consistency with the run() method, consider assigning the returned Response to a variable before invoking send(), which can help with error handling and debugging.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||
Arrays::invoke($this->onShutdown, $this, $e); | ||||||||
return; | ||||||||
|
||||||||
|
@@ -120,7 +121,7 @@ public function createInitialRequest(): Request | |||||||
} | ||||||||
|
||||||||
|
||||||||
public function processRequest(Request $request): void | ||||||||
public function processRequest(Request $request): Response | ||||||||
{ | ||||||||
process: | ||||||||
if (count($this->requests) > $this->maxLoop) { | ||||||||
|
@@ -155,7 +156,7 @@ public function processRequest(Request $request): void | |||||||
} | ||||||||
|
||||||||
Arrays::invoke($this->onResponse, $this, $response); | ||||||||
$response->send($this->httpRequest, $this->httpResponse); | ||||||||
return $response; | ||||||||
} | ||||||||
|
||||||||
|
||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
namespace Nette\Application\Responses; | ||
|
||
use Nette; | ||
use function strlen; | ||
|
||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
namespace Nette\Application\Routers; | ||
|
||
use Nette; | ||
use function is_array; | ||
|
||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,13 @@ | |
|
||
use JetBrains\PhpStorm\Language; | ||
use Nette; | ||
use function count, is_int, is_string, strlen, strncmp, substr; | ||
|
||
|
||
/** | ||
* The router broker. | ||
*/ | ||
class RouteList extends Nette\Routing\RouteList implements Nette\Routing\Router, \ArrayAccess | ||
Check failure on line 20 in src/Application/Routers/RouteList.php
|
||
{ | ||
private const PresenterKey = 'presenter'; | ||
|
||
|
@@ -75,7 +76,7 @@ | |
|
||
public function withModule(string $module): static | ||
{ | ||
$router = new static; | ||
$router->module = $module . ':'; | ||
$router->parent = $this; | ||
$this->add($router); | ||
|
@@ -95,6 +96,13 @@ | |
*/ | ||
public function offsetSet($index, $router): void | ||
{ | ||
if ($router instanceof Route) { | ||
trigger_error('Usage `$router[] = new Route(...)` is deprecated, use `$router->addRoute(...)`.', E_USER_DEPRECATED); | ||
} else { | ||
$class = getclass($router); | ||
trigger_error("Usage `\$router[] = new $class` is deprecated, use `\$router->add(new $class)`.", E_USER_DEPRECATED); | ||
} | ||
|
||
if ($index === null) { | ||
$this->add($router); | ||
} else { | ||
|
@@ -109,6 +117,7 @@ | |
*/ | ||
public function offsetGet($index): Nette\Routing\Router | ||
{ | ||
trigger_error('Usage `$route = $router[...]` is deprecated, use `$router->getRouters()`.', E_USER_DEPRECATED); | ||
if (!$this->offsetExists($index)) { | ||
throw new Nette\OutOfRangeException('Offset invalid or out of range'); | ||
} | ||
|
@@ -122,7 +131,8 @@ | |
*/ | ||
public function offsetExists($index): bool | ||
{ | ||
trigger_error('Usage `isset($router[...])` is deprecated.', E_USER_DEPRECATED); | ||
return is_int($index) && $index >= 0 && $index < count($this->getRouters()); | ||
} | ||
|
||
|
||
|
@@ -132,13 +142,11 @@ | |
*/ | ||
public function offsetUnset($index): void | ||
{ | ||
trigger_error('Usage `unset($router[$index])` is deprecated, use `$router->modify($index, null)`.', E_USER_DEPRECATED); | ||
if (!$this->offsetExists($index)) { | ||
throw new Nette\OutOfRangeException('Offset invalid or out of range'); | ||
} | ||
|
||
$this->modify($index, null); | ||
} | ||
} | ||
|
||
|
||
interface_exists(Nette\Application\IRouter::class); |
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.
[nitpick] For enhanced readability and debugging, consider storing the returned Response in a temporary variable before calling send().
Copilot uses AI. Check for mistakes.