DerivativeRequest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Deal with importing all those nasty globals and things
  4. *
  5. * Copyright © 2003 Brion Vibber <brion@pobox.com>
  6. * https://www.mediawiki.org/
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. * http://www.gnu.org/copyleft/gpl.html
  22. *
  23. * @file
  24. */
  25. /**
  26. * Similar to FauxRequest, but only fakes URL parameters and method
  27. * (POST or GET) and use the base request for the remaining stuff
  28. * (cookies, session and headers).
  29. *
  30. * @ingroup HTTP
  31. * @since 1.19
  32. */
  33. class DerivativeRequest extends FauxRequest {
  34. private $base;
  35. /**
  36. * @param WebRequest $base
  37. * @param array $data Array of *non*-urlencoded key => value pairs, the
  38. * fake GET/POST values
  39. * @param bool $wasPosted Whether to treat the data as POST
  40. */
  41. public function __construct( WebRequest $base, $data, $wasPosted = false ) {
  42. $this->base = $base;
  43. parent::__construct( $data, $wasPosted );
  44. }
  45. public function getCookie( $key, $prefix = null, $default = null ) {
  46. return $this->base->getCookie( $key, $prefix, $default );
  47. }
  48. public function getHeader( $name, $flags = 0 ) {
  49. return $this->base->getHeader( $name, $flags );
  50. }
  51. public function getAllHeaders() {
  52. return $this->base->getAllHeaders();
  53. }
  54. public function getSession() {
  55. return $this->base->getSession();
  56. }
  57. public function getSessionData( $key ) {
  58. return $this->base->getSessionData( $key );
  59. }
  60. public function setSessionData( $key, $data ) {
  61. $this->base->setSessionData( $key, $data );
  62. }
  63. public function getAcceptLang() {
  64. return $this->base->getAcceptLang();
  65. }
  66. public function getIP() {
  67. return $this->base->getIP();
  68. }
  69. public function getProtocol() {
  70. return $this->base->getProtocol();
  71. }
  72. public function getElapsedTime() {
  73. return $this->base->getElapsedTime();
  74. }
  75. }