1 | <?php |
||
11 | class Caster |
||
12 | { |
||
13 | |||
14 | 10 | public static function cast($value, $type) |
|
29 | |||
30 | 10 | public static function getValueType($value) |
|
31 | { |
||
32 | 10 | $fromType = gettype($value); |
|
33 | 10 | if ($fromType == "object") { |
|
34 | 2 | $fromType = get_class($value); |
|
35 | } |
||
36 | |||
37 | 10 | return $fromType; |
|
38 | } |
||
39 | |||
40 | 10 | public static function shouldCast($value, $type) |
|
41 | { |
||
42 | 10 | $fromType = self::getValueType($value); |
|
43 | 10 | if ($fromType == $type |
|
44 | 10 | || (isset(self::getCastMap()[$type]) && $fromType == self::getCastMap()[$type]) |
|
45 | 10 | || ($type == "ExchangeFormat" && gettype($value) !== "object")) { |
|
46 | 2 | return false; |
|
47 | } |
||
48 | |||
49 | 8 | return true; |
|
50 | } |
||
51 | |||
52 | 16 | public static function castExists($from, $to) |
|
58 | |||
59 | 9 | public static function getCastMap() |
|
60 | { |
||
68 | |||
69 | 18 | private static function getCasts() |
|
108 | } |
||
109 |