1: <?php
2:
3: namespace PHPixie\Framework\Processors\HTTP\Response;
4:
5: 6: 7:
8: class Normalize implements \PHPixie\Processors\Processor
9: {
10: 11: 12:
13: protected $http;
14:
15: 16: 17: 18:
19: public function __construct($http)
20: {
21: $this->http = $http;
22: }
23:
24: 25: 26: 27: 28: 29:
30: public function process($value)
31: {
32: if($value instanceof \PHPixie\HTTP\Responses\Response) {
33: return $value;
34: }
35:
36: if($value instanceof \Psr\Http\Message\ResponseInterface) {
37: return $value;
38: }
39:
40: if($value instanceof \PHPixie\Template\Container) {
41: $value = $value->render();
42: }
43:
44: if(is_string($value)) {
45: return $this->http->responses()->string($value);
46: }
47:
48: if(is_object($value) || is_array($value)) {
49: return $this->http->responses()->json($value);
50: }
51:
52: $type = gettype($value);
53: throw new \PHPixie\HTTPProcessors\Exception("Cannot convert type '$type' into a response");
54: }
55: }