Completed
Branch models-cleanup/model-objects-a... (bcae63)
by
unknown
64:36 queued 54:24
created
core/domain/DomainBase.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@
 block discarded – undo
121 121
 
122 122
 
123 123
     /**
124
-     * @return Version
124
+     * @return string
125 125
      */
126 126
     public function versionValueObject()
127 127
     {
Please login to merge, or discard this patch.
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -17,231 +17,231 @@
 block discarded – undo
17 17
 abstract class DomainBase implements DomainInterface
18 18
 {
19 19
 
20
-    const ASSETS_FOLDER = 'assets/';
21
-
22
-    /**
23
-     * Equivalent to `__FILE__` for main plugin file.
24
-     *
25
-     * @var FilePath
26
-     */
27
-    private $plugin_file;
28
-
29
-    /**
30
-     * String indicating version for plugin
31
-     *
32
-     * @var string
33
-     */
34
-    private $version;
35
-
36
-    /**
37
-     * @var string $plugin_basename
38
-     */
39
-    private $plugin_basename;
40
-
41
-    /**
42
-     * @var string $plugin_path
43
-     */
44
-    private $plugin_path;
45
-
46
-    /**
47
-     * @var string $plugin_url
48
-     */
49
-    private $plugin_url;
50
-
51
-    /**
52
-     * @var string $asset_namespace
53
-     */
54
-    private $asset_namespace;
55
-
56
-    /**
57
-     * @var string $assets_path
58
-     */
59
-    private $assets_path;
60
-
61
-    /**
62
-     * @var bool
63
-     */
64
-    protected $initialized = false;
65
-
66
-
67
-    /**
68
-     * Initializes internal properties.
69
-     *
70
-     * @param FilePath $plugin_file
71
-     * @param Version  $version
72
-     * @param string $asset_namespace
73
-     */
74
-    public function __construct(
75
-        FilePath $plugin_file,
76
-        Version $version,
77
-        string $asset_namespace = Domain::ASSET_NAMESPACE
78
-    ) {
79
-        $this->plugin_file = $plugin_file;
80
-        $this->version     = $version;
81
-        $this->initialize($asset_namespace);
82
-    }
83
-
84
-
85
-    /**
86
-     * @param string $asset_namespace
87
-     * @return void
88
-     * @since $VID:$
89
-     */
90
-    public function initialize($asset_namespace = Domain::ASSET_NAMESPACE)
91
-    {
92
-        if (! $this->initialized) {
93
-            $this->plugin_basename = plugin_basename($this->pluginFile());
94
-            $this->plugin_path     = plugin_dir_path($this->pluginFile());
95
-            $this->plugin_url      = plugin_dir_url($this->pluginFile());
96
-            $this->setAssetNamespace($asset_namespace);
97
-            $this->setDistributionAssetsPath();
98
-            $this->initialized = true;
99
-        }
100
-    }
101
-
102
-
103
-    /**
104
-     * @param string $asset_namespace
105
-     * @return void
106
-     */
107
-    public function setAssetNamespace($asset_namespace = Domain::ASSET_NAMESPACE)
108
-    {
109
-        if (! $this->asset_namespace) {
110
-            $this->asset_namespace = sanitize_key(
111
-                // convert directory separators to dashes and remove file extension
112
-                str_replace(['/', '.php'], ['-', ''], $asset_namespace)
113
-            );
114
-        }
115
-    }
116
-
117
-
118
-    /**
119
-     * @throws DomainException
120
-     * @since $VID:$
121
-     */
122
-    private function setDistributionAssetsPath()
123
-    {
124
-        $assets_folder_paths = [
125
-            $this->plugin_path . DomainBase::ASSETS_FOLDER,
126
-            $this->plugin_path . 'src/' . DomainBase::ASSETS_FOLDER,
127
-        ];
128
-        foreach ($assets_folder_paths as $assets_folder_path) {
129
-            if (is_readable($assets_folder_path)) {
130
-                $this->assets_path = trailingslashit($assets_folder_path);
131
-                // once we find a valid path, just break out of loop
132
-                break;
133
-            }
134
-        }
135
-    }
136
-
137
-
138
-    /**
139
-     * @return string
140
-     */
141
-    public function pluginFile(): string
142
-    {
143
-        return (string) $this->plugin_file;
144
-    }
145
-
146
-
147
-    /**
148
-     * @return FilePath
149
-     */
150
-    public function pluginFileObject(): FilePath
151
-    {
152
-        return $this->plugin_file;
153
-    }
154
-
155
-
156
-    /**
157
-     * @return string
158
-     */
159
-    public function pluginBasename(): string
160
-    {
161
-        return $this->plugin_basename;
162
-    }
163
-
164
-
165
-    /**
166
-     * @param string $additional_path
167
-     * @return string
168
-     */
169
-    public function pluginPath($additional_path = ''): string
170
-    {
171
-        return is_string($additional_path) && $additional_path !== ''
172
-            ? $this->plugin_path . $additional_path
173
-            : $this->plugin_path;
174
-    }
175
-
176
-
177
-    /**
178
-     * @param string $additional_path
179
-     * @return string
180
-     */
181
-    public function pluginUrl($additional_path = ''): string
182
-    {
183
-        return is_string($additional_path) && $additional_path !== ''
184
-            ? $this->plugin_url . $additional_path
185
-            : $this->plugin_url;
186
-    }
187
-
188
-
189
-    /**
190
-     * @return string
191
-     */
192
-    public function version(): string
193
-    {
194
-        return (string) $this->version;
195
-    }
196
-
197
-
198
-    /**
199
-     * @return Version
200
-     */
201
-    public function versionValueObject()
202
-    {
203
-        return $this->version;
204
-    }
205
-
206
-
207
-    /**
208
-     * @return string
209
-     */
210
-    public function distributionAssetsFolder(): string
211
-    {
212
-        return DomainBase::ASSETS_FOLDER;
213
-    }
214
-
215
-
216
-    /**
217
-     * @param string $additional_path
218
-     * @return string
219
-     */
220
-    public function distributionAssetsPath($additional_path = ''): string
221
-    {
222
-        return is_string($additional_path) && $additional_path !== ''
223
-            ? $this->assets_path . $additional_path
224
-            : $this->assets_path;
225
-    }
226
-
227
-
228
-    /**
229
-     * @param string $additional_path
230
-     * @return string
231
-     */
232
-    public function distributionAssetsUrl($additional_path = ''): string
233
-    {
234
-        return is_string($additional_path) && $additional_path !== ''
235
-            ? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path
236
-            : $this->plugin_url . DomainBase::ASSETS_FOLDER;
237
-    }
238
-
239
-
240
-    /**
241
-     * @return string
242
-     */
243
-    public function assetNamespace(): string
244
-    {
245
-        return $this->asset_namespace;
246
-    }
20
+	const ASSETS_FOLDER = 'assets/';
21
+
22
+	/**
23
+	 * Equivalent to `__FILE__` for main plugin file.
24
+	 *
25
+	 * @var FilePath
26
+	 */
27
+	private $plugin_file;
28
+
29
+	/**
30
+	 * String indicating version for plugin
31
+	 *
32
+	 * @var string
33
+	 */
34
+	private $version;
35
+
36
+	/**
37
+	 * @var string $plugin_basename
38
+	 */
39
+	private $plugin_basename;
40
+
41
+	/**
42
+	 * @var string $plugin_path
43
+	 */
44
+	private $plugin_path;
45
+
46
+	/**
47
+	 * @var string $plugin_url
48
+	 */
49
+	private $plugin_url;
50
+
51
+	/**
52
+	 * @var string $asset_namespace
53
+	 */
54
+	private $asset_namespace;
55
+
56
+	/**
57
+	 * @var string $assets_path
58
+	 */
59
+	private $assets_path;
60
+
61
+	/**
62
+	 * @var bool
63
+	 */
64
+	protected $initialized = false;
65
+
66
+
67
+	/**
68
+	 * Initializes internal properties.
69
+	 *
70
+	 * @param FilePath $plugin_file
71
+	 * @param Version  $version
72
+	 * @param string $asset_namespace
73
+	 */
74
+	public function __construct(
75
+		FilePath $plugin_file,
76
+		Version $version,
77
+		string $asset_namespace = Domain::ASSET_NAMESPACE
78
+	) {
79
+		$this->plugin_file = $plugin_file;
80
+		$this->version     = $version;
81
+		$this->initialize($asset_namespace);
82
+	}
83
+
84
+
85
+	/**
86
+	 * @param string $asset_namespace
87
+	 * @return void
88
+	 * @since $VID:$
89
+	 */
90
+	public function initialize($asset_namespace = Domain::ASSET_NAMESPACE)
91
+	{
92
+		if (! $this->initialized) {
93
+			$this->plugin_basename = plugin_basename($this->pluginFile());
94
+			$this->plugin_path     = plugin_dir_path($this->pluginFile());
95
+			$this->plugin_url      = plugin_dir_url($this->pluginFile());
96
+			$this->setAssetNamespace($asset_namespace);
97
+			$this->setDistributionAssetsPath();
98
+			$this->initialized = true;
99
+		}
100
+	}
101
+
102
+
103
+	/**
104
+	 * @param string $asset_namespace
105
+	 * @return void
106
+	 */
107
+	public function setAssetNamespace($asset_namespace = Domain::ASSET_NAMESPACE)
108
+	{
109
+		if (! $this->asset_namespace) {
110
+			$this->asset_namespace = sanitize_key(
111
+				// convert directory separators to dashes and remove file extension
112
+				str_replace(['/', '.php'], ['-', ''], $asset_namespace)
113
+			);
114
+		}
115
+	}
116
+
117
+
118
+	/**
119
+	 * @throws DomainException
120
+	 * @since $VID:$
121
+	 */
122
+	private function setDistributionAssetsPath()
123
+	{
124
+		$assets_folder_paths = [
125
+			$this->plugin_path . DomainBase::ASSETS_FOLDER,
126
+			$this->plugin_path . 'src/' . DomainBase::ASSETS_FOLDER,
127
+		];
128
+		foreach ($assets_folder_paths as $assets_folder_path) {
129
+			if (is_readable($assets_folder_path)) {
130
+				$this->assets_path = trailingslashit($assets_folder_path);
131
+				// once we find a valid path, just break out of loop
132
+				break;
133
+			}
134
+		}
135
+	}
136
+
137
+
138
+	/**
139
+	 * @return string
140
+	 */
141
+	public function pluginFile(): string
142
+	{
143
+		return (string) $this->plugin_file;
144
+	}
145
+
146
+
147
+	/**
148
+	 * @return FilePath
149
+	 */
150
+	public function pluginFileObject(): FilePath
151
+	{
152
+		return $this->plugin_file;
153
+	}
154
+
155
+
156
+	/**
157
+	 * @return string
158
+	 */
159
+	public function pluginBasename(): string
160
+	{
161
+		return $this->plugin_basename;
162
+	}
163
+
164
+
165
+	/**
166
+	 * @param string $additional_path
167
+	 * @return string
168
+	 */
169
+	public function pluginPath($additional_path = ''): string
170
+	{
171
+		return is_string($additional_path) && $additional_path !== ''
172
+			? $this->plugin_path . $additional_path
173
+			: $this->plugin_path;
174
+	}
175
+
176
+
177
+	/**
178
+	 * @param string $additional_path
179
+	 * @return string
180
+	 */
181
+	public function pluginUrl($additional_path = ''): string
182
+	{
183
+		return is_string($additional_path) && $additional_path !== ''
184
+			? $this->plugin_url . $additional_path
185
+			: $this->plugin_url;
186
+	}
187
+
188
+
189
+	/**
190
+	 * @return string
191
+	 */
192
+	public function version(): string
193
+	{
194
+		return (string) $this->version;
195
+	}
196
+
197
+
198
+	/**
199
+	 * @return Version
200
+	 */
201
+	public function versionValueObject()
202
+	{
203
+		return $this->version;
204
+	}
205
+
206
+
207
+	/**
208
+	 * @return string
209
+	 */
210
+	public function distributionAssetsFolder(): string
211
+	{
212
+		return DomainBase::ASSETS_FOLDER;
213
+	}
214
+
215
+
216
+	/**
217
+	 * @param string $additional_path
218
+	 * @return string
219
+	 */
220
+	public function distributionAssetsPath($additional_path = ''): string
221
+	{
222
+		return is_string($additional_path) && $additional_path !== ''
223
+			? $this->assets_path . $additional_path
224
+			: $this->assets_path;
225
+	}
226
+
227
+
228
+	/**
229
+	 * @param string $additional_path
230
+	 * @return string
231
+	 */
232
+	public function distributionAssetsUrl($additional_path = ''): string
233
+	{
234
+		return is_string($additional_path) && $additional_path !== ''
235
+			? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path
236
+			: $this->plugin_url . DomainBase::ASSETS_FOLDER;
237
+	}
238
+
239
+
240
+	/**
241
+	 * @return string
242
+	 */
243
+	public function assetNamespace(): string
244
+	{
245
+		return $this->asset_namespace;
246
+	}
247 247
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      */
90 90
     public function initialize($asset_namespace = Domain::ASSET_NAMESPACE)
91 91
     {
92
-        if (! $this->initialized) {
92
+        if ( ! $this->initialized) {
93 93
             $this->plugin_basename = plugin_basename($this->pluginFile());
94 94
             $this->plugin_path     = plugin_dir_path($this->pluginFile());
95 95
             $this->plugin_url      = plugin_dir_url($this->pluginFile());
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
      */
107 107
     public function setAssetNamespace($asset_namespace = Domain::ASSET_NAMESPACE)
108 108
     {
109
-        if (! $this->asset_namespace) {
109
+        if ( ! $this->asset_namespace) {
110 110
             $this->asset_namespace = sanitize_key(
111 111
                 // convert directory separators to dashes and remove file extension
112 112
                 str_replace(['/', '.php'], ['-', ''], $asset_namespace)
@@ -122,8 +122,8 @@  discard block
 block discarded – undo
122 122
     private function setDistributionAssetsPath()
123 123
     {
124 124
         $assets_folder_paths = [
125
-            $this->plugin_path . DomainBase::ASSETS_FOLDER,
126
-            $this->plugin_path . 'src/' . DomainBase::ASSETS_FOLDER,
125
+            $this->plugin_path.DomainBase::ASSETS_FOLDER,
126
+            $this->plugin_path.'src/'.DomainBase::ASSETS_FOLDER,
127 127
         ];
128 128
         foreach ($assets_folder_paths as $assets_folder_path) {
129 129
             if (is_readable($assets_folder_path)) {
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
     public function pluginPath($additional_path = ''): string
170 170
     {
171 171
         return is_string($additional_path) && $additional_path !== ''
172
-            ? $this->plugin_path . $additional_path
172
+            ? $this->plugin_path.$additional_path
173 173
             : $this->plugin_path;
174 174
     }
175 175
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
     public function pluginUrl($additional_path = ''): string
182 182
     {
183 183
         return is_string($additional_path) && $additional_path !== ''
184
-            ? $this->plugin_url . $additional_path
184
+            ? $this->plugin_url.$additional_path
185 185
             : $this->plugin_url;
186 186
     }
187 187
 
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
     public function distributionAssetsPath($additional_path = ''): string
221 221
     {
222 222
         return is_string($additional_path) && $additional_path !== ''
223
-            ? $this->assets_path . $additional_path
223
+            ? $this->assets_path.$additional_path
224 224
             : $this->assets_path;
225 225
     }
226 226
 
@@ -232,8 +232,8 @@  discard block
 block discarded – undo
232 232
     public function distributionAssetsUrl($additional_path = ''): string
233 233
     {
234 234
         return is_string($additional_path) && $additional_path !== ''
235
-            ? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path
236
-            : $this->plugin_url . DomainBase::ASSETS_FOLDER;
235
+            ? $this->plugin_url.DomainBase::ASSETS_FOLDER.$additional_path
236
+            : $this->plugin_url.DomainBase::ASSETS_FOLDER;
237 237
     }
238 238
 
239 239
 
Please login to merge, or discard this patch.
core/domain/entities/contexts/RequestTypeContext.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@
 block discarded – undo
91 91
     public function __construct($slug, $description)
92 92
     {
93 93
         parent::__construct($slug, $description);
94
-        if (! in_array($this->slug(), $this->validRequestTypes(), true)) {
94
+        if ( ! in_array($this->slug(), $this->validRequestTypes(), true)) {
95 95
             throw new InvalidArgumentException(
96 96
                 sprintf(
97 97
                     esc_html__(
Please login to merge, or discard this patch.
Indentation   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -16,185 +16,185 @@
 block discarded – undo
16 16
 class RequestTypeContext extends Context
17 17
 {
18 18
 
19
-    /**
20
-     * indicates that the current request involves some form of activation
21
-     */
22
-    const ACTIVATION = 'activation-request';
23
-
24
-    /**
25
-     * indicates that the current request is for the admin but is not being made via AJAX
26
-     */
27
-    const ADMIN = 'non-ajax-admin-request';
28
-
29
-    /**
30
-     * indicates that the current request is for the admin AND is being made via AJAX
31
-     */
32
-    const AJAX_ADMIN = 'admin-ajax-request';
33
-
34
-    /**
35
-     * indicates that the current request is for the frontend AND is being made via AJAX
36
-     */
37
-    const AJAX_FRONT = 'frontend-ajax-request';
38
-
39
-    /**
40
-     * indicates that the current request is for the WP Heartbeat
41
-     */
42
-    const AJAX_HEARTBEAT = 'admin-ajax-heartbeat';
43
-
44
-    /**
45
-     * indicates that the current request is being made via AJAX, but is NOT for EE
46
-     */
47
-    const AJAX_OTHER = 'other-ajax-request';
48
-
49
-    /**
50
-     * indicates that the current request is for the EE REST API
51
-     */
52
-    const API = 'rest-api';
53
-
54
-    /**
55
-     * indicates that the current request is from the command line
56
-     */
57
-    const CLI = 'command-line';
58
-
59
-    /**
60
-     * indicates that the current request is for a WP_Cron
61
-     */
62
-    const CRON = 'wp-cron';
63
-
64
-    /**
65
-     * indicates that the current request is for a feed (ie: RSS)
66
-     */
67
-    const FEED = 'feed-request';
68
-
69
-    /**
70
-     * indicates that the current request is for the frontend but is not being made via AJAX
71
-     */
72
-    const FRONTEND = 'non-ajax-frontend-request';
73
-
74
-    /**
75
-     * indicates that the current request is for content that is to be displayed within an iframe
76
-     */
77
-    const IFRAME = 'iframe-request';
78
-
79
-    /**
80
-     * indicates that the current request is for the EE GraphQL manager
81
-     */
82
-    const GQL = 'graphql';
83
-
84
-    /**
85
-     * indicates that the current request is for the WP REST API
86
-     */
87
-    const WP_API = 'wp-rest-api';
88
-
89
-    /**
90
-     * indicates that the current request is a loopback sent from WP core to test for errors
91
-     */
92
-    const WP_SCRAPE = 'wordpress-scrape';
93
-
94
-    /**
95
-     * @var boolean $is_activation
96
-     */
97
-    private $is_activation = false;
98
-
99
-    /**
100
-     * @var boolean $is_unit_testing
101
-     */
102
-    private $is_unit_testing = false;
103
-
104
-    /**
105
-     * @var array $valid_request_types
106
-     */
107
-    private $valid_request_types = array();
108
-
109
-
110
-    /**
111
-     * RequestTypeContext constructor.
112
-     *
113
-     * @param string $slug
114
-     * @param string $description
115
-     * @throws InvalidArgumentException
116
-     */
117
-    public function __construct($slug, $description)
118
-    {
119
-        parent::__construct($slug, $description);
120
-        if (! in_array($this->slug(), $this->validRequestTypes(), true)) {
121
-            throw new InvalidArgumentException(
122
-                sprintf(
123
-                    esc_html__(
124
-                        'The RequestTypeContext slug must be one of the following values: %1$s %2$s',
125
-                        'event_espresso'
126
-                    ),
127
-                    '<br />',
128
-                    var_export($this->validRequestTypes(), true)
129
-                )
130
-            );
131
-        }
132
-    }
133
-
134
-
135
-    /**
136
-     * @return array
137
-     */
138
-    public function validRequestTypes()
139
-    {
140
-        if (empty($this->valid_request_types)) {
141
-            $this->valid_request_types = apply_filters(
142
-                'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes',
143
-                array(
144
-                    RequestTypeContext::ACTIVATION,
145
-                    RequestTypeContext::ADMIN,
146
-                    RequestTypeContext::AJAX_ADMIN,
147
-                    RequestTypeContext::AJAX_FRONT,
148
-                    RequestTypeContext::AJAX_HEARTBEAT,
149
-                    RequestTypeContext::AJAX_OTHER,
150
-                    RequestTypeContext::API,
151
-                    RequestTypeContext::CLI,
152
-                    RequestTypeContext::CRON,
153
-                    RequestTypeContext::FEED,
154
-                    RequestTypeContext::FRONTEND,
155
-                    RequestTypeContext::GQL,
156
-                    RequestTypeContext::IFRAME,
157
-                    RequestTypeContext::WP_API,
158
-                    RequestTypeContext::WP_SCRAPE,
159
-                )
160
-            );
161
-        }
162
-        return $this->valid_request_types;
163
-    }
164
-
165
-
166
-    /**
167
-     * @return bool
168
-     */
169
-    public function isActivation()
170
-    {
171
-        return $this->is_activation;
172
-    }
173
-
174
-
175
-    /**
176
-     * @param bool $is_activation
177
-     */
178
-    public function setIsActivation($is_activation = false)
179
-    {
180
-        $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN);
181
-    }
182
-
183
-
184
-    /**
185
-     * @return bool
186
-     */
187
-    public function isUnitTesting()
188
-    {
189
-        return $this->is_unit_testing;
190
-    }
191
-
192
-
193
-    /**
194
-     * @param bool $is_unit_testing
195
-     */
196
-    public function setIsUnitTesting($is_unit_testing = false)
197
-    {
198
-        $this->is_unit_testing = filter_var($is_unit_testing, FILTER_VALIDATE_BOOLEAN);
199
-    }
19
+	/**
20
+	 * indicates that the current request involves some form of activation
21
+	 */
22
+	const ACTIVATION = 'activation-request';
23
+
24
+	/**
25
+	 * indicates that the current request is for the admin but is not being made via AJAX
26
+	 */
27
+	const ADMIN = 'non-ajax-admin-request';
28
+
29
+	/**
30
+	 * indicates that the current request is for the admin AND is being made via AJAX
31
+	 */
32
+	const AJAX_ADMIN = 'admin-ajax-request';
33
+
34
+	/**
35
+	 * indicates that the current request is for the frontend AND is being made via AJAX
36
+	 */
37
+	const AJAX_FRONT = 'frontend-ajax-request';
38
+
39
+	/**
40
+	 * indicates that the current request is for the WP Heartbeat
41
+	 */
42
+	const AJAX_HEARTBEAT = 'admin-ajax-heartbeat';
43
+
44
+	/**
45
+	 * indicates that the current request is being made via AJAX, but is NOT for EE
46
+	 */
47
+	const AJAX_OTHER = 'other-ajax-request';
48
+
49
+	/**
50
+	 * indicates that the current request is for the EE REST API
51
+	 */
52
+	const API = 'rest-api';
53
+
54
+	/**
55
+	 * indicates that the current request is from the command line
56
+	 */
57
+	const CLI = 'command-line';
58
+
59
+	/**
60
+	 * indicates that the current request is for a WP_Cron
61
+	 */
62
+	const CRON = 'wp-cron';
63
+
64
+	/**
65
+	 * indicates that the current request is for a feed (ie: RSS)
66
+	 */
67
+	const FEED = 'feed-request';
68
+
69
+	/**
70
+	 * indicates that the current request is for the frontend but is not being made via AJAX
71
+	 */
72
+	const FRONTEND = 'non-ajax-frontend-request';
73
+
74
+	/**
75
+	 * indicates that the current request is for content that is to be displayed within an iframe
76
+	 */
77
+	const IFRAME = 'iframe-request';
78
+
79
+	/**
80
+	 * indicates that the current request is for the EE GraphQL manager
81
+	 */
82
+	const GQL = 'graphql';
83
+
84
+	/**
85
+	 * indicates that the current request is for the WP REST API
86
+	 */
87
+	const WP_API = 'wp-rest-api';
88
+
89
+	/**
90
+	 * indicates that the current request is a loopback sent from WP core to test for errors
91
+	 */
92
+	const WP_SCRAPE = 'wordpress-scrape';
93
+
94
+	/**
95
+	 * @var boolean $is_activation
96
+	 */
97
+	private $is_activation = false;
98
+
99
+	/**
100
+	 * @var boolean $is_unit_testing
101
+	 */
102
+	private $is_unit_testing = false;
103
+
104
+	/**
105
+	 * @var array $valid_request_types
106
+	 */
107
+	private $valid_request_types = array();
108
+
109
+
110
+	/**
111
+	 * RequestTypeContext constructor.
112
+	 *
113
+	 * @param string $slug
114
+	 * @param string $description
115
+	 * @throws InvalidArgumentException
116
+	 */
117
+	public function __construct($slug, $description)
118
+	{
119
+		parent::__construct($slug, $description);
120
+		if (! in_array($this->slug(), $this->validRequestTypes(), true)) {
121
+			throw new InvalidArgumentException(
122
+				sprintf(
123
+					esc_html__(
124
+						'The RequestTypeContext slug must be one of the following values: %1$s %2$s',
125
+						'event_espresso'
126
+					),
127
+					'<br />',
128
+					var_export($this->validRequestTypes(), true)
129
+				)
130
+			);
131
+		}
132
+	}
133
+
134
+
135
+	/**
136
+	 * @return array
137
+	 */
138
+	public function validRequestTypes()
139
+	{
140
+		if (empty($this->valid_request_types)) {
141
+			$this->valid_request_types = apply_filters(
142
+				'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes',
143
+				array(
144
+					RequestTypeContext::ACTIVATION,
145
+					RequestTypeContext::ADMIN,
146
+					RequestTypeContext::AJAX_ADMIN,
147
+					RequestTypeContext::AJAX_FRONT,
148
+					RequestTypeContext::AJAX_HEARTBEAT,
149
+					RequestTypeContext::AJAX_OTHER,
150
+					RequestTypeContext::API,
151
+					RequestTypeContext::CLI,
152
+					RequestTypeContext::CRON,
153
+					RequestTypeContext::FEED,
154
+					RequestTypeContext::FRONTEND,
155
+					RequestTypeContext::GQL,
156
+					RequestTypeContext::IFRAME,
157
+					RequestTypeContext::WP_API,
158
+					RequestTypeContext::WP_SCRAPE,
159
+				)
160
+			);
161
+		}
162
+		return $this->valid_request_types;
163
+	}
164
+
165
+
166
+	/**
167
+	 * @return bool
168
+	 */
169
+	public function isActivation()
170
+	{
171
+		return $this->is_activation;
172
+	}
173
+
174
+
175
+	/**
176
+	 * @param bool $is_activation
177
+	 */
178
+	public function setIsActivation($is_activation = false)
179
+	{
180
+		$this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN);
181
+	}
182
+
183
+
184
+	/**
185
+	 * @return bool
186
+	 */
187
+	public function isUnitTesting()
188
+	{
189
+		return $this->is_unit_testing;
190
+	}
191
+
192
+
193
+	/**
194
+	 * @param bool $is_unit_testing
195
+	 */
196
+	public function setIsUnitTesting($is_unit_testing = false)
197
+	{
198
+		$this->is_unit_testing = filter_var($is_unit_testing, FILTER_VALIDATE_BOOLEAN);
199
+	}
200 200
 }
Please login to merge, or discard this patch.
core/libraries/messages/validators/EE_Messages_Validator.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -505,7 +505,7 @@
 block discarded – undo
505 505
      *
506 506
      * @param  string $value            string to evaluate
507 507
      * @param  array  $valid_shortcodes array of shortcodes that are acceptable.
508
-     * @return mixed (bool|string)  return either a list of invalid shortcodes OR false if the shortcodes validate.
508
+     * @return false|string (bool|string)  return either a list of invalid shortcodes OR false if the shortcodes validate.
509 509
      */
510 510
     protected function _invalid_shortcodes($value, $valid_shortcodes)
511 511
     {
Please login to merge, or discard this patch.
Indentation   +624 added lines, -624 removed lines patch added patch discarded remove patch
@@ -17,628 +17,628 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * These properties just hold the name for the Messenger and Message Type (defined by child classes).
22
-     * These are used for retrieving objects etc.
23
-     *
24
-     * @var string
25
-     */
26
-    protected $_m_name;
27
-    protected $_mt_name;
28
-
29
-
30
-    /**
31
-     * This will hold any error messages from the validation process.
32
-     * The _errors property holds an associative array of error messages
33
-     * listing the field as the key and the message as the value.
34
-     *
35
-     * @var array()
36
-     */
37
-    private $_errors = array();
38
-
39
-
40
-    /**
41
-     * holds an array of fields being validated
42
-     *
43
-     * @var array
44
-     */
45
-    protected $_fields;
46
-
47
-
48
-    /**
49
-     * this will hold the incoming context
50
-     *
51
-     * @var string
52
-     */
53
-    protected $_context;
54
-
55
-
56
-    /**
57
-     * this holds an array of fields and the relevant validation information
58
-     * that the incoming fields data get validated against.
59
-     * This gets setup in the _set_props() method.
60
-     *
61
-     * @var array
62
-     */
63
-    protected $_validators;
64
-
65
-
66
-    /**
67
-     * holds the messenger object
68
-     *
69
-     * @var object
70
-     */
71
-    protected $_messenger;
72
-
73
-
74
-    /**
75
-     * holds the message type object
76
-     *
77
-     * @var object
78
-     */
79
-    protected $_message_type;
80
-
81
-
82
-    /**
83
-     * will hold any valid_shortcode modifications made by the _modify_validator() method.
84
-     *
85
-     * @var array
86
-     */
87
-    protected $_valid_shortcodes_modifier;
88
-
89
-
90
-    /**
91
-     * There may be times where a message type wants to include a shortcode group but exclude specific
92
-     * shortcodes.  If that's the case then it can set this property as an array of shortcodes to exclude and
93
-     * they will not be allowed.
94
-     * Array should be indexed by field and values are an array of specific shortcodes to exclude.
95
-     *
96
-     * @var array
97
-     */
98
-    protected $_specific_shortcode_excludes = array();
99
-
100
-
101
-    /**
102
-     * Runs the validator using the incoming fields array as the fields/values to check.
103
-     *
104
-     * @param array $fields The fields sent by the EEM object.
105
-     * @param       $context
106
-     * @throws EE_Error
107
-     * @throws ReflectionException
108
-     */
109
-    public function __construct($fields, $context)
110
-    {
111
-        // check that _m_name and _mt_name have been set by child class otherwise we get out.
112
-        if (empty($this->_m_name) || empty($this->_mt_name)) {
113
-            throw new EE_Error(
114
-                esc_html__(
115
-                    'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property.  Check that the child class is doing this',
116
-                    'event_espresso'
117
-                )
118
-            );
119
-        }
120
-        $this->_fields  = $fields;
121
-        $this->_context = $context;
122
-
123
-        // load messenger and message_type objects and the related shortcode objects.
124
-        $this->_load_objects();
125
-
126
-
127
-        // modify any messenger/message_type specific validation instructions.  This is what child classes define.
128
-        $this->_modify_validator();
129
-
130
-
131
-        // let's set validators property
132
-        $this->_set_validators();
133
-    }
134
-
135
-
136
-    /**
137
-     * Child classes instantiate this and use it to modify the _validator_config array property
138
-     * for the messenger using messengers set_validate_config() method.
139
-     * This is so we can specify specific validation instructions for a messenger/message_type combo
140
-     * that aren't handled by the defaults setup in the messenger.
141
-     *
142
-     * @abstract
143
-     * @access protected
144
-     * @return void
145
-     */
146
-    abstract protected function _modify_validator();
147
-
148
-
149
-    /**
150
-     * loads all objects used by validator
151
-     *
152
-     * @access private
153
-     * @throws \EE_Error
154
-     */
155
-    private function _load_objects()
156
-    {
157
-        // load messenger
158
-        $messenger = ucwords(str_replace('_', ' ', $this->_m_name));
159
-        $messenger = str_replace(' ', '_', $messenger);
160
-        $messenger = 'EE_' . $messenger . '_messenger';
161
-
162
-        if (! class_exists($messenger)) {
163
-            throw new EE_Error(
164
-                sprintf(
165
-                    esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'),
166
-                    $this->_m_name
167
-                )
168
-            );
169
-        }
170
-
171
-        $this->_messenger = new $messenger();
172
-
173
-        // load message type
174
-        $message_type = ucwords(str_replace('_', ' ', $this->_mt_name));
175
-        $message_type = str_replace(' ', '_', $message_type);
176
-        $message_type = 'EE_' . $message_type . '_message_type';
177
-
178
-        if (! class_exists($message_type)) {
179
-            throw new EE_Error(
180
-                sprintf(
181
-                    esc_html__('There is no message type class for the given string (%s)', 'event_espresso'),
182
-                    $this->_mt_name
183
-                )
184
-            );
185
-        }
186
-
187
-        $this->_message_type = new $message_type();
188
-    }
189
-
190
-
191
-    /**
192
-     * used to set the $_validators property
193
-     *
194
-     * @access private
195
-     * @return void
196
-     * @throws ReflectionException
197
-     */
198
-    private function _set_validators()
199
-    {
200
-        // let's get all valid shortcodes from mt and message type
201
-        // (messenger will have its set in the _validator_config property for the messenger)
202
-        $mt_codes = $this->_message_type->get_valid_shortcodes();
203
-
204
-
205
-        // get messenger validator_config
206
-        $msgr_validator = $this->_messenger->get_validator_config();
207
-
208
-
209
-        // we only want the valid shortcodes for the given context!
210
-        $context  = $this->_context;
211
-        $mt_codes = $mt_codes[ $context ];
212
-
213
-        // in this first loop we're just getting all shortcode group indexes from the msgr_validator
214
-        // into a single array (so we can get the appropriate shortcode objects for the groups)
215
-        $shortcode_groups = $mt_codes;
216
-        $groups_per_field = array();
217
-
218
-        foreach ($msgr_validator as $field => $config) {
219
-            if (empty($config) || ! isset($config['shortcodes'])) {
220
-                continue;
221
-            }  //Nothing to see here.
222
-            $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes);
223
-            $shortcode_groups         = array_merge($config['shortcodes'], $shortcode_groups);
224
-        }
225
-
226
-        $shortcode_groups = array_unique($shortcode_groups);
227
-
228
-        // okay now we've got our groups.
229
-        // Let's get the codes from the objects into an array indexed by group for easy retrieval later.
230
-        $codes_from_objs = array();
231
-
232
-        foreach ($shortcode_groups as $group) {
233
-            $ref       = ucwords(str_replace('_', ' ', $group));
234
-            $ref       = str_replace(' ', '_', $ref);
235
-            $classname = 'EE_' . $ref . '_Shortcodes';
236
-            if (class_exists($classname)) {
237
-                $a                       = new ReflectionClass($classname);
238
-                $obj                     = $a->newInstance();
239
-                $codes_from_objs[ $group ] = $obj->get_shortcodes();
240
-            }
241
-        }
242
-
243
-
244
-        // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique)
245
-        $final_mt_codes = array();
246
-        foreach ($mt_codes as $group) {
247
-            $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]);
248
-        }
249
-
250
-        $mt_codes = $final_mt_codes;
251
-
252
-
253
-        // k now in this next loop we're going to loop through $msgr_validator again
254
-        // and setup the _validators property from the data we've setup so far.
255
-        foreach ($msgr_validator as $field => $config) {
256
-            // if required shortcode is not in our list of codes for the given field, then we skip this field.
257
-            $required = isset($config['required'])
258
-                ? array_intersect($config['required'], array_keys($mt_codes))
259
-                : true;
260
-            if (empty($required)) {
261
-                continue;
262
-            }
263
-
264
-            if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) {
265
-                // If we have an override then we use it to indicate the codes we want.
266
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
267
-                    $this->_valid_shortcodes_modifier[ $context ][ $field ],
268
-                    $codes_from_objs
269
-                );
270
-            } elseif (isset($groups_per_field[ $field ])) {
271
-                // if we have specific shortcodes for a field then we need to use them
272
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
273
-                    $groups_per_field[ $field ],
274
-                    $codes_from_objs
275
-                );
276
-            } elseif (empty($config)) {
277
-                // if empty config then we're assuming we're just going to use the shortcodes from the message type
278
-                // context
279
-                $this->_validators[ $field ]['shortcodes'] = $mt_codes;
280
-            } elseif (isset($config['specific_shortcodes'])) {
281
-                // if we have specific shortcodes then we need to use them
282
-                $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes'];
283
-            } else {
284
-                // otherwise the shortcodes are what is set by the messenger for that field
285
-                foreach ($config['shortcodes'] as $group) {
286
-                    $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes'])
287
-                        ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ])
288
-                        : $codes_from_objs[ $group ];
289
-                }
290
-            }
291
-
292
-            // now let's just make sure that any excluded specific shortcodes are removed.
293
-            $specific_excludes = $this->get_specific_shortcode_excludes();
294
-            if (isset($specific_excludes[ $field ])) {
295
-                foreach ($specific_excludes[ $field ] as $sex) {
296
-                    if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) {
297
-                        unset($this->_validators[ $field ]['shortcodes'][ $sex ]);
298
-                    }
299
-                }
300
-            }
301
-
302
-            // hey! don't forget to include the type if present!
303
-            $this->_validators[ $field ]['type'] = isset($config['type']) ? $config['type'] : null;
304
-        }
305
-    }
306
-
307
-
308
-    /**
309
-     * This just returns the validators property that contains information
310
-     * about the various shortcodes and their availability with each field
311
-     *
312
-     * @return array
313
-     */
314
-    public function get_validators()
315
-    {
316
-        return $this->_validators;
317
-    }
318
-
319
-
320
-    /**
321
-     * This simply returns the specific shortcode_excludes property that is set.
322
-     *
323
-     * @since 4.5.0
324
-     * @return array
325
-     */
326
-    public function get_specific_shortcode_excludes()
327
-    {
328
-        // specific validator filter
329
-        $shortcode_excludes = apply_filters(
330
-            'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;',
331
-            $this->_specific_shortcode_excludes,
332
-            $this->_context
333
-        );
334
-        // global filter
335
-        return apply_filters(
336
-            'FHEE__EE_Messages_Validator__get_specific_shortcode_excludes',
337
-            $shortcode_excludes,
338
-            $this->_context,
339
-            $this
340
-        );
341
-    }
342
-
343
-
344
-    /**
345
-     * This is the main method that handles validation
346
-     * What it does is loop through the _fields (the ones that get validated)
347
-     * and checks them against the shortcodes array for the field and the 'type' indicated by the
348
-     *
349
-     * @access public
350
-     * @return mixed (bool|array)  if errors present we return the array otherwise true
351
-     */
352
-    public function validate()
353
-    {
354
-        // some defaults
355
-        $template_fields = $this->_messenger->get_template_fields();
356
-        // loop through the fields and check!
357
-        foreach ($this->_fields as $field => $value) {
358
-            $this->_errors[ $field ] = array();
359
-            $err_msg               = '';
360
-            $field_label           = '';
361
-            // if field is not present in the _validators array then we continue
362
-            if (! isset($this->_validators[ $field ])) {
363
-                unset($this->_errors[ $field ]);
364
-                continue;
365
-            }
366
-
367
-            // get the translated field label!
368
-            // first check if it's in the main fields list
369
-            if (isset($template_fields[ $field ])) {
370
-                if (empty($template_fields[ $field ])) {
371
-                    $field_label = $field;
372
-                } else {
373
-                    // most likely the field is found in the 'extra' array.
374
-                    $field_label = $template_fields[ $field ]['label'];
375
-                }
376
-            }
377
-
378
-            // if field label is empty OR is equal to the current field
379
-            // then we need to loop through the 'extra' fields in the template_fields config (if present)
380
-            if (isset($template_fields['extra']) && (empty($field_label) || $field_label === $field)) {
381
-                foreach ($template_fields['extra'] as $main_field => $secondary_field) {
382
-                    foreach ($secondary_field as $name => $values) {
383
-                        if ($name === $field) {
384
-                            $field_label = $values['label'];
385
-                        }
386
-
387
-                        // if we've got a 'main' secondary field, let's see if that matches what field we're on
388
-                        // which means it contains the label for this field.
389
-                        if ($name === 'main' && $main_field === $field_label) {
390
-                            $field_label = $values['label'];
391
-                        }
392
-                    }
393
-                }
394
-            }
395
-
396
-            // field is present. Let's validate shortcodes first (but only if shortcodes present).
397
-            if (
398
-                isset($this->_validators[ $field ]['shortcodes'])
399
-                && ! empty($this->_validators[ $field ]['shortcodes'])
400
-            ) {
401
-                $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']);
402
-                // if true then that means there is a returned error message
403
-                // that we'll need to add to the _errors array for this field.
404
-                if ($invalid_shortcodes) {
405
-                    $v_s     = array_keys($this->_validators[ $field ]['shortcodes']);
406
-                    $err_msg = sprintf(
407
-                        esc_html__(
408
-                            '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s',
409
-                            'event_espresso'
410
-                        ),
411
-                        '<strong>' . $field_label . '</strong>',
412
-                        $invalid_shortcodes,
413
-                        '<p>',
414
-                        '</p >'
415
-                    );
416
-                    $err_msg .= sprintf(
417
-                        esc_html__('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'),
418
-                        implode(', ', $v_s),
419
-                        '<strong>',
420
-                        '</strong>'
421
-                    );
422
-                }
423
-            }
424
-
425
-            // if there's a "type" to be validated then let's do that too.
426
-            if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) {
427
-                switch ($this->_validators[ $field ]['type']) {
428
-                    case 'number':
429
-                        if (! is_numeric($value)) {
430
-                            $err_msg .= sprintf(
431
-                                esc_html__(
432
-                                    '%3$sThe %1$s field is supposed to be a number. The value given (%2$s)  is not.  Please double-check and make sure the field contains a number%4$s',
433
-                                    'event_espresso'
434
-                                ),
435
-                                $field_label,
436
-                                $value,
437
-                                '<p>',
438
-                                '</p >'
439
-                            );
440
-                        }
441
-                        break;
442
-                    case 'email':
443
-                        $valid_email = $this->_validate_email($value);
444
-                        if (! $valid_email) {
445
-                            $err_msg .= htmlentities(
446
-                                sprintf(
447
-                                    esc_html__(
448
-                                        'The %1$s field has at least one string that is not a valid email address record.  Valid emails are in the format: "Name <[email protected]>" or "[email protected]" and multiple emails can be separated by a comma.',
449
-                                        'event_espresso'
450
-                                    ),
451
-                                    $field_label
452
-                                )
453
-                            );
454
-                        }
455
-                        break;
456
-                    default:
457
-                        break;
458
-                }
459
-            }
460
-
461
-            // if $err_msg isn't empty let's setup the _errors array for this field.
462
-            if (! empty($err_msg)) {
463
-                $this->_errors[ $field ]['msg'] = $err_msg;
464
-            } else {
465
-                unset($this->_errors[ $field ]);
466
-            }
467
-        }
468
-
469
-        // if we have ANY errors, then we want to make sure we return the values
470
-        // for ALL the fields so the user doesn't have to retype them all.
471
-        if (! empty($this->_errors)) {
472
-            foreach ($this->_fields as $field => $value) {
473
-                $this->_errors[ $field ]['value'] = stripslashes($value);
474
-            }
475
-        }
476
-
477
-        // return any errors or just TRUE if everything validates
478
-        return empty($this->_errors) ? true : $this->_errors;
479
-    }
480
-
481
-
482
-    /**
483
-     * Reassembles and returns an array of valid shortcodes
484
-     * given the array of groups and array of shortcodes indexed by group.
485
-     *
486
-     * @param  array $groups          array of shortcode groups that we want shortcodes for
487
-     * @param  array $codes_from_objs All the codes available.
488
-     * @return array                   an array of actual shortcodes (that will be used for validation).
489
-     */
490
-    private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs)
491
-    {
492
-        $shortcodes = array();
493
-        foreach ($groups as $group) {
494
-            $shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]);
495
-        }
496
-        return $shortcodes;
497
-    }
498
-
499
-
500
-    /**
501
-     * Validates a string against a list of accepted shortcodes
502
-     * This function takes in an array of shortcodes
503
-     * and makes sure that the given string ONLY contains shortcodes in that array.
504
-     *
505
-     * @param  string $value            string to evaluate
506
-     * @param  array  $valid_shortcodes array of shortcodes that are acceptable.
507
-     * @return mixed (bool|string)  return either a list of invalid shortcodes OR false if the shortcodes validate.
508
-     */
509
-    protected function _invalid_shortcodes($value, $valid_shortcodes)
510
-    {
511
-        // first we need to go through the string and get the shortcodes in the string
512
-        preg_match_all('/(\[.+?\])/', $value, $matches);
513
-        $incoming_shortcodes = (array) $matches[0];
514
-
515
-        // get a diff of the shortcodes in the string vs the valid shortcodes
516
-        $diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes));
517
-
518
-        // we need to account for custom codes so let's loop through the diff and remove any of those type of codes
519
-        foreach ($diff as $ind => $code) {
520
-            if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) {
521
-                // strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] )
522
-                $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code);
523
-                // does this exist in the $valid_shortcodes?  If so then unset.
524
-                if (isset($valid_shortcodes[ $dynamic_sc ])) {
525
-                    unset($diff[ $ind ]);
526
-                }
527
-            }
528
-        }
529
-
530
-        if (empty($diff)) {
531
-            return false;
532
-        } //there is no diff, we have no invalid shortcodes, so return
533
-
534
-        // made it here? then let's assemble the error message
535
-        $invalid_shortcodes = implode('</strong>,<strong>', $diff);
536
-        $invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>';
537
-        return $invalid_shortcodes;
538
-    }
539
-
540
-
541
-    /**
542
-     * Validates an incoming string and makes sure we have valid emails in the string.
543
-     *
544
-     * @param  string $value incoming value to validate
545
-     * @return bool        true if the string validates, false if it doesn't
546
-     */
547
-    protected function _validate_email($value)
548
-    {
549
-        $validate = true;
550
-        $or_val   = $value;
551
-
552
-        // empty strings will validate because this is how a message template
553
-        // for a particular context can be "turned off" (if there is no email then no message)
554
-        if (empty($value)) {
555
-            return $validate;
556
-        }
557
-
558
-        // first determine if there ARE any shortcodes.
559
-        // If there are shortcodes and then later we find that there were no other valid emails
560
-        // but the field isn't empty...
561
-        // that means we've got extra commas that were left after stripping out shortcodes so probably still valid.
562
-        $has_shortcodes = preg_match('/(\[.+?\])/', $value);
563
-
564
-        // first we need to strip out all the shortcodes!
565
-        $value = preg_replace('/(\[.+?\])/', '', $value);
566
-
567
-        // if original value is not empty and new value is, then we've parsed out a shortcode
568
-        // and we now have an empty string which DOES validate.
569
-        // We also validate complete empty field for email because
570
-        // its possible that this message is being "turned off" for a particular context
571
-
572
-
573
-        if (! empty($or_val) && empty($value)) {
574
-            return $validate;
575
-        }
576
-
577
-        // trim any commas from beginning and end of string ( after whitespace trimmed );
578
-        $value = trim(trim($value), ',');
579
-
580
-
581
-        // next we need to split up the string if its comma delimited.
582
-        $emails = explode(',', $value);
583
-        $empty  = false; // used to indicate that there is an empty comma.
584
-        // now let's loop through the emails and do our checks
585
-        foreach ($emails as $email) {
586
-            if (empty($email)) {
587
-                $empty = true;
588
-                continue;
589
-            }
590
-
591
-            // trim whitespace
592
-            $email = trim($email);
593
-            // either its of type "[email protected]", or its of type "fname lname <[email protected]>"
594
-            if (is_email($email)) {
595
-                continue;
596
-            }
597
-            $matches  = array();
598
-            $validate = preg_match('/(.*)<(.+)>/', $email, $matches) ? true : false;
599
-            if ($validate && is_email($matches[2])) {
600
-                continue;
601
-            }
602
-            return false;
603
-        }
604
-
605
-        $validate = $empty && ! $has_shortcodes ? false : $validate;
606
-
607
-        return $validate;
608
-    }
609
-
610
-
611
-    /**
612
-     * Magic getter
613
-     * Using this to provide back compat with add-ons referencing deprecated properties.
614
-     *
615
-     * @param string $property Property being requested
616
-     * @throws Exception
617
-     * @return mixed
618
-     */
619
-    public function __get($property)
620
-    {
621
-        $expected_properties_map = array(
622
-            /**
623
-             * @deprecated 4.9.0
624
-             */
625
-            '_MSGR'   => '_messenger',
626
-            /**
627
-             * @deprecated 4.9.0
628
-             */
629
-            '_MSGTYP' => '_message_type',
630
-        );
631
-
632
-        if (isset($expected_properties_map[ $property ])) {
633
-            return $this->{$expected_properties_map[ $property ]};
634
-        }
635
-
636
-        throw new Exception(
637
-            sprintf(
638
-                esc_html__('The property %1$s being requested on %2$s does not exist', 'event_espresso'),
639
-                $property,
640
-                get_class($this)
641
-            )
642
-        );
643
-    }
20
+	/**
21
+	 * These properties just hold the name for the Messenger and Message Type (defined by child classes).
22
+	 * These are used for retrieving objects etc.
23
+	 *
24
+	 * @var string
25
+	 */
26
+	protected $_m_name;
27
+	protected $_mt_name;
28
+
29
+
30
+	/**
31
+	 * This will hold any error messages from the validation process.
32
+	 * The _errors property holds an associative array of error messages
33
+	 * listing the field as the key and the message as the value.
34
+	 *
35
+	 * @var array()
36
+	 */
37
+	private $_errors = array();
38
+
39
+
40
+	/**
41
+	 * holds an array of fields being validated
42
+	 *
43
+	 * @var array
44
+	 */
45
+	protected $_fields;
46
+
47
+
48
+	/**
49
+	 * this will hold the incoming context
50
+	 *
51
+	 * @var string
52
+	 */
53
+	protected $_context;
54
+
55
+
56
+	/**
57
+	 * this holds an array of fields and the relevant validation information
58
+	 * that the incoming fields data get validated against.
59
+	 * This gets setup in the _set_props() method.
60
+	 *
61
+	 * @var array
62
+	 */
63
+	protected $_validators;
64
+
65
+
66
+	/**
67
+	 * holds the messenger object
68
+	 *
69
+	 * @var object
70
+	 */
71
+	protected $_messenger;
72
+
73
+
74
+	/**
75
+	 * holds the message type object
76
+	 *
77
+	 * @var object
78
+	 */
79
+	protected $_message_type;
80
+
81
+
82
+	/**
83
+	 * will hold any valid_shortcode modifications made by the _modify_validator() method.
84
+	 *
85
+	 * @var array
86
+	 */
87
+	protected $_valid_shortcodes_modifier;
88
+
89
+
90
+	/**
91
+	 * There may be times where a message type wants to include a shortcode group but exclude specific
92
+	 * shortcodes.  If that's the case then it can set this property as an array of shortcodes to exclude and
93
+	 * they will not be allowed.
94
+	 * Array should be indexed by field and values are an array of specific shortcodes to exclude.
95
+	 *
96
+	 * @var array
97
+	 */
98
+	protected $_specific_shortcode_excludes = array();
99
+
100
+
101
+	/**
102
+	 * Runs the validator using the incoming fields array as the fields/values to check.
103
+	 *
104
+	 * @param array $fields The fields sent by the EEM object.
105
+	 * @param       $context
106
+	 * @throws EE_Error
107
+	 * @throws ReflectionException
108
+	 */
109
+	public function __construct($fields, $context)
110
+	{
111
+		// check that _m_name and _mt_name have been set by child class otherwise we get out.
112
+		if (empty($this->_m_name) || empty($this->_mt_name)) {
113
+			throw new EE_Error(
114
+				esc_html__(
115
+					'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property.  Check that the child class is doing this',
116
+					'event_espresso'
117
+				)
118
+			);
119
+		}
120
+		$this->_fields  = $fields;
121
+		$this->_context = $context;
122
+
123
+		// load messenger and message_type objects and the related shortcode objects.
124
+		$this->_load_objects();
125
+
126
+
127
+		// modify any messenger/message_type specific validation instructions.  This is what child classes define.
128
+		$this->_modify_validator();
129
+
130
+
131
+		// let's set validators property
132
+		$this->_set_validators();
133
+	}
134
+
135
+
136
+	/**
137
+	 * Child classes instantiate this and use it to modify the _validator_config array property
138
+	 * for the messenger using messengers set_validate_config() method.
139
+	 * This is so we can specify specific validation instructions for a messenger/message_type combo
140
+	 * that aren't handled by the defaults setup in the messenger.
141
+	 *
142
+	 * @abstract
143
+	 * @access protected
144
+	 * @return void
145
+	 */
146
+	abstract protected function _modify_validator();
147
+
148
+
149
+	/**
150
+	 * loads all objects used by validator
151
+	 *
152
+	 * @access private
153
+	 * @throws \EE_Error
154
+	 */
155
+	private function _load_objects()
156
+	{
157
+		// load messenger
158
+		$messenger = ucwords(str_replace('_', ' ', $this->_m_name));
159
+		$messenger = str_replace(' ', '_', $messenger);
160
+		$messenger = 'EE_' . $messenger . '_messenger';
161
+
162
+		if (! class_exists($messenger)) {
163
+			throw new EE_Error(
164
+				sprintf(
165
+					esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'),
166
+					$this->_m_name
167
+				)
168
+			);
169
+		}
170
+
171
+		$this->_messenger = new $messenger();
172
+
173
+		// load message type
174
+		$message_type = ucwords(str_replace('_', ' ', $this->_mt_name));
175
+		$message_type = str_replace(' ', '_', $message_type);
176
+		$message_type = 'EE_' . $message_type . '_message_type';
177
+
178
+		if (! class_exists($message_type)) {
179
+			throw new EE_Error(
180
+				sprintf(
181
+					esc_html__('There is no message type class for the given string (%s)', 'event_espresso'),
182
+					$this->_mt_name
183
+				)
184
+			);
185
+		}
186
+
187
+		$this->_message_type = new $message_type();
188
+	}
189
+
190
+
191
+	/**
192
+	 * used to set the $_validators property
193
+	 *
194
+	 * @access private
195
+	 * @return void
196
+	 * @throws ReflectionException
197
+	 */
198
+	private function _set_validators()
199
+	{
200
+		// let's get all valid shortcodes from mt and message type
201
+		// (messenger will have its set in the _validator_config property for the messenger)
202
+		$mt_codes = $this->_message_type->get_valid_shortcodes();
203
+
204
+
205
+		// get messenger validator_config
206
+		$msgr_validator = $this->_messenger->get_validator_config();
207
+
208
+
209
+		// we only want the valid shortcodes for the given context!
210
+		$context  = $this->_context;
211
+		$mt_codes = $mt_codes[ $context ];
212
+
213
+		// in this first loop we're just getting all shortcode group indexes from the msgr_validator
214
+		// into a single array (so we can get the appropriate shortcode objects for the groups)
215
+		$shortcode_groups = $mt_codes;
216
+		$groups_per_field = array();
217
+
218
+		foreach ($msgr_validator as $field => $config) {
219
+			if (empty($config) || ! isset($config['shortcodes'])) {
220
+				continue;
221
+			}  //Nothing to see here.
222
+			$groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes);
223
+			$shortcode_groups         = array_merge($config['shortcodes'], $shortcode_groups);
224
+		}
225
+
226
+		$shortcode_groups = array_unique($shortcode_groups);
227
+
228
+		// okay now we've got our groups.
229
+		// Let's get the codes from the objects into an array indexed by group for easy retrieval later.
230
+		$codes_from_objs = array();
231
+
232
+		foreach ($shortcode_groups as $group) {
233
+			$ref       = ucwords(str_replace('_', ' ', $group));
234
+			$ref       = str_replace(' ', '_', $ref);
235
+			$classname = 'EE_' . $ref . '_Shortcodes';
236
+			if (class_exists($classname)) {
237
+				$a                       = new ReflectionClass($classname);
238
+				$obj                     = $a->newInstance();
239
+				$codes_from_objs[ $group ] = $obj->get_shortcodes();
240
+			}
241
+		}
242
+
243
+
244
+		// let's just replace the $mt shortcode group indexes with the actual shortcodes (unique)
245
+		$final_mt_codes = array();
246
+		foreach ($mt_codes as $group) {
247
+			$final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]);
248
+		}
249
+
250
+		$mt_codes = $final_mt_codes;
251
+
252
+
253
+		// k now in this next loop we're going to loop through $msgr_validator again
254
+		// and setup the _validators property from the data we've setup so far.
255
+		foreach ($msgr_validator as $field => $config) {
256
+			// if required shortcode is not in our list of codes for the given field, then we skip this field.
257
+			$required = isset($config['required'])
258
+				? array_intersect($config['required'], array_keys($mt_codes))
259
+				: true;
260
+			if (empty($required)) {
261
+				continue;
262
+			}
263
+
264
+			if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) {
265
+				// If we have an override then we use it to indicate the codes we want.
266
+				$this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
267
+					$this->_valid_shortcodes_modifier[ $context ][ $field ],
268
+					$codes_from_objs
269
+				);
270
+			} elseif (isset($groups_per_field[ $field ])) {
271
+				// if we have specific shortcodes for a field then we need to use them
272
+				$this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
273
+					$groups_per_field[ $field ],
274
+					$codes_from_objs
275
+				);
276
+			} elseif (empty($config)) {
277
+				// if empty config then we're assuming we're just going to use the shortcodes from the message type
278
+				// context
279
+				$this->_validators[ $field ]['shortcodes'] = $mt_codes;
280
+			} elseif (isset($config['specific_shortcodes'])) {
281
+				// if we have specific shortcodes then we need to use them
282
+				$this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes'];
283
+			} else {
284
+				// otherwise the shortcodes are what is set by the messenger for that field
285
+				foreach ($config['shortcodes'] as $group) {
286
+					$this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes'])
287
+						? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ])
288
+						: $codes_from_objs[ $group ];
289
+				}
290
+			}
291
+
292
+			// now let's just make sure that any excluded specific shortcodes are removed.
293
+			$specific_excludes = $this->get_specific_shortcode_excludes();
294
+			if (isset($specific_excludes[ $field ])) {
295
+				foreach ($specific_excludes[ $field ] as $sex) {
296
+					if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) {
297
+						unset($this->_validators[ $field ]['shortcodes'][ $sex ]);
298
+					}
299
+				}
300
+			}
301
+
302
+			// hey! don't forget to include the type if present!
303
+			$this->_validators[ $field ]['type'] = isset($config['type']) ? $config['type'] : null;
304
+		}
305
+	}
306
+
307
+
308
+	/**
309
+	 * This just returns the validators property that contains information
310
+	 * about the various shortcodes and their availability with each field
311
+	 *
312
+	 * @return array
313
+	 */
314
+	public function get_validators()
315
+	{
316
+		return $this->_validators;
317
+	}
318
+
319
+
320
+	/**
321
+	 * This simply returns the specific shortcode_excludes property that is set.
322
+	 *
323
+	 * @since 4.5.0
324
+	 * @return array
325
+	 */
326
+	public function get_specific_shortcode_excludes()
327
+	{
328
+		// specific validator filter
329
+		$shortcode_excludes = apply_filters(
330
+			'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;',
331
+			$this->_specific_shortcode_excludes,
332
+			$this->_context
333
+		);
334
+		// global filter
335
+		return apply_filters(
336
+			'FHEE__EE_Messages_Validator__get_specific_shortcode_excludes',
337
+			$shortcode_excludes,
338
+			$this->_context,
339
+			$this
340
+		);
341
+	}
342
+
343
+
344
+	/**
345
+	 * This is the main method that handles validation
346
+	 * What it does is loop through the _fields (the ones that get validated)
347
+	 * and checks them against the shortcodes array for the field and the 'type' indicated by the
348
+	 *
349
+	 * @access public
350
+	 * @return mixed (bool|array)  if errors present we return the array otherwise true
351
+	 */
352
+	public function validate()
353
+	{
354
+		// some defaults
355
+		$template_fields = $this->_messenger->get_template_fields();
356
+		// loop through the fields and check!
357
+		foreach ($this->_fields as $field => $value) {
358
+			$this->_errors[ $field ] = array();
359
+			$err_msg               = '';
360
+			$field_label           = '';
361
+			// if field is not present in the _validators array then we continue
362
+			if (! isset($this->_validators[ $field ])) {
363
+				unset($this->_errors[ $field ]);
364
+				continue;
365
+			}
366
+
367
+			// get the translated field label!
368
+			// first check if it's in the main fields list
369
+			if (isset($template_fields[ $field ])) {
370
+				if (empty($template_fields[ $field ])) {
371
+					$field_label = $field;
372
+				} else {
373
+					// most likely the field is found in the 'extra' array.
374
+					$field_label = $template_fields[ $field ]['label'];
375
+				}
376
+			}
377
+
378
+			// if field label is empty OR is equal to the current field
379
+			// then we need to loop through the 'extra' fields in the template_fields config (if present)
380
+			if (isset($template_fields['extra']) && (empty($field_label) || $field_label === $field)) {
381
+				foreach ($template_fields['extra'] as $main_field => $secondary_field) {
382
+					foreach ($secondary_field as $name => $values) {
383
+						if ($name === $field) {
384
+							$field_label = $values['label'];
385
+						}
386
+
387
+						// if we've got a 'main' secondary field, let's see if that matches what field we're on
388
+						// which means it contains the label for this field.
389
+						if ($name === 'main' && $main_field === $field_label) {
390
+							$field_label = $values['label'];
391
+						}
392
+					}
393
+				}
394
+			}
395
+
396
+			// field is present. Let's validate shortcodes first (but only if shortcodes present).
397
+			if (
398
+				isset($this->_validators[ $field ]['shortcodes'])
399
+				&& ! empty($this->_validators[ $field ]['shortcodes'])
400
+			) {
401
+				$invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']);
402
+				// if true then that means there is a returned error message
403
+				// that we'll need to add to the _errors array for this field.
404
+				if ($invalid_shortcodes) {
405
+					$v_s     = array_keys($this->_validators[ $field ]['shortcodes']);
406
+					$err_msg = sprintf(
407
+						esc_html__(
408
+							'%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s',
409
+							'event_espresso'
410
+						),
411
+						'<strong>' . $field_label . '</strong>',
412
+						$invalid_shortcodes,
413
+						'<p>',
414
+						'</p >'
415
+					);
416
+					$err_msg .= sprintf(
417
+						esc_html__('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'),
418
+						implode(', ', $v_s),
419
+						'<strong>',
420
+						'</strong>'
421
+					);
422
+				}
423
+			}
424
+
425
+			// if there's a "type" to be validated then let's do that too.
426
+			if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) {
427
+				switch ($this->_validators[ $field ]['type']) {
428
+					case 'number':
429
+						if (! is_numeric($value)) {
430
+							$err_msg .= sprintf(
431
+								esc_html__(
432
+									'%3$sThe %1$s field is supposed to be a number. The value given (%2$s)  is not.  Please double-check and make sure the field contains a number%4$s',
433
+									'event_espresso'
434
+								),
435
+								$field_label,
436
+								$value,
437
+								'<p>',
438
+								'</p >'
439
+							);
440
+						}
441
+						break;
442
+					case 'email':
443
+						$valid_email = $this->_validate_email($value);
444
+						if (! $valid_email) {
445
+							$err_msg .= htmlentities(
446
+								sprintf(
447
+									esc_html__(
448
+										'The %1$s field has at least one string that is not a valid email address record.  Valid emails are in the format: "Name <[email protected]>" or "[email protected]" and multiple emails can be separated by a comma.',
449
+										'event_espresso'
450
+									),
451
+									$field_label
452
+								)
453
+							);
454
+						}
455
+						break;
456
+					default:
457
+						break;
458
+				}
459
+			}
460
+
461
+			// if $err_msg isn't empty let's setup the _errors array for this field.
462
+			if (! empty($err_msg)) {
463
+				$this->_errors[ $field ]['msg'] = $err_msg;
464
+			} else {
465
+				unset($this->_errors[ $field ]);
466
+			}
467
+		}
468
+
469
+		// if we have ANY errors, then we want to make sure we return the values
470
+		// for ALL the fields so the user doesn't have to retype them all.
471
+		if (! empty($this->_errors)) {
472
+			foreach ($this->_fields as $field => $value) {
473
+				$this->_errors[ $field ]['value'] = stripslashes($value);
474
+			}
475
+		}
476
+
477
+		// return any errors or just TRUE if everything validates
478
+		return empty($this->_errors) ? true : $this->_errors;
479
+	}
480
+
481
+
482
+	/**
483
+	 * Reassembles and returns an array of valid shortcodes
484
+	 * given the array of groups and array of shortcodes indexed by group.
485
+	 *
486
+	 * @param  array $groups          array of shortcode groups that we want shortcodes for
487
+	 * @param  array $codes_from_objs All the codes available.
488
+	 * @return array                   an array of actual shortcodes (that will be used for validation).
489
+	 */
490
+	private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs)
491
+	{
492
+		$shortcodes = array();
493
+		foreach ($groups as $group) {
494
+			$shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]);
495
+		}
496
+		return $shortcodes;
497
+	}
498
+
499
+
500
+	/**
501
+	 * Validates a string against a list of accepted shortcodes
502
+	 * This function takes in an array of shortcodes
503
+	 * and makes sure that the given string ONLY contains shortcodes in that array.
504
+	 *
505
+	 * @param  string $value            string to evaluate
506
+	 * @param  array  $valid_shortcodes array of shortcodes that are acceptable.
507
+	 * @return mixed (bool|string)  return either a list of invalid shortcodes OR false if the shortcodes validate.
508
+	 */
509
+	protected function _invalid_shortcodes($value, $valid_shortcodes)
510
+	{
511
+		// first we need to go through the string and get the shortcodes in the string
512
+		preg_match_all('/(\[.+?\])/', $value, $matches);
513
+		$incoming_shortcodes = (array) $matches[0];
514
+
515
+		// get a diff of the shortcodes in the string vs the valid shortcodes
516
+		$diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes));
517
+
518
+		// we need to account for custom codes so let's loop through the diff and remove any of those type of codes
519
+		foreach ($diff as $ind => $code) {
520
+			if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) {
521
+				// strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] )
522
+				$dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code);
523
+				// does this exist in the $valid_shortcodes?  If so then unset.
524
+				if (isset($valid_shortcodes[ $dynamic_sc ])) {
525
+					unset($diff[ $ind ]);
526
+				}
527
+			}
528
+		}
529
+
530
+		if (empty($diff)) {
531
+			return false;
532
+		} //there is no diff, we have no invalid shortcodes, so return
533
+
534
+		// made it here? then let's assemble the error message
535
+		$invalid_shortcodes = implode('</strong>,<strong>', $diff);
536
+		$invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>';
537
+		return $invalid_shortcodes;
538
+	}
539
+
540
+
541
+	/**
542
+	 * Validates an incoming string and makes sure we have valid emails in the string.
543
+	 *
544
+	 * @param  string $value incoming value to validate
545
+	 * @return bool        true if the string validates, false if it doesn't
546
+	 */
547
+	protected function _validate_email($value)
548
+	{
549
+		$validate = true;
550
+		$or_val   = $value;
551
+
552
+		// empty strings will validate because this is how a message template
553
+		// for a particular context can be "turned off" (if there is no email then no message)
554
+		if (empty($value)) {
555
+			return $validate;
556
+		}
557
+
558
+		// first determine if there ARE any shortcodes.
559
+		// If there are shortcodes and then later we find that there were no other valid emails
560
+		// but the field isn't empty...
561
+		// that means we've got extra commas that were left after stripping out shortcodes so probably still valid.
562
+		$has_shortcodes = preg_match('/(\[.+?\])/', $value);
563
+
564
+		// first we need to strip out all the shortcodes!
565
+		$value = preg_replace('/(\[.+?\])/', '', $value);
566
+
567
+		// if original value is not empty and new value is, then we've parsed out a shortcode
568
+		// and we now have an empty string which DOES validate.
569
+		// We also validate complete empty field for email because
570
+		// its possible that this message is being "turned off" for a particular context
571
+
572
+
573
+		if (! empty($or_val) && empty($value)) {
574
+			return $validate;
575
+		}
576
+
577
+		// trim any commas from beginning and end of string ( after whitespace trimmed );
578
+		$value = trim(trim($value), ',');
579
+
580
+
581
+		// next we need to split up the string if its comma delimited.
582
+		$emails = explode(',', $value);
583
+		$empty  = false; // used to indicate that there is an empty comma.
584
+		// now let's loop through the emails and do our checks
585
+		foreach ($emails as $email) {
586
+			if (empty($email)) {
587
+				$empty = true;
588
+				continue;
589
+			}
590
+
591
+			// trim whitespace
592
+			$email = trim($email);
593
+			// either its of type "[email protected]", or its of type "fname lname <[email protected]>"
594
+			if (is_email($email)) {
595
+				continue;
596
+			}
597
+			$matches  = array();
598
+			$validate = preg_match('/(.*)<(.+)>/', $email, $matches) ? true : false;
599
+			if ($validate && is_email($matches[2])) {
600
+				continue;
601
+			}
602
+			return false;
603
+		}
604
+
605
+		$validate = $empty && ! $has_shortcodes ? false : $validate;
606
+
607
+		return $validate;
608
+	}
609
+
610
+
611
+	/**
612
+	 * Magic getter
613
+	 * Using this to provide back compat with add-ons referencing deprecated properties.
614
+	 *
615
+	 * @param string $property Property being requested
616
+	 * @throws Exception
617
+	 * @return mixed
618
+	 */
619
+	public function __get($property)
620
+	{
621
+		$expected_properties_map = array(
622
+			/**
623
+			 * @deprecated 4.9.0
624
+			 */
625
+			'_MSGR'   => '_messenger',
626
+			/**
627
+			 * @deprecated 4.9.0
628
+			 */
629
+			'_MSGTYP' => '_message_type',
630
+		);
631
+
632
+		if (isset($expected_properties_map[ $property ])) {
633
+			return $this->{$expected_properties_map[ $property ]};
634
+		}
635
+
636
+		throw new Exception(
637
+			sprintf(
638
+				esc_html__('The property %1$s being requested on %2$s does not exist', 'event_espresso'),
639
+				$property,
640
+				get_class($this)
641
+			)
642
+		);
643
+	}
644 644
 }
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
         // load messenger
