*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Controller / Request / HttpTestCase.php
blobf1ce3875d94d70cc95ae8c8071a7f2cb90051448
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
15 * @category Zend
16 * @package Zend_Controller
17 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license http://framework.zend.com/license/new-bsd New BSD License
19 * @version $Id: HttpTestCase.php 16541 2009-07-07 06:59:03Z bkarwin $
22 /**
23 * @see Zend_Controller_Request_Http
25 require_once 'Zend/Controller/Request/Http.php';
27 /**
28 * Zend_Controller_Request_HttpTestCase
30 * HTTP request object for use with Zend_Controller family.
32 * @uses Zend_Controller_Request_Http
33 * @package Zend_Controller
34 * @subpackage Request
36 class Zend_Controller_Request_HttpTestCase extends Zend_Controller_Request_Http
38 /**
39 * Request headers
40 * @var array
42 protected $_headers = array();
44 /**
45 * Request method
46 * @var string
48 protected $_method;
50 /**
51 * Raw POST body
52 * @var string|null
54 protected $_rawBody;
56 /**
57 * Valid request method types
58 * @var array
60 protected $_validMethodTypes = array(
61 'DELETE',
62 'GET',
63 'HEAD',
64 'OPTIONS',
65 'POST',
66 'PUT',
69 /**
70 * Clear GET values
72 * @return Zend_Controller_Request_HttpTestCase
74 public function clearQuery()
76 $_GET = array();
77 return $this;
80 /**
81 * Clear POST values
83 * @return Zend_Controller_Request_HttpTestCase
85 public function clearPost()
87 $_POST = array();
88 return $this;
91 /**
92 * Set raw POST body
94 * @param string $content
95 * @return Zend_Controller_Request_HttpTestCase
97 public function setRawBody($content)
99 $this->_rawBody = (string) $content;
100 return $this;
104 * Get RAW POST body
106 * @return string|null
108 public function getRawBody()
110 return $this->_rawBody;
114 * Clear raw POST body
116 * @return Zend_Controller_Request_HttpTestCase
118 public function clearRawBody()
120 $this->_rawBody = null;
121 return $this;
125 * Set a cookie
127 * @param string $key
128 * @param mixed $value
129 * @return Zend_Controller_Request_HttpTestCase
131 public function setCookie($key, $value)
133 $_COOKIE[(string) $key] = $value;
134 return $this;
138 * Set multiple cookies at once
140 * @param array $cookies
141 * @return void
143 public function setCookies(array $cookies)
145 foreach ($cookies as $key => $value) {
146 $_COOKIE[$key] = $value;
148 return $this;
152 * Clear all cookies
154 * @return Zend_Controller_Request_HttpTestCase
156 public function clearCookies()
158 $_COOKIE = array();
159 return $this;
163 * Set request method
165 * @param string $type
166 * @return Zend_Controller_Request_HttpTestCase
168 public function setMethod($type)
170 $type = strtoupper(trim((string) $type));
171 if (!in_array($type, $this->_validMethodTypes)) {
172 require_once 'Zend/Controller/Exception.php';
173 throw new Zend_Controller_Exception('Invalid request method specified');
175 $this->_method = $type;
176 return $this;
180 * Get request method
182 * @return string|null
184 public function getMethod()
186 return $this->_method;
190 * Set a request header
192 * @param string $key
193 * @param string $value
194 * @return Zend_Controller_Request_HttpTestCase
196 public function setHeader($key, $value)
198 $key = $this->_normalizeHeaderName($key);
199 $this->_headers[$key] = (string) $value;
200 return $this;
204 * Set request headers
206 * @param array $headers
207 * @return Zend_Controller_Request_HttpTestCase
209 public function setHeaders(array $headers)
211 foreach ($headers as $key => $value) {
212 $this->setHeader($key, $value);
214 return $this;
218 * Get request header
220 * @param string $header
221 * @param mixed $default
222 * @return string|null
224 public function getHeader($header, $default = null)
226 $header = $this->_normalizeHeaderName($header);
227 if (array_key_exists($header, $this->_headers)) {
228 return $this->_headers[$header];
230 return $default;
234 * Get all request headers
236 * @return array
238 public function getHeaders()
240 return $this->_headers;
244 * Clear request headers
246 * @return Zend_Controller_Request_HttpTestCase
248 public function clearHeaders()
250 $this->_headers = array();
251 return $this;
255 * Get REQUEST_URI
257 * @return null|string
259 public function getRequestUri()
261 return $this->_requestUri;
265 * Normalize a header name for setting and retrieval
267 * @param string $name
268 * @return string
270 protected function _normalizeHeaderName($name)
272 $name = strtoupper((string) $name);
273 $name = str_replace('-', '_', $name);
274 return $name;