| Total Complexity | 5 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 4 | trait ResponseUrlTrait |
||
| 5 | { |
||
| 6 | abstract protected function request(); |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Redirect to an application location (Request target). |
||
| 10 | * This method returns a HttpResponse object that needs to be in turn returned to the application. |
||
| 11 | */ |
||
| 12 | final protected function getRedirectResponse($location, $addSuffix = true) |
||
| 20 | } |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Redirect to an application location (Request target). |
||
| 24 | * This method sends a HttpRequest, forcing a redirect. |
||
| 25 | */ |
||
| 26 | final protected function forceRedirect($location, $addSuffix = true) |
||
| 27 | { |
||
| 28 | $response = $this->getRedirectResponse($location, $addSuffix); |
||
| 29 | $response->send(); |
||
| 30 | exit; |
||
|
|
|||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Redirect to the current URL. |
||
| 35 | * This method returns a HttpResponse object that needs to be in turn returned to the application. |
||
| 36 | */ |
||
| 37 | final protected function getReloadResponse($removeParameters = []) |
||
| 38 | { |
||
| 39 | $url = $this->request()->getUrl($removeParameters); |
||
| 40 | return $this->getRedirectUrlResponse($url); |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Redirect to a full URL. |
||
| 45 | * This method returns a HttpResponse object that needs to be in turn returned to the application. |
||
| 46 | */ |
||
| 47 | final protected function getRedirectUrlResponse($url) |
||
| 53 | ); |
||
| 54 | } |
||
| 55 | } |
||
| 56 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.