158 158
         $messenger = ucwords(str_replace('_', ' ', $this->_m_name));
159 159
         $messenger = str_replace(' ', '_', $messenger);
160
-        $messenger = 'EE_' . $messenger . '_messenger';
160
+        $messenger = 'EE_'.$messenger.'_messenger';
161 161
 
162
-        if (! class_exists($messenger)) {
162
+        if ( ! class_exists($messenger)) {
163 163
             throw new EE_Error(
164 164
                 sprintf(
165 165
                     esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'),
@@ -173,9 +173,9 @@  discard block
 block discarded – undo
173 173
         // load message type
174 174
         $message_type = ucwords(str_replace('_', ' ', $this->_mt_name));
175 175
         $message_type = str_replace(' ', '_', $message_type);
176
-        $message_type = 'EE_' . $message_type . '_message_type';
176
+        $message_type = 'EE_'.$message_type.'_message_type';
177 177
 
178
-        if (! class_exists($message_type)) {
178
+        if ( ! class_exists($message_type)) {
179 179
             throw new EE_Error(
180 180
                 sprintf(
181 181
                     esc_html__('There is no message type class for the given string (%s)', 'event_espresso'),
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 
209 209
         // we only want the valid shortcodes for the given context!
210 210
         $context  = $this->_context;
211
-        $mt_codes = $mt_codes[ $context ];
211
+        $mt_codes = $mt_codes[$context];
212 212
 
213 213
         // in this first loop we're just getting all shortcode group indexes from the msgr_validator
214 214
         // into a single array (so we can get the appropriate shortcode objects for the groups)
@@ -219,8 +219,8 @@  discard block
 block discarded – undo
219 219
             if (empty($config) || ! isset($config['shortcodes'])) {
220 220
                 continue;
221 221
             }  //Nothing to see here.
222
-            $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes);
223
-            $shortcode_groups         = array_merge($config['shortcodes'], $shortcode_groups);
222
+            $groups_per_field[$field] = array_intersect($config['shortcodes'], $mt_codes);
223
+            $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups);
224 224
         }
225 225
 
226 226
         $shortcode_groups = array_unique($shortcode_groups);
@@ -232,11 +232,11 @@  discard block
 block discarded – undo
232 232
         foreach ($shortcode_groups as $group) {
233 233
             $ref       = ucwords(str_replace('_', ' ', $group));
234 234
             $ref       = str_replace(' ', '_', $ref);
235
-            $classname = 'EE_' . $ref . '_Shortcodes';
235
+            $classname = 'EE_'.$ref.'_Shortcodes';
236 236
             if (class_exists($classname)) {
237 237
                 $a                       = new ReflectionClass($classname);
238 238
                 $obj                     = $a->newInstance();
239
-                $codes_from_objs[ $group ] = $obj->get_shortcodes();
239
+                $codes_from_objs[$group] = $obj->get_shortcodes();
240 240
             }
241 241
         }
242 242
 
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
         // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique)
245 245
         $final_mt_codes = array();
246 246
         foreach ($mt_codes as $group) {
247
-            $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]);
247
+            $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[$group]);
248 248
         }
249 249
 
250 250
         $mt_codes = $final_mt_codes;
@@ -261,46 +261,46 @@  discard block
 block discarded – undo
261 261
                 continue;
262 262
             }
263 263
 
264
-            if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) {
264
+            if (isset($this->_valid_shortcodes_modifier[$context][$field])) {
265 265
                 // If we have an override then we use it to indicate the codes we want.
266
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
267
-                    $this->_valid_shortcodes_modifier[ $context ][ $field ],
266
+                $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
267
+                    $this->_valid_shortcodes_modifier[$context][$field],
268 268
                     $codes_from_objs
269 269
                 );
270
-            } elseif (isset($groups_per_field[ $field ])) {
270
+            } elseif (isset($groups_per_field[$field])) {
271 271
                 // if we have specific shortcodes for a field then we need to use them
272
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
273
-                    $groups_per_field[ $field ],
272
+                $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
273
+                    $groups_per_field[$field],
274 274
                     $codes_from_objs
275 275
                 );
