1: <?php
2: /**
3: * Created by PhpStorm.
4: * User: manus
5: * Date: 16/03/16
6: * Time: 13:05
7: */
8:
9: namespace GLFramework;
10:
11:
12: class Response
13: {
14: private $content;
15: private $uri;
16: private $contentType = null;
17: private $redirection = null;
18: private $ajax;
19: private $responseCode = 200;
20: /**
21: * Obtener el contenid de la respuesta
22: * @return mixed
23: */
24: public function getContent()
25: {
26: return $this->content;
27: }
28:
29: /**
30: * Establecer el contenido de la respuesta
31: * @param mixed $content
32: */
33: public function setContent($content)
34: {
35: $this->content = $content;
36: }
37:
38: /**
39: * Obtener el tipo de contenido de la respuesta
40: * @return string
41: */
42: public function getContentType()
43: {
44: return $this->contentType;
45: }
46:
47: /**
48: * Establece el tipo de contenido de la respuesta
49: * @param string $contentType
50: */
51: public function setContentType($contentType)
52: {
53: $this->contentType = $contentType;
54: }
55:
56: /**
57: * Obtiene la url de la redireccion
58: * @return mixed
59: */
60: public function getRedirection()
61: {
62: return $this->redirection;
63: }
64:
65: /**
66: * Establece la URI de la redireccion
67: * @param mixed $redirection
68: */
69: public function setRedirection($redirection)
70: {
71: $this->redirection = $redirection;
72: }
73:
74: /**
75: * Envia la respuesta al cliente
76: */
77: public function display()
78: {
79: Events::fire('beforeResponseSend', array($this));
80: \http_response_code($this->getResponseCode());
81: if($this->contentType) header("Content-Type: " . $this->contentType);
82: if($this->redirection) header("Location: " . $this->redirection);
83: print $this->content;
84: }
85:
86: /**
87: * true si la respueta tiene una redireccion
88: * @return bool
89: */
90: public function isRedirect()
91: {
92: return $this->redirection !== null;
93: }
94:
95: /**
96: * Establecer la URI de respuesta
97: * @param $url
98: */
99: public function setUri($url)
100: {
101: $this->uri = $url;
102: }
103:
104: /**
105: * Obtener la URI de la respuesta
106: * @return mixed
107: */
108: public function getUri()
109: {
110: return $this->uri;
111: }
112:
113: /**
114: * Devuelve el estado de AJAX
115: * @return mixed
116: */
117: public function getAjax()
118: {
119: return $this->ajax;
120: }
121:
122: /**
123: * Establece el estado de AJAX
124: * @param mixed $ajax
125: */
126: public function setAjax($ajax)
127: {
128: $this->ajax = $ajax;
129: }
130:
131: /**
132: * Obtener el codigo de respuesta HTTP
133: * @return int
134: */
135: public function getResponseCode()
136: {
137: return $this->responseCode;
138: }
139:
140: /**
141: * Establece el codigo de respuesta HTTP
142: * @param int $responseCode
143: */
144: public function setResponseCode($responseCode)
145: {
146: $this->responseCode = $responseCode;
147: }
148:
149:
150:
151:
152: }