@@ 11-22 (lines=12) @@ | ||
8 | { |
|
9 | if (is_array($val)) { |
|
10 | return $val; |
|
11 | } elseif (is_string($val)) { |
|
12 | try { |
|
13 | $val = json_decode($val); |
|
14 | } catch (\Exception $e) { |
|
15 | throw $this->getValidationException($e->getMessage(), $val); |
|
16 | } |
|
17 | if (!is_array($val)) { |
|
18 | throw $this->getValidationException('json string must decode to array', $val); |
|
19 | } else { |
|
20 | return $val; |
|
21 | } |
|
22 | } else { |
|
23 | throw $this->getValidationException('must be array or string', $val); |
|
24 | } |
|
25 | } |
@@ 11-21 (lines=11) @@ | ||
8 | { |
|
9 | protected function validateCastValue($val) |
|
10 | { |
|
11 | if (!is_string($val)) { |
|
12 | throw $this->getValidationException('must be string', $val); |
|
13 | } else { |
|
14 | $val = trim($val); |
|
15 | try { |
|
16 | // we create a dateInterval first, because it's more restrictive |
|
17 | return CarbonInterval::instance(new \DateInterval($val)); |
|
18 | } catch (\Exception $e) { |
|
19 | throw $this->getValidationException($e->getMessage(), $val); |
|
20 | } |
|
21 | } |
|
22 | } |
|
23 | ||
24 | public static function type() |
@@ 9-18 (lines=10) @@ | ||
6 | { |
|
7 | protected function validateCastValue($val) |
|
8 | { |
|
9 | if (is_string($val)) { |
|
10 | try { |
|
11 | $val = json_decode($val); |
|
12 | } catch (\Exception $e) { |
|
13 | throw $this->getValidationException($e->getMessage(), $val); |
|
14 | } |
|
15 | if (!$val) { |
|
16 | throw $this->getValidationException('failed to decode json', $val); |
|
17 | } |
|
18 | } |
|
19 | $val = json_decode(json_encode($val)); |
|
20 | if (!is_object($val)) { |
|
21 | throw $this->getValidationException('must be an object', $val); |