-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoder.php
More file actions
49 lines (42 loc) · 1.16 KB
/
Coder.php
File metadata and controls
49 lines (42 loc) · 1.16 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
<?php
declare(strict_types=1);
namespace PetrKnap\Binary\Coder;
use Throwable;
/**
* @internal shared logic
*/
abstract class Coder implements CoderInterface
{
public function encode(string $decoded): string
{
try {
return @$this->doEncode($decoded);
} catch (Exception\CoderCouldNotEncodeData $exception) {
throw $exception;
} catch (Throwable $reason) {
throw new Exception\CoderCouldNotEncodeData(__METHOD__, $decoded, $reason);
}
}
public function decode(string $encoded): string
{
try {
return @$this->doDecode($encoded);
} catch (Exception\CoderCouldNotDecodeData $exception) {
throw $exception;
} catch (Throwable $reason) {
throw new Exception\CoderCouldNotDecodeData(__METHOD__, $encoded, $reason);
}
}
/**
* @note errors will be silenced
*
* @throws Throwable
*/
abstract protected function doEncode(string $decoded): string;
/**
* @note errors will be silenced
*
* @throws Throwable
*/
abstract protected function doDecode(string $encoded): string;
}