-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFuseDecoder.php
More file actions
37 lines (31 loc) · 883 Bytes
/
FuseDecoder.php
File metadata and controls
37 lines (31 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
declare(strict_types=1);
namespace Codewithkyrian\Tokenizers\Decoders;
/**
* A decoder that fuses tokens together with an optional separator.
* Defaults to empty string (no separator) for backward compatibility.
*/
class FuseDecoder extends BaseDecoder
{
public function __construct(
protected string $separator = ''
) {}
public function getConfig(?string $key = null, mixed $default = null): mixed
{
if (null !== $key) {
return match ($key) {
'type' => 'Fuse',
'separator' => $this->separator,
default => $default,
};
}
return [
'type' => 'Fuse',
'separator' => $this->separator,
];
}
protected function processTokens(array $tokens): array
{
return [implode($this->separator, $tokens)];
}
}