PageRenderTime 52ms CodeModel.GetById 30ms app.highlight 5ms RepoModel.GetById 15ms app.codeStats 0ms

/tests/mock/request.php

https://github.com/Jipem/phpbb
PHP | 117 lines | 84 code | 21 blank | 12 comment | 0 complexity | 3631ddfa04378970d9dd308d1a4a7f42 MD5 | raw file
  1<?php
  2/**
  3*
  4* This file is part of the phpBB Forum Software package.
  5*
  6* @copyright (c) phpBB Limited <https://www.phpbb.com>
  7* @license GNU General Public License, version 2 (GPL-2.0)
  8*
  9* For full copyright and license information, please see
 10* the docs/CREDITS.txt file.
 11*
 12*/
 13
 14class phpbb_mock_request implements \phpbb\request\request_interface
 15{
 16	protected $data;
 17
 18	protected $super_globals_disabled = false;
 19
 20	public function __construct($get = array(), $post = array(), $cookie = array(), $server = array(), $request = false, $files = array())
 21	{
 22		$this->data[\phpbb\request\request_interface::GET] = $get;
 23		$this->data[\phpbb\request\request_interface::POST] = $post;
 24		$this->data[\phpbb\request\request_interface::COOKIE] = $cookie;
 25		$this->data[\phpbb\request\request_interface::REQUEST] = ($request === false) ? $post + $get : $request;
 26		$this->data[\phpbb\request\request_interface::SERVER] = $server;
 27		$this->data[\phpbb\request\request_interface::FILES] = $files;
 28
 29		$this->disable_super_globals();
 30	}
 31
 32	public function overwrite($var_name, $value, $super_global = \phpbb\request\request_interface::REQUEST)
 33	{
 34		$this->data[$super_global][$var_name] = $value;
 35	}
 36
 37	public function variable($var_name, $default, $multibyte = false, $super_global = \phpbb\request\request_interface::REQUEST)
 38	{
 39		return isset($this->data[$super_global][$var_name]) ? $this->data[$super_global][$var_name] : $default;
 40	}
 41
 42	public function server($var_name, $default = '')
 43	{
 44		$super_global = \phpbb\request\request_interface::SERVER;
 45		return isset($this->data[$super_global][$var_name]) ? $this->data[$super_global][$var_name] : $default;
 46	}
 47
 48	public function header($header_name, $default = '')
 49	{
 50		$var_name = 'HTTP_' . str_replace('-', '_', strtoupper($header_name));
 51		return $this->server($var_name, $default);
 52	}
 53
 54	public function file($form_name)
 55	{
 56		$super_global = \phpbb\request\request_interface::FILES;
 57		return isset($this->data[$super_global][$form_name]) ? $this->data[$super_global][$form_name] : array();
 58	}
 59
 60	public function is_set_post($name)
 61	{
 62		return $this->is_set($name, \phpbb\request\request_interface::POST);
 63	}
 64
 65	public function is_set($var, $super_global = \phpbb\request\request_interface::REQUEST)
 66	{
 67		return isset($this->data[$super_global][$var]);
 68	}
 69
 70	public function is_ajax()
 71	{
 72		return false;
 73	}
 74
 75	public function is_secure()
 76	{
 77		return false;
 78	}
 79
 80	public function variable_names($super_global = \phpbb\request\request_interface::REQUEST)
 81	{
 82		return array_keys($this->data[$super_global]);
 83	}
 84
 85	public function get_super_global($super_global = \phpbb\request\request_interface::REQUEST)
 86	{
 87		return $this->data[$super_global];
 88	}
 89
 90	public function super_globals_disabled()
 91	{
 92		return $this->super_globals_disabled;
 93	}
 94
 95	public function disable_super_globals()
 96	{
 97		$this->super_globals_disabled = true;
 98	}
 99
100	public function enable_super_globals()
101	{
102		$this->super_globals_disabled = false;
103	}
104
105	/* custom methods */
106
107	public function set_header($header_name, $value)
108	{
109		$var_name = 'HTTP_' . str_replace('-', '_', strtoupper($header_name));
110		$this->data[\phpbb\request\request_interface::SERVER][$var_name] = $value;
111	}
112
113	public function merge($super_global = \phpbb\request\request_interface::REQUEST, $values)
114	{
115		$this->data[$super_global] = array_merge($this->data[$super_global], $values);
116	}
117}