276 276
             } elseif (empty($config)) {
277 277
                 // if empty config then we're assuming we're just going to use the shortcodes from the message type
278 278
                 // context
279
-                $this->_validators[ $field ]['shortcodes'] = $mt_codes;
279
+                $this->_validators[$field]['shortcodes'] = $mt_codes;
280 280
             } elseif (isset($config['specific_shortcodes'])) {
281 281
                 // if we have specific shortcodes then we need to use them
282
-                $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes'];
282
+                $this->_validators[$field]['shortcodes'] = $config['specific_shortcodes'];
283 283
             } else {
284 284
                 // otherwise the shortcodes are what is set by the messenger for that field
285 285
                 foreach ($config['shortcodes'] as $group) {
286
-                    $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes'])
287
-                        ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ])
288
-                        : $codes_from_objs[ $group ];
286
+                    $this->_validators[$field]['shortcodes'] = isset($this->_validators[$field]['shortcodes'])
287
+                        ? array_merge($this->_validators[$field]['shortcodes'], $codes_from_objs[$group])
288
+                        : $codes_from_objs[$group];
289 289
                 }
290 290
             }
291 291
 
292 292
             // now let's just make sure that any excluded specific shortcodes are removed.
293 293
             $specific_excludes = $this->get_specific_shortcode_excludes();
