Skip to content

Commit

Permalink
CsrfTokenReplacer avoid str_replace(): Passing null to parameter #1 (…
Browse files Browse the repository at this point in the history
…$search) of type array|string is deprecated (#482)

Co-authored-by: Herbert Maschke <[email protected]>
  • Loading branch information
thyseus and Herbert Maschke authored Dec 9, 2024
1 parent 06d97ea commit 2604409
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Replacers/CsrfTokenReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,33 @@ class CsrfTokenReplacer implements Replacer

public function prepareResponseToCache(Response $response): void
{
if (! $response->getContent()) {
$csrf_token = csrf_token();
$content = $response->getContent();

if (! $content || ! $csrf_token) {
return;
}

$response->setContent(str_replace(
csrf_token(),
$csrf_token,
$this->replacementString,
$response->getContent()
$content,
));
}

public function replaceInCachedResponse(Response $response): void
{
if (! $response->getContent()) {
$csrf_token = csrf_token();
$content = $response->getContent();

if (! $content || ! $csrf_token) {
return;
}

$response->setContent(str_replace(
$this->replacementString,
csrf_token(),
$response->getContent()
$csrf_token,
$content,
));
}
}

0 comments on commit 2604409

Please sign in to comment.