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
  • Loading branch information
Herbert Maschke committed Oct 8, 2024
1 parent efb1ecd commit 15519de
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Replacers/CsrfTokenReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,30 @@ class CsrfTokenReplacer implements Replacer

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

if (! $response->getContent() || !$csrf_token) {
return;
}

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

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

if (! $response->getContent() || !$csrf_token) {
return;
}

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

0 comments on commit 15519de

Please sign in to comment.