forked from paquettg/string-encoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncoder.php
More file actions
76 lines (61 loc) · 1.7 KB
/
Copy pathEncoder.php
File metadata and controls
76 lines (61 loc) · 1.7 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
declare(strict_types=1);
namespace StringEncoder;
use StringEncoder\Contracts\ConvertReadInterface;
use StringEncoder\Contracts\EncoderInterface;
use StringEncoder\Contracts\OptionsInterface;
use StringEncoder\DTO\EncodingDTO;
use StringEncoder\Exceptions\InvalidEncodingException;
use StringEncoder\MB\Convert;
final class Encoder implements EncoderInterface
{
/**
* @var EncodingDTO|null
*/
private $sourceEncoding;
/**
* @var EncodingDTO|null
*/
private $targetEncoding;
/**
* @var OptionsInterface|null
*/
private $options;
public function setOptions(OptionsInterface $options): EncoderInterface
{
$this->options = $options;
return $this;
}
public function getTargetEncoding(): ?string
{
if ($this->targetEncoding === null) {
return null;
}
return $this->targetEncoding->getEncoding();
}
/**
* @throws InvalidEncodingException
*/
public function setTargetEncoding(string $encoding): void
{
$this->targetEncoding = EncodingDTO::makeFromString($encoding, null, $this->options);
}
public function getSourceEncoding(): ?string
{
if ($this->sourceEncoding === null) {
return null;
}
return $this->sourceEncoding->getEncoding();
}
/**
* @throws InvalidEncodingException
*/
public function setSourceEncoding(string $encoding): void
{
$this->sourceEncoding = EncodingDTO::makeFromString($encoding, null, $this->options);
}
public function convert(): ConvertReadInterface
{
return new Convert($this->sourceEncoding, $this->targetEncoding, $this->options);
}
}