| Conditions | 6 |
| Paths | 4 |
| Total Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 44 | public static final function byJsonString($string, array $requiredKeys = null) { |
||
| 45 | $v = json_decode($string, true); |
||
| 46 | if(null === $v || false === $v) { |
||
| 47 | throw new Exception('invalid json string'); |
||
| 48 | } |
||
| 49 | |||
| 50 | //validate first |
||
| 51 | if(null !== $requiredKeys) { |
||
| 52 | //validate array first |
||
| 53 | foreach($requiredKeys as $requiredKey) { |
||
| 54 | if(false === array($v)) { |
||
| 55 | throw new Exception('required key '.$requiredKey.' failed'); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | } |
||
| 59 | return new AssocArray($v); |
||
| 60 | } |
||
| 61 | } |
||
| 62 |