294
-            if (isset($specific_excludes[ $field ])) {
295
-                foreach ($specific_excludes[ $field ] as $sex) {
296
-                    if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) {
297
-                        unset($this->_validators[ $field ]['shortcodes'][ $sex ]);
294
+            if (isset($specific_excludes[$field])) {
295
+                foreach ($specific_excludes[$field] as $sex) {
296
+                    if (isset($this->_validators[$field]['shortcodes'][$sex])) {
297
+                        unset($this->_validators[$field]['shortcodes'][$sex]);
298 298
                     }
299 299
                 }
300 300
             }
301 301
 
302 302
             // hey! don't forget to include the type if present!
303
-            $this->_validators[ $field ]['type'] = isset($config['type']) ? $config['type'] : null;
303
+            $this->_validators[$field]['type'] = isset($config['type']) ? $config['type'] : null;
304 304
         }
305 305
     }
306 306
 
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
     {
328 328
         // specific validator filter
329 329
         $shortcode_excludes = apply_filters(
330
-            'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;',
330
+            'FHEE__'.get_class($this).'__get_specific_shortcode_excludes;',
331 331
             $this->_specific_shortcode_excludes,
332 332
             $this->_context
333 333
         );
@@ -355,23 +355,23 @@  discard block
 block discarded – undo
355 355
         $template_fields = $this->_messenger->get_template_fields();
356 356
         // loop through the fields and check!
357 357
         foreach ($this->_fields as $field => $value) {
358
-            $this->_errors[ $field ] = array();
358
+            $this->_errors[$field] = array();
359 359
             $err_msg               = '';
360 360
             $field_label           = '';
361 361
             // if field is not present in the _validators array then we continue
362
-            if (! isset($this->_validators[ $field ])) {
363
-                unset($this->_errors[ $field ]);
362
+            if ( ! isset($this->_validators[$field])) {
363
+                unset($this->_errors[$field]);
364 364
                 continue;
365 365
             }
366 366
 
367 367
             // get the translated field label!
368 368
             // first check if it's in the main fields list
369
-            if (isset($template_fields[ $field ])) {
370
-                if (empty($template_fields[ $field ])) {
369
+            if (isset($template_fields[$field])) {
370
+                if (empty($template_fields[$field])) {
371 371
                     $field_label = $field;
372 372
                 } else {
373 373
                     // most likely the field is found in the 'extra' array.
374
-                    $field_label = $template_fields[ $field ]['label'];
374
+                    $field_label = $template_fields[$field]['label'];
375 375
                 }
376 376
             }
377 377
 
@@ -395,20 +395,20 @@  discard block
 block discarded – undo
395 395
 
396 396
             // field is present. Let's validate shortcodes first (but only if shortcodes present).
397 397
             if (
398
-                isset($this->_validators[ $field ]['shortcodes'])
399
-                && ! empty($this->_validators[ $field ]['shortcodes'])
398
+                isset($this->_validators[$field]['shortcodes'])
399
+                && ! empty($this->_validators[$field]['shortcodes'])
400 400
             ) {
401
-                $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']);
401
+                $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[$field]['shortcodes']);
402 402
                 // if true then that means there is a returned error message
403 403
                 // that we'll need to add to the _errors array for this field.
404 404
                 if ($invalid_shortcodes) {
405
-                    $v_s     = array_keys($this->_validators[ $field ]['shortcodes']);
405
+                    $v_s     = array_keys($this->_validators[$field]['shortcodes']);
406 406
                     $err_msg = sprintf(
407 407
                         esc_html__(
408 408
                             '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s',
409 409
                             'event_espresso'
410 410
                         ),
411
-                        '<strong>' . $field_label . '</strong>',
411
+                        '<strong>'.$field_label.'</strong>',
412 412
                         $invalid_shortcodes,
413 413
                         '<p>',
414 414
                         '</p >'
@@ -423,10 +423,10 @@  discard block
 block discarded – undo
423 423
             }
424 424
 
425 425
             // if there's a "type" to be validated then let's do that too.
426
-            if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) {
427
-                switch ($this->_validators[ $field ]['type']) {
426
+            if (isset($this->_validators[$field]['type']) && ! empty($this->_validators[$field]['type'])) {
427
+                switch ($this->_validators[$field]['type']) {
428 428
                     case 'number':
429
-                        if (! is_numeric($value)) {
429
+                        if ( ! is_numeric($value)) {
430 430
                             $err_msg .= sprintf(
431 431
                                 esc_html__(
432 432
                                     '%3$sThe %1$s field is supposed to be a number. The value given (%2$s)  is not.  Please double-check and make sure the field contains a number%4$s',
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
                         break;
442 442
                     case 'email':
443 443
                         $valid_email = $this->_validate_email($value);
444
-                        if (! $valid_email) {
444
+                        if ( ! $valid_email) {
445 445
                             $err_msg .= htmlentities(
446 446
                                 sprintf(
447 447
                                     esc_html__(
@@ -459,18 +459,18 @@  discard block
 block discarded – undo
459 459
             }
460 460
 
461 461
             // if $err_msg isn't empty let's setup the _errors array for this field.
462
-            if (! empty($err_msg)) {
463
-                $this->_errors[ $field ]['msg'] = $err_msg;
462
+            if ( ! empty($err_msg)) {
463
+                $this->_errors[$field]['msg'] = $err_msg;
464 464
             } else {
465
-                unset($this->_errors[ $field ]);
465
+                unset($this->_errors[$field]);
466 466
             }
467 467
         }
468 468
 
469 469
         // if we have ANY errors, then we want to make sure we return the values
470 470
         // for ALL the fields so the user doesn't have to retype them all.
471
-        if (! empty($this->_errors)) {
471
+        if ( ! empty($this->_errors)) {
472 472
             foreach ($this->_fields as $field => $value) {
473
-                $this->_errors[ $field ]['value'] = stripslashes($value);
473
+                $this->_errors[$field]['value'] = stripslashes($value);
474 474
             }
475 475
         }
476 476
 
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
     {
492 492
         $shortcodes = array();
493 493
         foreach ($groups as $group) {
494
-            $shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]);
494
+            $shortcodes = array_merge($shortcodes, $codes_from_objs[$group]);
495 495
         }
496 496
         return $shortcodes;
497 497
     }
@@ -521,8 +521,8 @@  discard block
 block discarded – undo
521 521
                 // strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] )
522 522
                 $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code);
523 523
                 // does this exist in the $valid_shortcodes?  If so then unset.
524
-                if (isset($valid_shortcodes[ $dynamic_sc ])) {
525
-                    unset($diff[ $ind ]);
524
+                if (isset($valid_shortcodes[$dynamic_sc])) {
525
+                    unset($diff[$ind]);
526 526
                 }
527 527
             }
528 528
         }
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
 
534 534
         // made it here? then let's assemble the error message
535 535
         $invalid_shortcodes = implode('</strong>,<strong>', $diff);
536
-        $invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>';
536
+        $invalid_shortcodes = '<strong>'.$invalid_shortcodes.'</strong>';
537 537
         return $invalid_shortcodes;
538 538
     }
539 539
 
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
         // its possible that this message is being "turned off" for a particular context
571 571
 
572 572
 
573
-        if (! empty($or_val) && empty($value)) {
573
+        if ( ! empty($or_val) && empty($value)) {
574 574
             return $validate;
575 575
         }
576 576
 
@@ -629,8 +629,8 @@  discard block
 block discarded – undo
629 629
             '_MSGTYP' => '_message_type',
630 630
         );
631 631
 
632
-        if (isset($expected_properties_map[ $property ])) {
633
-            return $this->{$expected_properties_map[ $property ]};
632
+        if (isset($expected_properties_map[$property])) {
633
+            return $this->{$expected_properties_map[$property]};
634 634
         }
635 635
 
636 636
         throw new Exception(
Please login to merge, or discard this patch.
core/db_models/fields/EE_Simple_HTML_Field.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -11,14 +11,14 @@
 block discarded – undo
11 11
 
12 12
 
13 13
 
14
-    /**
15
-     * removes all tags which a WP Post wouldn't allow in its content normally
16
-     *
17
-     * @param string $value
18
-     * @return string
19
-     */
20
-    public function prepare_for_set($value)
21
-    {
22
-        return parent::prepare_for_set(wp_kses("$value", EEH_HTML::get_simple_tags()));
23
-    }
14
+	/**
15
+	 * removes all tags which a WP Post wouldn't allow in its content normally
16
+	 *
17
+	 * @param string $value
18
+	 * @return string
19
+	 */
20
+	public function prepare_for_set($value)
21
+	{
22
+		return parent::prepare_for_set(wp_kses("$value", EEH_HTML::get_simple_tags()));
23
+	}
24 24
 }
Please login to merge, or discard this patch.
core/db_classes/EE_WP_User.class.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
      */
52 52
     public function wp_user_obj()
53 53
     {
54
-        if (! $this->_wp_user_obj) {
54
+        if ( ! $this->_wp_user_obj) {
55 55
             $this->_wp_user_obj = get_user_by('ID', $this->ID());
56 56
         }
57 57
         return $this->_wp_user_obj;
Please login to merge, or discard this patch.
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -11,91 +11,91 @@
 block discarded – undo
11 11
 class EE_WP_User extends EE_Base_Class implements EEI_Admin_Links
12 12
 {
13 13
 
14
-    /**
15
-     * @var WP_User
16
-     */
17
-    protected $_wp_user_obj;
14
+	/**
15
+	 * @var WP_User
16
+	 */
17
+	protected $_wp_user_obj;
18 18
 
19
-    /**
20
-     * @param array $props_n_values
21
-     * @return EE_WP_User|mixed
22
-     */
23
-    public static function new_instance($props_n_values = array())
24
-    {
25
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
26
-        return $has_object ? $has_object : new self($props_n_values);
27
-    }
19
+	/**
20
+	 * @param array $props_n_values
21
+	 * @return EE_WP_User|mixed
22
+	 */
23
+	public static function new_instance($props_n_values = array())
24
+	{
25
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
26
+		return $has_object ? $has_object : new self($props_n_values);
27
+	}
28 28
 
29 29
 
30
-    /**
31
-     * @param array $props_n_values
32
-     * @return EE_WP_User
33
-     */
34
-    public static function new_instance_from_db($props_n_values = array())
35
-    {
36
-        return new self($props_n_values, true);
37
-    }
30
+	/**
31
+	 * @param array $props_n_values
32
+	 * @return EE_WP_User
33
+	 */
34
+	public static function new_instance_from_db($props_n_values = array())
35
+	{
36
+		return new self($props_n_values, true);
37
+	}
38 38
 
39
-    /**
40
-     * Return a normal WP_User object (caches the object for future calls)
41
-     *
42
-     * @return WP_User
43
-     */
44
-    public function wp_user_obj()
45
-    {
46
-        if (! $this->_wp_user_obj) {
47
-            $this->_wp_user_obj = get_user_by('ID', $this->ID());
48
-        }
49
-        return $this->_wp_user_obj;
50
-    }
39
+	/**
40
+	 * Return a normal WP_User object (caches the object for future calls)
41
+	 *
42
+	 * @return WP_User
43
+	 */
44
+	public function wp_user_obj()
45
+	{
46
+		if (! $this->_wp_user_obj) {
47
+			$this->_wp_user_obj = get_user_by('ID', $this->ID());
48
+		}
49
+		return $this->_wp_user_obj;
50
+	}
51 51
 
52
-    /**
53
-     * Return the link to the admin details for the object.
54
-     *
55
-     * @return string
56
-     */
57
-    public function get_admin_details_link()
58
-    {
59
-        return $this->get_admin_edit_link();
60
-    }
52
+	/**
53
+	 * Return the link to the admin details for the object.
54
+	 *
55
+	 * @return string
56
+	 */
57
+	public function get_admin_details_link()
58
+	{
59
+		return $this->get_admin_edit_link();
60
+	}
61 61
 
62
-    /**
63
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
64
-     *
65
-     * @return string
66
-     */
67
-    public function get_admin_edit_link()
68
-    {
69
-        return esc_url(
70
-            add_query_arg(
71
-                'wp_http_referer',
72
-                urlencode(
73
-                    wp_unslash(
74
-                        $_SERVER['REQUEST_URI']
75
-                    )
76
-                ),
77
-                get_edit_user_link($this->ID())
78
-            )
79
-        );
80
-    }
62
+	/**
63
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
64
+	 *
65
+	 * @return string
66
+	 */
67
+	public function get_admin_edit_link()
68
+	{
69
+		return esc_url(
70
+			add_query_arg(
71
+				'wp_http_referer',
72
+				urlencode(
73
+					wp_unslash(
74
+						$_SERVER['REQUEST_URI']
75
+					)
76
+				),
77
+				get_edit_user_link($this->ID())
78
+			)
79
+		);
80
+	}
81 81
 
82
-    /**
83
-     * Returns the link to a settings page for the object.
84
-     *
85
-     * @return string
86
-     */
87
-    public function get_admin_settings_link()
88
-    {
89
-        return $this->get_admin_edit_link();
90
-    }
82
+	/**
83
+	 * Returns the link to a settings page for the object.
84
+	 *
85
+	 * @return string
86
+	 */
87
+	public function get_admin_settings_link()
88
+	{
89
+		return $this->get_admin_edit_link();
90
+	}
91 91
 
92
-    /**
93
-     * Returns the link to the "overview" for the object (typically the "list table" view).
94
-     *
95
-     * @return string
96
-     */
97
-    public function get_admin_overview_link()
98
-    {
99
-        return admin_url('users.php');
100
-    }
92
+	/**
93
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
94
+	 *
95
+	 * @return string
96
+	 */
97
+	public function get_admin_overview_link()
98
+	{
99
+		return admin_url('users.php');
100
+	}
101 101
 }
Please login to merge, or discard this patch.
core/EE_Module_Request_Router.core.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      * this method instantiates modules and calls the method that was defined when the route was registered
183 183
      *
184 184
      * @param string $module_name
185
-     * @return EED_Module|object|null
185
+     * @return null|EED_Module
186 186
      * @throws ReflectionException
187 187
      */
188 188
     public static function module_factory($module_name)
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 
253 253
 
254 254
     /**
255
-     * @param $current_route
255
+     * @param string $current_route
256 256
      * @return string
257 257
      */
258 258
     public function get_view($current_route)
Please login to merge, or discard this patch.
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -15,255 +15,255 @@
 block discarded – undo
15 15
 final class EE_Module_Request_Router implements InterminableInterface
16 16
 {
17 17
 
18
-    /**
19
-     * @var EE_Request $request
20
-     */
21
-    private $request;
18
+	/**
19
+	 * @var EE_Request $request
20
+	 */
21
+	private $request;
22 22
 
23
-    /**
24
-     * @var array $_previous_routes
25
-     */
26
-    private static $_previous_routes = array();
23
+	/**
24
+	 * @var array $_previous_routes
25
+	 */
26
+	private static $_previous_routes = array();
27 27
 
28
-    /**
29
-     * @var WP_Query $WP_Query
30
-     */
31
-    public $WP_Query;
28
+	/**
29
+	 * @var WP_Query $WP_Query
30
+	 */
31
+	public $WP_Query;
32 32
 
33 33
 
34
-    /**
35
-     * EE_Module_Request_Router constructor.
36
-     *
37
-     * @param EE_Request $request
38
-     */
39
-    public function __construct(EE_Request $request)
40
-    {
41
-        $this->request = $request;
42
-    }
34
+	/**
35
+	 * EE_Module_Request_Router constructor.
36
+	 *
37
+	 * @param EE_Request $request
38
+	 */
39
+	public function __construct(EE_Request $request)
40
+	{
41
+		$this->request = $request;
42
+	}
43 43
 
44 44
 
45
-    /**
46
-     * on the first call  to this method, it checks the EE_Request_Handler for a "route"
47
-     * on subsequent calls to this method,
48
-     * instead of checking the EE_Request_Handler for a route, it checks the previous routes array,
49
-     * and checks if the last called route has any forwarding routes registered for it
50
-     *
51
-     * @param WP_Query $WP_Query
52
-     * @return NULL|string
53
-     * @throws EE_Error
54
-     * @throws ReflectionException
55
-     */
56
-    public function get_route(WP_Query $WP_Query)
57
-    {
58
-        $this->WP_Query = $WP_Query;
59
-        // assume this if first route being called
60
-        $previous_route = false;
61
-        // but is it really ???
62
-        if (! empty(self::$_previous_routes)) {
63
-            // get last run route
64
-            $previous_routes = array_values(self::$_previous_routes);
65
-            $previous_route = array_pop($previous_routes);
66
-        }
67
-        //  has another route already been run ?
68
-        if ($previous_route) {
69
-            // check if  forwarding has been set
70
-            $current_route = $this->get_forward($previous_route);
71
-            try {
72
-                // check for recursive forwarding
73
-                if (isset(self::$_previous_routes[ $current_route ])) {
74
-                    throw new EE_Error(
75
-                        sprintf(
76
-                            __(
77
-                                'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.',
78
-                                'event_espresso'
79
-                            ),
80
-                            $current_route
81
-                        )
82
-                    );
83
-                }
84
-            } catch (EE_Error $e) {
85
-                $e->get_error();
86
-                return null;
87
-            }
88
-        } else {
89
-            // first route called
90
-            $current_route = null;
91
-            // grab all routes
92
-            $routes = EE_Config::get_routes();
93
-            foreach ($routes as $key => $route) {
94
-                // first determine if route key uses w?ldc*rds
95
-                $uses_wildcards = strpos($key, '?') !== false
96
-                                  || strpos($key, '*') !== false;
97
-                // check request for module route
98
-                $route_found = $uses_wildcards
99
-                    ? $this->request->matches($key)
100
-                    : $this->request->is_set($key);
101
-                if ($route_found) {
102
-                    $current_route = $uses_wildcards
103
-                        ? $this->request->getMatch($key)
104
-                        : $this->request->get($key);
105
-                    $current_route = sanitize_text_field($current_route);
106
-                    if ($current_route) {
107
-                        $current_route = array($key, $current_route);
108
-                        break;
109
-                    }
110
-                }
111
-            }
112
-        }
113
-        // sorry, but I can't read what you route !
114
-        if (empty($current_route)) {
115
-            return null;
116
-        }
117
-        // add route to previous routes array
118
-        self::$_previous_routes[] = $current_route;
119
-        return $current_route;
120
-    }
45
+	/**
46
+	 * on the first call  to this method, it checks the EE_Request_Handler for a "route"
47
+	 * on subsequent calls to this method,
48
+	 * instead of checking the EE_Request_Handler for a route, it checks the previous routes array,
49
+	 * and checks if the last called route has any forwarding routes registered for it
50
+	 *
51
+	 * @param WP_Query $WP_Query
52
+	 * @return NULL|string
53
+	 * @throws EE_Error
54
+	 * @throws ReflectionException
55
+	 */
56
+	public function get_route(WP_Query $WP_Query)
57
+	{
58
+		$this->WP_Query = $WP_Query;
59
+		// assume this if first route being called
60
+		$previous_route = false;
61
+		// but is it really ???
62
+		if (! empty(self::$_previous_routes)) {
63
+			// get last run route
64
+			$previous_routes = array_values(self::$_previous_routes);
65
+			$previous_route = array_pop($previous_routes);
66
+		}
67
+		//  has another route already been run ?
68
+		if ($previous_route) {
69
+			// check if  forwarding has been set
70
+			$current_route = $this->get_forward($previous_route);
71
+			try {
72
+				// check for recursive forwarding
73
+				if (isset(self::$_previous_routes[ $current_route ])) {
74
+					throw new EE_Error(
75
+						sprintf(
76
+							__(
77
+								'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.',
78
+								'event_espresso'
79
+							),
80
+							$current_route
81
+						)
82
+					);
83
+				}
84
+			} catch (EE_Error $e) {
85
+				$e->get_error();
86
+				return null;
87
+			}
88
+		} else {
89
+			// first route called
90
+			$current_route = null;
91
+			// grab all routes
92
+			$routes = EE_Config::get_routes();
93
+			foreach ($routes as $key => $route) {
94
+				// first determine if route key uses w?ldc*rds
95
+				$uses_wildcards = strpos($key, '?') !== false
96
+								  || strpos($key, '*') !== false;
97
+				// check request for module route
98
+				$route_found = $uses_wildcards
99
+					? $this->request->matches($key)
100
+					: $this->request->is_set($key);
101
+				if ($route_found) {
102
+					$current_route = $uses_wildcards
103
+						? $this->request->getMatch($key)
104
+						: $this->request->get($key);
105
+					$current_route = sanitize_text_field($current_route);
106
+					if ($current_route) {
107
+						$current_route = array($key, $current_route);
108
+						break;
109
+					}
110
+				}
111
+			}
112
+		}
113
+		// sorry, but I can't read what you route !
114
+		if (empty($current_route)) {
115
+			return null;
116
+		}
117
+		// add route to previous routes array
118
+		self::$_previous_routes[] = $current_route;
119
+		return $current_route;
120
+	}
121 121
 
122 122
 
123
-    /**
124
-     * this method simply takes a valid route, and resolves what module class method the route points to
125
-     *
126
-     * @param string $key
127
-     * @param string $current_route
128
-     * @return mixed EED_Module | boolean
129
-     * @throws EE_Error
130
-     * @throws ReflectionException
131
-     */
132
-    public function resolve_route($key, $current_route)
133
-    {
134
-        // get module method that route has been mapped to
135
-        $module_method = EE_Config::get_route($current_route, $key);
136
-        // verify result was returned
137
-        if (empty($module_method)) {
138
-            $msg = sprintf(
139
-                __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'),
140
-                $current_route
141
-            );
142
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
143
-            return false;
144
-        }
145
-        // verify that result is an array
146
-        if (! is_array($module_method)) {
147
-            $msg = sprintf(__('The %s  route has not been properly registered.', 'event_espresso'), $current_route);
148
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
149
-            return false;
150
-        }
151
-        // grab module name
152
-        $module_name = $module_method[0];
153
-        // verify that a class method was registered properly
154
-        if (! isset($module_method[1])) {
155
-            $msg = sprintf(
156
-                __('A class method for the %s  route has not been properly registered.', 'event_espresso'),
157
-                $current_route
158
-            );
159
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
160
-            return false;
161
-        }
162
-        // grab method
163
-        $method = $module_method[1];
164
-        // verify that class exists
165
-        if (! class_exists($module_name)) {
166
-            $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name);
167
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
168
-            return false;
169
-        }
170
-        // verify that method exists
171
-        if (! method_exists($module_name, $method)) {
172
-            $msg = sprintf(
173
-                __('The class method %s for the %s route is in invalid.', 'event_espresso'),
174
-                $method,
175
-                $current_route
176
-            );
177
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
178
-            return false;
179
-        }
180
-        // instantiate module and call route method
181
-        return $this->_module_router($module_name, $method);
182
-    }
123
+	/**
124
+	 * this method simply takes a valid route, and resolves what module class method the route points to
125
+	 *
126
+	 * @param string $key
127
+	 * @param string $current_route
128
+	 * @return mixed EED_Module | boolean
129
+	 * @throws EE_Error
130
+	 * @throws ReflectionException
131
+	 */
132
+	public function resolve_route($key, $current_route)
133
+	{
134
+		// get module method that route has been mapped to
135
+		$module_method = EE_Config::get_route($current_route, $key);
136
+		// verify result was returned
137
+		if (empty($module_method)) {
138
+			$msg = sprintf(
139
+				__('The requested route %s could not be mapped to any registered modules.', 'event_espresso'),
140
+				$current_route
141
+			);
142
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
143
+			return false;
144
+		}
145
+		// verify that result is an array
146
+		if (! is_array($module_method)) {
147
+			$msg = sprintf(__('The %s  route has not been properly registered.', 'event_espresso'), $current_route);
148
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
149
+			return false;
150
+		}
151
+		// grab module name
152
+		$module_name = $module_method[0];
153
+		// verify that a class method was registered properly
154
+		if (! isset($module_method[1])) {
155
+			$msg = sprintf(
156
+				__('A class method for the %s  route has not been properly registered.', 'event_espresso'),
157
+				$current_route
158
+			);
159
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
160
+			return false;
161
+		}
162
+		// grab method
163
+		$method = $module_method[1];
164
+		// verify that class exists
165
+		if (! class_exists($module_name)) {
166
+			$msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name);
167
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
168
+			return false;
169
+		}
170
+		// verify that method exists
171
+		if (! method_exists($module_name, $method)) {
172
+			$msg = sprintf(
173
+				__('The class method %s for the %s route is in invalid.', 'event_espresso'),
174
+				$method,
175
+				$current_route
176
+			);
177
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
178
+			return false;
179
+		}
180
+		// instantiate module and call route method
181
+		return $this->_module_router($module_name, $method);
182
+	}
183 183
 
184 184
 
185
-    /**
186
-     * this method instantiates modules and calls the method that was defined when the route was registered
187
-     *
188
-     * @param string $module_name
189
-     * @return EED_Module|object|null
190
-     * @throws ReflectionException
191
-     */
192
-    public static function module_factory($module_name)
193
-    {
194
-        if ($module_name === 'EED_Module') {
195
-            EE_Error::add_error(
196
-                sprintf(
197
-                    __(
198
-                        'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.',
199
-                        'event_espresso'
200
-                    ),
201
-                    $module_name
202
-                ),
203
-                __FILE__,
204
-                __FUNCTION__,
205
-                __LINE__
206
-            );
207
-            return null;
208
-        }
209
-        // instantiate module class
210
-        $module = new $module_name();
211
-        // ensure that class is actually a module
212
-        if (! $module instanceof EED_Module) {
213
-            EE_Error::add_error(
214
-                sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name),
215
-                __FILE__,
216
-                __FUNCTION__,
217
-                __LINE__
218
-            );
219
-            return null;
220
-        }
221
-        return $module;
222
-    }
185
+	/**
186
+	 * this method instantiates modules and calls the method that was defined when the route was registered
187
+	 *
188
+	 * @param string $module_name
189
+	 * @return EED_Module|object|null
190
+	 * @throws ReflectionException
191
+	 */
192
+	public static function module_factory($module_name)
193
+	{
194
+		if ($module_name === 'EED_Module') {
195
+			EE_Error::add_error(
196
+				sprintf(
197
+					__(
198
+						'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.',
199
+						'event_espresso'
200
+					),
201
+					$module_name
202
+				),
203
+				__FILE__,
204
+				__FUNCTION__,
205
+				__LINE__
206
+			);
207
+			return null;
208
+		}
209
+		// instantiate module class
210
+		$module = new $module_name();
211
+		// ensure that class is actually a module
212
+		if (! $module instanceof EED_Module) {
213
+			EE_Error::add_error(
214
+				sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name),
215
+				__FILE__,
216
+				__FUNCTION__,
217
+				__LINE__
218
+			);
219
+			return null;
220
+		}
221
+		return $module;
222
+	}
223 223
 
224 224
 
225
-    /**
226
-     * this method instantiates modules and calls the method that was defined when the route was registered
227
-     *
228
-     * @param string $module_name
229
-     * @param string $method
230
-     * @return EED_Module|null
231
-     * @throws EE_Error
232
-     * @throws ReflectionException
233
-     */
234
-    private function _module_router($module_name, $method)
235
-    {
236
-        // instantiate module class
237
-        $module = EE_Module_Request_Router::module_factory($module_name);
238
-        if ($module instanceof EED_Module) {
239
-            // and call whatever action the route was for
240
-            try {
241
-                call_user_func(array($module, $method), $this->WP_Query);
242
-            } catch (EE_Error $e) {
243
-                $e->get_error();
244
-                return null;
245
-            }
246
-        }
247
-        return $module;
248
-    }
225
+	/**
226
+	 * this method instantiates modules and calls the method that was defined when the route was registered
227
+	 *
228
+	 * @param string $module_name
229
+	 * @param string $method
230
+	 * @return EED_Module|null
231
+	 * @throws EE_Error
232
+	 * @throws ReflectionException
233
+	 */
234
+	private function _module_router($module_name, $method)
235
+	{
236
+		// instantiate module class
237
+		$module = EE_Module_Request_Router::module_factory($module_name);
238
+		if ($module instanceof EED_Module) {
239
+			// and call whatever action the route was for
240
+			try {
241
+				call_user_func(array($module, $method), $this->WP_Query);
242
+			} catch (EE_Error $e) {
243
+				$e->get_error();
244
+				return null;
245
+			}
246
+		}
247
+		return $module;
248
+	}
249 249
 
250 250
 
251
-    /**
252
-     * @param $current_route
253
-     * @return string
254
-     */
255
-    public function get_forward($current_route)
256
-    {
257
-        return EE_Config::get_forward($current_route);
258
-    }
251
+	/**
252
+	 * @param $current_route
253
+	 * @return string
254
+	 */
255
+	public function get_forward($current_route)
256
+	{
257
+		return EE_Config::get_forward($current_route);
258
+	}
259 259
 
260 260
 
261
-    /**
262
-     * @param $current_route
263
-     * @return string
264
-     */
265
-    public function get_view($current_route)
266
-    {
267
-        return EE_Config::get_view($current_route);
268
-    }
261
+	/**
262
+	 * @param $current_route
263
+	 * @return string
264
+	 */
265
+	public function get_view($current_route)
266
+	{
267
+		return EE_Config::get_view($current_route);
268
+	}
269 269
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
         // assume this if first route being called
60 60
         $previous_route = false;
61 61
         // but is it really ???
62
-        if (! empty(self::$_previous_routes)) {
62
+        if ( ! empty(self::$_previous_routes)) {
63 63
             // get last run route
64 64
             $previous_routes = array_values(self::$_previous_routes);
65 65
             $previous_route = array_pop($previous_routes);
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
             $current_route = $this->get_forward($previous_route);
71 71
             try {
72 72
                 // check for recursive forwarding
73
-                if (isset(self::$_previous_routes[ $current_route ])) {
73
+                if (isset(self::$_previous_routes[$current_route])) {
74 74
                     throw new EE_Error(
75 75
                         sprintf(
76 76
                             __(
@@ -143,38 +143,38 @@  discard block
 block discarded – undo
143 143
             return false;
144 144
         }
145 145
         // verify that result is an array
146
-        if (! is_array($module_method)) {
146
+        if ( ! is_array($module_method)) {
147 147
             $msg = sprintf(__('The %s  route has not been properly registered.', 'event_espresso'), $current_route);
148
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
148
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
149 149
             return false;
150 150
         }
151 151
         // grab module name
152 152
         $module_name = $module_method[0];
153 153
         // verify that a class method was registered properly
154
-        if (! isset($module_method[1])) {
154
+        if ( ! isset($module_method[1])) {
155 155
             $msg = sprintf(
156 156
                 __('A class method for the %s  route has not been properly registered.', 'event_espresso'),
157 157
                 $current_route
158 158
             );
159
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
159
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
160 160
             return false;
161 161
         }
162 162
         // grab method
163 163
         $method = $module_method[1];
164 164
         // verify that class exists
165
-        if (! class_exists($module_name)) {
165
+        if ( ! class_exists($module_name)) {
166 166
             $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name);
167 167
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
168 168
             return false;
169 169
         }
170 170
         // verify that method exists
171
-        if (! method_exists($module_name, $method)) {
171
+        if ( ! method_exists($module_name, $method)) {
172 172
             $msg = sprintf(
173 173
                 __('The class method %s for the %s route is in invalid.', 'event_espresso'),
174 174
                 $method,
175 175
                 $current_route
176 176
             );
177
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
177
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
178 178
             return false;
179 179
         }
180 180
         // instantiate module and call route method
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
         // instantiate module class
210 210
         $module = new $module_name();
211 211
         // ensure that class is actually a module
212
-        if (! $module instanceof EED_Module) {
212
+        if ( ! $module instanceof EED_Module) {
213 213
             EE_Error::add_error(
214 214
                 sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name),
215 215
                 __FILE__,
Please login to merge, or discard this patch.
core/interfaces/EEI_Request_Decorator.interface.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -9,24 +9,24 @@
 block discarded – undo
9 9
 interface EEI_Request_Decorator
10 10
 {
11 11
 
12
-    /**
13
-     * converts a Request to a Response
14
-     * can perform their logic either before or after the core application has run like so:
15
-     *    public function handle_request( EE_Request $request, EE_Response $response ) {
16
-     *        $this->request = $request;
17
-     *        $this->response = $response;
18
-     *      // logic performed BEFORE core app has run
19
-     *      $this->process_request_stack( $this->request, $this->response );
20
-     *      // logic performed AFTER core app has run
21
-     *      return $response;
22
-     *    }
23
-     *
24
-     * @deprecated 4.9.53
25
-     * @param    EE_Request $request
26
-     * @param    EE_Response   $response
27
-     * @return    EE_Response
28
-     */
29
-    public function handle_request(EE_Request $request, EE_Response $response);
12
+	/**
13
+	 * converts a Request to a Response
14
+	 * can perform their logic either before or after the core application has run like so:
15
+	 *    public function handle_request( EE_Request $request, EE_Response $response ) {
16
+	 *        $this->request = $request;
17
+	 *        $this->response = $response;
18
+	 *      // logic performed BEFORE core app has run
19
+	 *      $this->process_request_stack( $this->request, $this->response );
20
+	 *      // logic performed AFTER core app has run
21
+	 *      return $response;
22
+	 *    }
23
+	 *
24
+	 * @deprecated 4.9.53
25
+	 * @param    EE_Request $request
26
+	 * @param    EE_Response   $response
27
+	 * @return    EE_Response
28
+	 */
29
+	public function handle_request(EE_Request $request, EE_Response $response);
30 30
 
31 31
 
32 32
 }
Please login to merge, or discard this patch.
core/services/request/LegacyRequestInterface.php 1 patch
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -15,125 +15,125 @@
 block discarded – undo
15 15
 interface LegacyRequestInterface
16 16
 {
17 17
 
18
-    /**
19
-     * @return array
20
-     */
21
-    public function get_params();
18
+	/**
19
+	 * @return array
20
+	 */
21
+	public function get_params();
22 22
 
23 23
 
24
-    /**
25
-     * @return array
26
-     */
27
-    public function post_params();
24
+	/**
25
+	 * @return array
26
+	 */
27
+	public function post_params();
28 28
 
29 29
 
30
-    /**
31
-     * @return array
32
-     */
33
-    public function cookie_params();
30
+	/**
31
+	 * @return array
32
+	 */
33
+	public function cookie_params();
34 34
 
35 35
 
36
-    /**
37
-     * @return array
38
-     */
39
-    public function server_params();
36
+	/**
37
+	 * @return array
38
+	 */
39
+	public function server_params();
40 40
 
41 41
 
42
-    /**
43
-     * returns contents of $_REQUEST
44
-     *
45
-     * @return array
46
-     */
47
-    public function params();
42
+	/**
43
+	 * returns contents of $_REQUEST
44
+	 *
45
+	 * @return array
46
+	 */
47
+	public function params();
48 48
 
49 49
 
50
-    /**
51
-     * @param      $key
52
-     * @param      $value
53
-     * @param bool $override_ee
54
-     * @return    void
55
-     */
56
-    public function set($key, $value, $override_ee = false);
50
+	/**
51
+	 * @param      $key
52
+	 * @param      $value
53
+	 * @param bool $override_ee
54
+	 * @return    void
55
+	 */
56
+	public function set($key, $value, $override_ee = false);
57 57
 
58 58
 
59
-    /**
60
-     * returns   the value for a request param if the given key exists
61
-     *
62
-     * @param       $key
63
-     * @param null  $default
64
-     * @return mixed
65
-     */
66
-    public function get($key, $default = null);
59
+	/**
60
+	 * returns   the value for a request param if the given key exists
61
+	 *
62
+	 * @param       $key
63
+	 * @param null  $default
64
+	 * @return mixed
65
+	 */
66
+	public function get($key, $default = null);
67 67
 
68 68
 
69
-    /**
70
-     * check if param exists
71
-     *
72
-     * @param       $key
73
-     * @return bool
74
-     */
75
-    public function is_set($key);
69
+	/**
70
+	 * check if param exists
71
+	 *
72
+	 * @param       $key
73
+	 * @return bool
74
+	 */
75
+	public function is_set($key);
76 76
 
77 77
 
78
-    /**
79
-     * remove param
80
-     *
81
-     * @param      $key
82
-     * @param bool $unset_from_global_too
83
-     */
84
-    public function un_set($key, $unset_from_global_too = false);
78
+	/**
79
+	 * remove param
80
+	 *
81
+	 * @param      $key
82
+	 * @param bool $unset_from_global_too
83
+	 */
84
+	public function un_set($key, $unset_from_global_too = false);
85 85
 
86 86
 
87
-    /**
88
-     * @return string
89
-     */
90
-    public function ip_address();
87
+	/**
88
+	 * @return string
89
+	 */
90
+	public function ip_address();
91 91
 
92 92
 
93
-    /**
94
-     * @return bool
95
-     */
96
-    public function isAdmin();
93
+	/**
94
+	 * @return bool
95
+	 */
96
+	public function isAdmin();
97 97
 
98 98
 
99
-    /**
100
-     * @return mixed
101
-     */
102
-    public function isAjax();
99
+	/**
100
+	 * @return mixed
101
+	 */
102
+	public function isAjax();
103 103
 
104 104
 
105
-    /**
106
-     * @return mixed
107
-     */
108
-    public function isFrontAjax();
105
+	/**
106
+	 * @return mixed
107
+	 */
108
+	public function isFrontAjax();
109 109
 
110 110
 
111
-    /**
112
-     * @return mixed|string
113
-     */
114
-    public function requestUri();
111
+	/**
112
+	 * @return mixed|string
113
+	 */
114
+	public function requestUri();
115 115
 
116 116
 
117
-    /**
118
-     * @return string
119
-     */
120
-    public function userAgent();
117
+	/**
118
+	 * @return string
119
+	 */
120
+	public function userAgent();
121 121
 
122 122
 
123
-    /**
124
-     * @param string $user_agent
125
-     */
126
-    public function setUserAgent($user_agent = '');
123
+	/**
124
+	 * @param string $user_agent
125
+	 */
126
+	public function setUserAgent($user_agent = '');
127 127
 
128 128
 
129
-    /**
130
-     * @return bool
131
-     */
132
-    public function isBot();
129
+	/**
130
+	 * @return bool
131
+	 */
132
+	public function isBot();
133 133
 
134 134
 
135
-    /**
136
-     * @param bool $is_bot
137
-     */
138
-    public function setIsBot($is_bot);
135
+	/**
136
+	 * @param bool $is_bot
137
+	 */
138
+	public function setIsBot($is_bot);
139 139
 }
Please login to merge, or discard this patch.
core/services/request/Response.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
      */
59 59
     public function setNotice($key, $value)
60 60
     {
61
-        $this->notice[ $key ] = $value;
61
+        $this->notice[$key] = $value;
62 62
     }
63 63
 
64 64
 
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public function getNotice($key)
71 71
     {
72
-        return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null;
72
+        return isset($this->notice[$key]) ? $this->notice[$key] : null;
73 73
     }
74 74
 
75 75
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
      */
91 91
     public function addOutput($string, $append = true)
92 92
     {
93
-        $this->output = $append ? $this->output . $string : $string . $this->output;
93
+        $this->output = $append ? $this->output.$string : $string.$this->output;
94 94
     }
95 95
 
96 96
 
Please login to merge, or discard this patch.
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -16,119 +16,119 @@
 block discarded – undo
16 16
 class Response implements ResponseInterface, ReservedInstanceInterface
17 17
 {
18 18
 
19
-    /**
20
-     * @var array $notice
21
-     */
22
-    protected $notice = array();
23
-
24
-    /**
25
-     * rendered output to be returned to WP
26
-     *
27
-     * @var string $output
28
-     */
29
-    protected $output = '';
30
-
31
-    /**
32
-     * @var bool
33
-     */
34
-    protected $request_terminated = false;
35
-
36
-    /**
37
-     * @var bool $deactivate_plugin
38
-     */
39
-    protected $deactivate_plugin = false;
40
-
41
-
42
-    /**
43
-     * EE_Response constructor.
44
-     */
45
-    public function __construct()
46
-    {
47
-        $this->terminateRequest(false);
48
-    }
49
-
50
-
51
-    /**
52
-     * @param $key
53
-     * @param $value
54
-     * @return    void
55
-     */
56
-    public function setNotice($key, $value)
57
-    {
58
-        $this->notice[ $key ] = $value;
59
-    }
60
-
61
-
62
-    /**
63
-     * @param $key
64
-     * @return    mixed
65
-     */
66
-    public function getNotice($key)
67
-    {
68
-        return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null;
69
-    }
70
-
71
-
72
-    /**
73
-     * @return array
74
-     */
75
-    public function getNotices()
76
-    {
77
-        return $this->notice;
78
-    }
79
-
80
-
81
-    /**
82
-     * @param string $string
83
-     * @param bool   $append
84
-     */
85
-    public function addOutput($string, $append = true)
86
-    {
87
-        $this->output = $append ? $this->output . $string : $string . $this->output;
88
-    }
89
-
90
-
91
-    /**
92
-     * @return string
93
-     */
94
-    public function getOutput()
95
-    {
96
-        return $this->output;
97
-    }
98
-
99
-
100
-    /**
101
-     * @return boolean
102
-     */
103
-    public function requestTerminated()
104
-    {
105
-        return $this->request_terminated;
106
-    }
107
-
108
-
109
-    /**
110
-     * @param boolean $request_terminated
111
-     */
112
-    public function terminateRequest($request_terminated = true)
113
-    {
114
-        $this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN);
115
-    }
116
-
117
-
118
-    /**
119
-     * @return boolean
120
-     */
121
-    public function pluginDeactivated()
122
-    {
123
-        return $this->deactivate_plugin;
124
-    }
125
-
126
-
127
-    /**
128
-     * sets $deactivate_plugin to true
129
-     */
130
-    public function deactivatePlugin()
131
-    {
132
-        $this->deactivate_plugin = true;
133
-    }
19
+	/**
20
+	 * @var array $notice
21
+	 */
22
+	protected $notice = array();
23
+
24
+	/**
25
+	 * rendered output to be returned to WP
26
+	 *
27
+	 * @var string $output
28
+	 */
29
+	protected $output = '';
30
+
31
+	/**
32
+	 * @var bool
33
+	 */
34
+	protected $request_terminated = false;
35
+
36
+	/**
37
+	 * @var bool $deactivate_plugin
38
+	 */
39
+	protected $deactivate_plugin = false;
40
+
41
+
42
+	/**
43
+	 * EE_Response constructor.
44
+	 */
45
+	public function __construct()
46
+	{
47
+		$this->terminateRequest(false);
48
+	}
49
+
50
+
51
+	/**
52
+	 * @param $key
53
+	 * @param $value
54
+	 * @return    void
55
+	 */
56
+	public function setNotice($key, $value)
57
+	{
58
+		$this->notice[ $key ] = $value;
59
+	}
60
+
61
+
62
+	/**
63
+	 * @param $key
64
+	 * @return    mixed
65
+	 */
66
+	public function getNotice($key)
67
+	{
68
+		return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null;
69
+	}
70
+
71
+
72
+	/**
73
+	 * @return array
74
+	 */
75
+	public function getNotices()
76
+	{
77
+		return $this->notice;
78
+	}
79
+
80
+
81
+	/**
82
+	 * @param string $string
83
+	 * @param bool   $append
84
+	 */
85
+	public function addOutput($string, $append = true)
86
+	{
87
+		$this->output = $append ? $this->output . $string : $string . $this->output;
88
+	}
89
+
90
+
91
+	/**
92
+	 * @return string
93
+	 */
94
+	public function getOutput()
95
+	{
96
+		return $this->output;
97
+	}
98
+
99
+
100
+	/**
101
+	 * @return boolean
102
+	 */
103
+	public function requestTerminated()
104
+	{
105
+		return $this->request_terminated;
106
+	}
107
+
108
+
109
+	/**
110
+	 * @param boolean $request_terminated
111
+	 */
112
+	public function terminateRequest($request_terminated = true)
113
+	{
114
+		$this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN);
115
+	}
116
+
117
+
118
+	/**
119
+	 * @return boolean
120
+	 */
121
+	public function pluginDeactivated()
122
+	{
123
+		return $this->deactivate_plugin;
124
+	}
125
+
126
+
127
+	/**
128
+	 * sets $deactivate_plugin to true
129
+	 */
130
+	public function deactivatePlugin()
131
+	{
132
+		$this->deactivate_plugin = true;
133
+	}
134 134
 }
Please login to merge, or discard this patch.