Skip to content

Commit

Permalink
Inject Alertify only if Response has a body, don't have a meta refre…
Browse files Browse the repository at this point in the history
…sh and is not a RedirectResponse (#51)

Inject Alertify only if Response has a body, don't have a meta refresh and is not a RedirectResponse
  • Loading branch information
gregumo authored and lenybernard committed Oct 28, 2016
1 parent 79f047a commit 9f8942d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions EventListener/AlertifyListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ protected function injectAlertify(Response $response, Request $request)
}

$content = $response->getContent();
$pos = strripos($content, '</body>');
$endBodyPos = strripos($content, '</body>');
$hasBody = false !== $endBodyPos;
$hasMetaRefresh = false !== strripos($content, 'http-equiv="refresh"');
$isRedirectResponse = $response instanceof RedirectResponse;

if (false !== $pos) {
if ($hasBody && !$hasMetaRefresh && !$isRedirectResponse) {
$alertify = $this->alertifySessionHandler->handle($this->session);
$content = substr($content, 0, $pos).$alertify.substr($content, $pos);
$content = substr($content, 0, $endBodyPos).$alertify.substr($content, $endBodyPos);
$response->setContent($content);
}
}
Expand Down

0 comments on commit 9f8942d

Please sign in to comment.