Skip to content

Commit 85361c0

Browse files
Merge pull request #23 from CodeWithKyrian/hot-fix-decoder
bugfix: Decoder sequence not calling the right method
2 parents e47064f + a0e087b commit 85361c0

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Decoders/DecoderSequence.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected function decodeChain(array $tokens): array
2929
{
3030
return array_reduce(
3131
$this->decoders,
32-
fn(array $tokens, Decoder $decoder) => $decoder->decode($tokens),
32+
fn(array $tokens, Decoder $decoder) => $decoder->decodeChain($tokens),
3333
$tokens
3434
);
3535
}

src/Decoders/ReplaceDecoder.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ protected function decodeChain(array $tokens): array
2020
{
2121
$pattern = $this->config['pattern'] ?? null;
2222

23+
2324
return $pattern == null ?
2425
$tokens :
2526
array_map(function ($token) use ($pattern) {
26-
return str_replace($pattern, $this->config['content'], $token);
27+
if (isset($pattern['Regex'])) {
28+
return preg_replace("/{$pattern['Regex']}/u", $this->config['content'], (string)$token);
29+
} elseif (isset($pattern['String'])) {
30+
return str_replace($pattern['String'], $this->config['content'], (string)$token);
31+
} else {
32+
return $token;
33+
}
2734
}, $tokens);
2835
}
2936
}

0 commit comments

Comments
 (0)