| Conditions | 5 |
| Paths | 4 |
| Total Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 5.9256 |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | 1 | public function render(array $output) |
|
| 15 | { |
||
| 16 | 1 | $response = new Response(); |
|
| 17 | 1 | $response->headers->set('Content-Type', 'application/json'); |
|
| 18 | 1 | foreach ($output as $key=>$value){ |
|
| 19 | //TODO 支持自定义格式输出 |
||
| 20 | //TODO 支持更多的输出目标 |
||
| 21 | 1 | if($key == 'content'){ |
|
| 22 | //if(is_array($value) || is_object($value)){ |
||
| 23 | 1 | $value = json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
| 24 | //} |
||
| 25 | 1 | $response->setContent($value); |
|
| 26 | 1 | }elseif($key == 'headers'){ |
|
| 27 | foreach ($value as $k=>$v){ |
||
| 28 | $response->headers->set($k, $v); |
||
| 29 | } |
||
| 30 | }else{ |
||
| 31 | \PhpBoot\abort(new \UnexpectedValueException("Unexpected output target $key")); |
||
| 32 | } |
||
| 33 | |||
| 34 | 1 | } |
|
| 35 | 1 | return $response; |
|
| 36 | } |
||
| 37 | } |