Completed
Branch BUG-9456-request-params (7bb883)
by
unknown
373:51 queued 358:41
created

EE_Request::get_params()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
/**
3
 * class EE_Request
4
 *
5
 * @package         Event Espresso
6
 * @subpackage  /core/
7
 * @author          Brent Christensen
8
 *
9
 * ------------------------------------------------------------------------
10
 */
11
class EE_Request {
12
13
	/**
14
	 * @access private
15
	 * @var    array $_get $_GET parameters
16
	 */
17
	private $_get = array();
18
19
	/**
20
	 * @access private
21
	 * @var    array $_post $_POST parameters
22
	 */
23
	private $_post = array();
24
25
	/**
26
	 * @access private
27
	 * @var    array $_cookie $_COOKIE parameters
28
	 */
29
	private $_cookie = array();
30
31
	/**
32
	 * @access private
33
	 * @var    array $_params $_REQUEST parameters
34
	 */
35
	private $_params = array();
36
37
	/**
38
	 * whether current request is via AJAX
39
	 *
40
	 * @var    boolean
41
	 * @access public
42
	 */
43
	public $ajax = false;
44
45
	/**
46
	 * whether current request is via AJAX from the frontend of the site
47
	 *
48
	 * @var    boolean
49
	 * @access public
50
	 */
51
	public $front_ajax = false;
52
53
54
55
	/**
56
	 *    class constructor
57
	 *
58
	 * @access    public
59
	 * @param array $get
60
	 * @param array $post
61
	 * @param array $cookie
62
	 */
63
	public function __construct( $get, $post, $cookie ) {
64
		// grab request vars
65
		$this->_get    = $get;
66
		$this->_post   = $post;
67
		$this->_cookie = $cookie;
68
		$this->_params = array_merge( $get, $post );
69
		// AJAX ???
70
		$this->ajax       = defined( 'DOING_AJAX' ) ? true : false;
71
		$this->front_ajax = $this->is_set( 'ee_front_ajax' ) && $this->get( 'ee_front_ajax' ) == 1 ? true : false;
72
	}
73
74
75
76
	/**
77
	 * @return array
78
	 */
79
	public function get_params() {
80
		return $this->_get;
81
	}
82
83
84
85
	/**
86
	 * @return array
87
	 */
88
	public function post_params() {
89
		return $this->_post;
90
	}
91
92
93
94
	/**
95
	 * @return array
96
	 */
97
	public function cookie_params() {
98
		return $this->_cookie;
99
	}
100
101
102
103
	/**
104
	 * returns contents of $_REQUEST
105
	 * @return array
106
	 */
107
	public function params() {
108
		return $this->_params;
109
	}
110
111
112
113
	/**
114
	 *    setter
115
	 *
116
	 * @access    public
117
	 * @param      $key
118
	 * @param      $value
119
	 * @param bool $override_ee
120
	 * @return    void
121
	 */
122
	public function set( $key, $value, $override_ee = FALSE ) {
123
		// don't allow "ee" to be overwritten unless explicitly instructed to do so
124 View Code Duplication
		if ( $key != 'ee' || ( $key == 'ee' && empty( $this->_params['ee'] )) || ( $key == 'ee' && ! empty( $this->_params['ee'] ) && $override_ee )) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
125
			$this->_params[ $key ] = $value;
126
		}
127
	}
128
129
130
131
	/**
132
	 *    getter
133
	 *
134
	 * @access    public
135
	 * @param      $key
136
	 * @param null $default
137
	 * @return    mixed
138
	 */
139
	public function get( $key, $default = NULL ) {
140
		return isset( $this->_params[ $key ] ) ? $this->_params[ $key ] : $default;
141
	}
142
143
144
145
	/**
146
	 *    check if param exists
147
	 *
148
	 * @access    public
149
	 * @param $key
150
	 * @return    boolean
151
	 */
152
	public function is_set( $key ) {
153
		return isset( $this->_params[ $key ] ) ? TRUE : FALSE;
154
	}
155
156
157
158
	/**
159
	 *    remove param
160
	 *
161
	 * @access    public
162
	 * @param $key
163
	 * @param bool $unset_from_global_too
164
	 */
165
	public function un_set( $key, $unset_from_global_too = false ) {
166
		unset( $this->_params[ $key ] );
167
		if ( $unset_from_global_too ) {
168
			unset( $_REQUEST[ $key ] );
169
		}
170
	}
171
172
173
174
175
}
176
// End of file EE_Request.core.php
177
// Location: /core/request_stack/EE_Request.core.php