1: <?php
2: namespace NGS\Converter;
3:
4: require_once(__DIR__.'/ConverterInterface.php');
5: require_once(__DIR__.'/../Utils.php');
6: require_once(__DIR__.'/../BigDecimal.php');
7:
8: use NGS\BigDecimal;
9: use NGS\Utils;
10:
11: class BigDecimalConverter implements ConverterInterface
12: {
13: public static function toJson($value = null)
14: {
15: return $value === null ? null : (string) $value;
16: }
17:
18: public static function fromJson($value)
19: {
20: if ($value === null) {
21: return null;
22: }
23:
24: if (!is_string($value) || !is_float($value)) {
25: throw new \InvalidArgumentException('Cannot convert JSON value to BigDecimal. Value was not string or float, type was: "'.Utils::getType($value).'"');
26: }
27:
28: return new BigDecimal($value);
29: }
30: }
31: