-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathAbstractDeserializer.php
49 lines (39 loc) · 1.02 KB
/
AbstractDeserializer.php
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 PHPTCloud\TelegramApi;
/**
* @author Юдов Алексей tcloud.ax@gmail.com
*/
abstract class AbstractDeserializer
{
protected function filterNumeric(mixed $value, int|float $default = null): int|float|null
{
if (is_float($value)) {
return $value;
} elseif (is_int($value)) {
return $value;
}
return $default;
}
protected function filterString(mixed $value, string $default = null): ?string
{
if (is_string($value)) {
return trim($value);
}
return $default;
}
protected function filterBoolean(mixed $value, bool $default = null): ?bool
{
if (is_bool($value)) {
return filter_var($value, FILTER_VALIDATE_BOOL);
}
return $default;
}
protected function filterArray(mixed $value, array $default = null): ?array
{
if (is_array($value)) {
return $value;
}
return $default;
}
}