PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/src/frapi/library/Zend/Controller/Request/HttpTestCase.php

https://github.com/Martin1982/IBMessagingWorkshopServer
PHP | 276 lines | 109 code | 22 blank | 145 comment | 2 complexity | b84f4f50316cd6d7e586288522148d87 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  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.
  14. *
  15. * @category Zend
  16. * @package Zend_Controller
  17. * @copyright Copyright (c) 2005-2010 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 20096 2010-01-06 02:05:09Z bkarwin $
  20. */
  21. /**
  22. * @see Zend_Controller_Request_Http
  23. */
  24. // require_once 'Zend/Controller/Request/Http.php';
  25. /**
  26. * Zend_Controller_Request_HttpTestCase
  27. *
  28. * HTTP request object for use with Zend_Controller family.
  29. *
  30. * @uses Zend_Controller_Request_Http
  31. * @package Zend_Controller
  32. * @subpackage Request
  33. */
  34. class Zend_Controller_Request_HttpTestCase extends Zend_Controller_Request_Http
  35. {
  36. /**
  37. * Request headers
  38. * @var array
  39. */
  40. protected $_headers = array();
  41. /**
  42. * Request method
  43. * @var string
  44. */
  45. protected $_method = 'GET';
  46. /**
  47. * Raw POST body
  48. * @var string|null
  49. */
  50. protected $_rawBody;
  51. /**
  52. * Valid request method types
  53. * @var array
  54. */
  55. protected $_validMethodTypes = array(
  56. 'DELETE',
  57. 'GET',
  58. 'HEAD',
  59. 'OPTIONS',
  60. 'POST',
  61. 'PUT',
  62. );
  63. /**
  64. * Clear GET values
  65. *
  66. * @return Zend_Controller_Request_HttpTestCase
  67. */
  68. public function clearQuery()
  69. {
  70. $_GET = array();
  71. return $this;
  72. }
  73. /**
  74. * Clear POST values
  75. *
  76. * @return Zend_Controller_Request_HttpTestCase
  77. */
  78. public function clearPost()
  79. {
  80. $_POST = array();
  81. return $this;
  82. }
  83. /**
  84. * Set raw POST body
  85. *
  86. * @param string $content
  87. * @return Zend_Controller_Request_HttpTestCase
  88. */
  89. public function setRawBody($content)
  90. {
  91. $this->_rawBody = (string) $content;
  92. return $this;
  93. }
  94. /**
  95. * Get RAW POST body
  96. *
  97. * @return string|null
  98. */
  99. public function getRawBody()
  100. {
  101. return $this->_rawBody;
  102. }
  103. /**
  104. * Clear raw POST body
  105. *
  106. * @return Zend_Controller_Request_HttpTestCase
  107. */
  108. public function clearRawBody()
  109. {
  110. $this->_rawBody = null;
  111. return $this;
  112. }
  113. /**
  114. * Set a cookie
  115. *
  116. * @param string $key
  117. * @param mixed $value
  118. * @return Zend_Controller_Request_HttpTestCase
  119. */
  120. public function setCookie($key, $value)
  121. {
  122. $_COOKIE[(string) $key] = $value;
  123. return $this;
  124. }
  125. /**
  126. * Set multiple cookies at once
  127. *
  128. * @param array $cookies
  129. * @return void
  130. */
  131. public function setCookies(array $cookies)
  132. {
  133. foreach ($cookies as $key => $value) {
  134. $_COOKIE[$key] = $value;
  135. }
  136. return $this;
  137. }
  138. /**
  139. * Clear all cookies
  140. *
  141. * @return Zend_Controller_Request_HttpTestCase
  142. */
  143. public function clearCookies()
  144. {
  145. $_COOKIE = array();
  146. return $this;
  147. }
  148. /**
  149. * Set request method
  150. *
  151. * @param string $type
  152. * @return Zend_Controller_Request_HttpTestCase
  153. */
  154. public function setMethod($type)
  155. {
  156. $type = strtoupper(trim((string) $type));
  157. if (!in_array($type, $this->_validMethodTypes)) {
  158. // require_once 'Zend/Controller/Exception.php';
  159. throw new Zend_Controller_Exception('Invalid request method specified');
  160. }
  161. $this->_method = $type;
  162. return $this;
  163. }
  164. /**
  165. * Get request method
  166. *
  167. * @return string|null
  168. */
  169. public function getMethod()
  170. {
  171. return $this->_method;
  172. }
  173. /**
  174. * Set a request header
  175. *
  176. * @param string $key
  177. * @param string $value
  178. * @return Zend_Controller_Request_HttpTestCase
  179. */
  180. public function setHeader($key, $value)
  181. {
  182. $key = $this->_normalizeHeaderName($key);
  183. $this->_headers[$key] = (string) $value;
  184. return $this;
  185. }
  186. /**
  187. * Set request headers
  188. *
  189. * @param array $headers
  190. * @return Zend_Controller_Request_HttpTestCase
  191. */
  192. public function setHeaders(array $headers)
  193. {
  194. foreach ($headers as $key => $value) {
  195. $this->setHeader($key, $value);
  196. }
  197. return $this;
  198. }
  199. /**
  200. * Get request header
  201. *
  202. * @param string $header
  203. * @param mixed $default
  204. * @return string|null
  205. */
  206. public function getHeader($header, $default = null)
  207. {
  208. $header = $this->_normalizeHeaderName($header);
  209. if (array_key_exists($header, $this->_headers)) {
  210. return $this->_headers[$header];
  211. }
  212. return $default;
  213. }
  214. /**
  215. * Get all request headers
  216. *
  217. * @return array
  218. */
  219. public function getHeaders()
  220. {
  221. return $this->_headers;
  222. }
  223. /**
  224. * Clear request headers
  225. *
  226. * @return Zend_Controller_Request_HttpTestCase
  227. */
  228. public function clearHeaders()
  229. {
  230. $this->_headers = array();
  231. return $this;
  232. }
  233. /**
  234. * Get REQUEST_URI
  235. *
  236. * @return null|string
  237. */
  238. public function getRequestUri()
  239. {
  240. return $this->_requestUri;
  241. }
  242. /**
  243. * Normalize a header name for setting and retrieval
  244. *
  245. * @param string $name
  246. * @return string
  247. */
  248. protected function _normalizeHeaderName($name)
  249. {
  250. $name = strtoupper((string) $name);
  251. $name = str_replace('-', '_', $name);
  252. return $name;
  253. }
  254. }