1: <?php
2: namespace NGS\Converter;
3:
4: require_once(__DIR__.'/ConverterInterface.php');
5: require_once(__DIR__.'/../Utils.php');
6: require_once(__DIR__.'/../UUID.php');
7:
8: use NGS\UUID;
9: use NGS\Utils;
10:
11: class UUIDConverter 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: if(!is_string($value)) {
24: throw new \InvalidArgumentException('Cannot convert JSON value to UUID. Value type was not string, type was: "'.Utils::getType($value).'"');
25: }
26: return new UUID($value);
27: }
28: }
29: