@@ 12-28 (lines=17) @@ | ||
9 | use Gica\Serialize\ObjectHydrator\Exception\ValueNotUnserializable; |
|
10 | use Gica\Serialize\ObjectHydrator\ObjectUnserializer; |
|
11 | ||
12 | class FromPrimitive implements ObjectUnserializer |
|
13 | { |
|
14 | ||
15 | /** |
|
16 | * @inheritdoc |
|
17 | */ |
|
18 | public function tryToUnserializeValue(string $objectClassName, $serializedValue) |
|
19 | { |
|
20 | if (is_scalar($serializedValue) || is_array($serializedValue)) { |
|
21 | if (is_callable([$objectClassName, 'fromPrimitive'])) { |
|
22 | return call_user_func([$objectClassName, 'fromPrimitive'], $serializedValue); |
|
23 | } |
|
24 | } |
|
25 | ||
26 | throw new ValueNotUnserializable(); |
|
27 | } |
|
28 | } |
@@ 12-29 (lines=18) @@ | ||
9 | use Gica\Serialize\ObjectHydrator\Exception\ValueNotUnserializable; |
|
10 | use Gica\Serialize\ObjectHydrator\ObjectUnserializer; |
|
11 | ||
12 | class FromString implements ObjectUnserializer |
|
13 | { |
|
14 | ||
15 | /** |
|
16 | * @inheritdoc |
|
17 | */ |
|
18 | public function tryToUnserializeValue(string $objectClassName, $serializedValue) |
|
19 | { |
|
20 | if ((is_string($serializedValue) || is_callable([$serializedValue, '__toString']))) { |
|
21 | if (is_callable([$objectClassName, 'fromString'])) { |
|
22 | ||
23 | return call_user_func([$objectClassName, 'fromString'], (string)$serializedValue); |
|
24 | } |
|
25 | } |
|
26 | ||
27 | throw new ValueNotUnserializable(); |
|
28 | } |
|
29 | } |