1: <?php
2: /**
3: * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4: * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
5: *
6: * Licensed under The MIT License
7: * Redistributions of files must retain the above copyright notice.
8: *
9: * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
10: * @link http://cakephp.org CakePHP(tm) Project
11: * @since 3.0.0
12: * @license http://www.opensource.org/licenses/mit-license.php MIT License
13: */
14: namespace Cake\Http\Client;
15:
16: /**
17: * Base class for other HTTP requests/responses
18: *
19: * Defines some common helper methods, constants
20: * and properties.
21: */
22: class Message
23: {
24:
25: /**
26: * HTTP 200 code
27: *
28: * @var int
29: */
30: const STATUS_OK = 200;
31:
32: /**
33: * HTTP 201 code
34: *
35: * @var int
36: */
37: const STATUS_CREATED = 201;
38:
39: /**
40: * HTTP 202 code
41: *
42: * @var int
43: */
44: const STATUS_ACCEPTED = 202;
45:
46: /**
47: * HTTP 301 code
48: *
49: * @var int
50: */
51: const STATUS_MOVED_PERMANENTLY = 301;
52:
53: /**
54: * HTTP 302 code
55: *
56: * @var int
57: */
58: const STATUS_FOUND = 302;
59:
60: /**
61: * HTTP 303 code
62: *
63: * @var int
64: */
65: const STATUS_SEE_OTHER = 303;
66:
67: /**
68: * HTTP 307 code
69: *
70: * @var int
71: */
72: const STATUS_TEMPORARY_REDIRECT = 307;
73:
74: /**
75: * HTTP GET method
76: *
77: * @var string
78: */
79: const METHOD_GET = 'GET';
80:
81: /**
82: * HTTP POST method
83: *
84: * @var string
85: */
86: const METHOD_POST = 'POST';
87:
88: /**
89: * HTTP PUT method
90: *
91: * @var string
92: */
93: const METHOD_PUT = 'PUT';
94:
95: /**
96: * HTTP DELETE method
97: *
98: * @var string
99: */
100: const METHOD_DELETE = 'DELETE';
101:
102: /**
103: * HTTP PATCH method
104: *
105: * @var string
106: */
107: const METHOD_PATCH = 'PATCH';
108:
109: /**
110: * HTTP OPTIONS method
111: *
112: * @var string
113: */
114: const METHOD_OPTIONS = 'OPTIONS';
115:
116: /**
117: * HTTP TRACE method
118: *
119: * @var string
120: */
121: const METHOD_TRACE = 'TRACE';
122:
123: /**
124: * HTTP HEAD method
125: *
126: * @var string
127: */
128: const METHOD_HEAD = 'HEAD';
129:
130: /**
131: * The array of cookies in the response.
132: *
133: * @var array
134: */
135: protected $_cookies = [];
136:
137: /**
138: * Get all headers
139: *
140: * @return array
141: * @deprecated 3.3.0 Use getHeaders() instead.
142: */
143: public function headers()
144: {
145: return $this->headers;
146: }
147:
148: /**
149: * Get all cookies
150: *
151: * @return array
152: */
153: public function cookies()
154: {
155: return $this->_cookies;
156: }
157:
158: /**
159: * Get/set the body for the message.
160: *
161: * @param string|null $body The body for the request. Leave null for get
162: * @return mixed Either $this or the body value.
163: */
164: public function body($body = null)
165: {
166: if ($body === null) {
167: return $this->_body;
168: }
169: $this->_body = $body;
170:
171: return $this;
172: }
173: }
174: