Skip to content

Instantly share code, notes, and snippets.

@shadowhand
Created December 21, 2015 21:11
Show Gist options
  • Save shadowhand/10685482c1f3c2a06450 to your computer and use it in GitHub Desktop.
Save shadowhand/10685482c1f3c2a06450 to your computer and use it in GitHub Desktop.
class RedirectResponder implements Responder
{
public function __invoke(
Request $request,
Response $response,
Payload $payload
) {
if ($this->hasRedirect($payload)) {
$messages = $payload->getMessages() + [
'status' => 302,
];
return $response
->withStatus($messages['status'])
->withHeader('Location', $messages['redirect']);
}
return $response;
}
private function hasRedirect(Payload $payload)
{
$messages = $payload->getMessages();
return !empty($messages['redirect']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment