Completed
Branch FET/simplify-rest-api-passing-... (073bff)
by
unknown
40:42 queued 31:00
created
core/EE_Network_Config.core.php 2 patches
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -14,180 +14,180 @@  discard block
 block discarded – undo
14 14
 final class EE_Network_Config
15 15
 {
16 16
 
17
-    /**
18
-     * @var EE_Network_Config $_instance
19
-     */
20
-    private static $_instance;
21
-
22
-    /**
23
-     * addons can add their specific network_config objects to this property
24
-     *
25
-     * @var EE_Config_Base[] $addons
26
-     */
27
-    public $addons;
28
-
29
-    /**
30
-     * @var EE_Network_Core_Config $core
31
-     */
32
-    public $core;
33
-
34
-
35
-    /**
36
-     * @singleton method used to instantiate class object
37
-     * @return EE_Network_Config instance
38
-     */
39
-    public static function instance()
40
-    {
41
-        // check if class object is instantiated, and instantiated properly
42
-        if (! self::$_instance instanceof EE_Network_Config) {
43
-            self::$_instance = new self();
44
-        }
45
-        return self::$_instance;
46
-    }
47
-
48
-
49
-    /**
50
-     * class constructor
51
-     */
52
-    private function __construct()
53
-    {
54
-        do_action('AHEE__EE_Network_Config__construct__begin', $this);
55
-        // set defaults
56
-        $this->core = apply_filters('FHEE__EE_Network_Config___construct__core', new EE_Network_Core_Config());
57
-        $this->addons = array();
58
-
59
-        $this->_load_config();
60
-
61
-        // construct__end hook
62
-        do_action('AHEE__EE_Network_Config__construct__end', $this);
63
-    }
64
-
65
-
66
-    /**
67
-     * load EE Network Config options
68
-     *
69
-     * @return void
70
-     */
71
-    private function _load_config()
72
-    {
73
-        // load network config start hook
74
-        do_action('AHEE__EE_Network_Config___load_config__start', $this);
75
-        $config = $this->get_config();
76
-        foreach ($config as $config_prop => $settings) {
77
-            if ($config_prop === 'core' && ! $settings instanceof EE_Network_Core_Config) {
78
-                $core = new EE_Network_Core_Config();
79
-                foreach ($settings as $prop => $setting) {
80
-                    if (property_exists($core, $prop)) {
81
-                        $core->{$prop} = $setting;
82
-                    }
83
-                }
84
-                $settings = $core;
85
-                add_filter('FHEE__EE_Network_Config___load_config__update_network_config', '__return_true');
86
-            }
87
-            if (is_object($settings) && property_exists($this, $config_prop)) {
88
-                $this->{$config_prop} = apply_filters(
89
-                    'FHEE__EE_Network_Config___load_config__config_settings',
90
-                    $settings,
91
-                    $config_prop,
92
-                    $this
93
-                );
94
-                if (method_exists($settings, 'populate')) {
95
-                    $this->{$config_prop}->populate();
96
-                }
97
-                if (method_exists($settings, 'do_hooks')) {
98
-                    $this->{$config_prop}->do_hooks();
99
-                }
100
-            }
101
-        }
102
-        if (apply_filters('FHEE__EE_Network_Config___load_config__update_network_config', false)) {
103
-            $this->update_config();
104
-        }
105
-
106
-        // load network config end hook
107
-        do_action('AHEE__EE_Network_Config___load_config__end', $this);
108
-    }
109
-
110
-
111
-    /**
112
-     * get_config
113
-     *
114
-     * @return array of network config stuff
115
-     */
116
-    public function get_config()
117
-    {
118
-        // grab network configuration
119
-        $CFG = get_site_option('ee_network_config', array());
120
-        $CFG = apply_filters('FHEE__EE_Network_Config__get_config__CFG', $CFG);
121
-        return $CFG;
122
-    }
123
-
124
-
125
-    /**
126
-     * update_config
127
-     *
128
-     * @param bool $add_success
129
-     * @param bool $add_error
130
-     * @return bool success
131
-     */
132
-    public function update_config($add_success = false, $add_error = true)
133
-    {
134
-        do_action('AHEE__EE_Network_Config__update_config__begin', $this);
135
-
136
-        // need to bust cache for comparing original if this is a multisite install
137
-        if (is_multisite()) {
138
-            global $current_site;
139
-            $cache_key = $current_site->id . ':ee_network_config';
140
-            wp_cache_delete($cache_key, 'site-options');
141
-        }
142
-
143
-        // we have to compare existing saved config with config in memory because if there is no difference that means
144
-        // that the method executed fine but there just was no update.  WordPress doesn't distinguish between false because
145
-        // there were 0 records updated because of no change vs false because some error produced problems with the update.
146
-        $original = get_site_option('ee_network_config');
147
-
148
-        if ($original == $this) {
149
-            return true;
150
-        }
151
-        // update
152
-        $saved = update_site_option('ee_network_config', $this);
153
-
154
-        do_action('AHEE__EE_Network_Config__update_config__end', $this, $saved);
155
-        // if config remains the same or was updated successfully
156
-        if ($saved) {
157
-            if ($add_success) {
158
-                $msg = is_multisite() ? __(
159
-                    'The Event Espresso Network Configuration Settings have been successfully updated.',
160
-                    'event_espresso'
161
-                ) : __('Extra Event Espresso Configuration settings were successfully updated.', 'event_espresso');
162
-                EE_Error::add_success($msg);
163
-            }
164
-            return true;
165
-        }
166
-        if ($add_error) {
167
-            $msg = is_multisite() ? __(
168
-                'The Event Espresso Network Configuration Settings were not updated.',
169
-                'event_espresso'
170
-            ) : __('Extra Event Espresso Network Configuration settings were not updated.', 'event_espresso');
171
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
172
-        }
173
-        return false;
174
-    }
175
-
176
-
177
-    /**
178
-     * __sleep
179
-     *
180
-     * @return array
181
-     */
182
-    public function __sleep()
183
-    {
184
-        return apply_filters(
185
-            'FHEE__EE_Network_Config__sleep',
186
-            array(
187
-                'core',
188
-            )
189
-        );
190
-    }
17
+	/**
18
+	 * @var EE_Network_Config $_instance
19
+	 */
20
+	private static $_instance;
21
+
22
+	/**
23
+	 * addons can add their specific network_config objects to this property
24
+	 *
25
+	 * @var EE_Config_Base[] $addons
26
+	 */
27
+	public $addons;
28
+
29
+	/**
30
+	 * @var EE_Network_Core_Config $core
31
+	 */
32
+	public $core;
33
+
34
+
35
+	/**
36
+	 * @singleton method used to instantiate class object
37
+	 * @return EE_Network_Config instance
38
+	 */
39
+	public static function instance()
40
+	{
41
+		// check if class object is instantiated, and instantiated properly
42
+		if (! self::$_instance instanceof EE_Network_Config) {
43
+			self::$_instance = new self();
44
+		}
45
+		return self::$_instance;
46
+	}
47
+
48
+
49
+	/**
50
+	 * class constructor
51
+	 */
52
+	private function __construct()
53
+	{
54
+		do_action('AHEE__EE_Network_Config__construct__begin', $this);
55
+		// set defaults
56
+		$this->core = apply_filters('FHEE__EE_Network_Config___construct__core', new EE_Network_Core_Config());
57
+		$this->addons = array();
58
+
59
+		$this->_load_config();
60
+
61
+		// construct__end hook
62
+		do_action('AHEE__EE_Network_Config__construct__end', $this);
63
+	}
64
+
65
+
66
+	/**
67
+	 * load EE Network Config options
68
+	 *
69
+	 * @return void
70
+	 */
71
+	private function _load_config()
72
+	{
73
+		// load network config start hook
74
+		do_action('AHEE__EE_Network_Config___load_config__start', $this);
75
+		$config = $this->get_config();
76
+		foreach ($config as $config_prop => $settings) {
77
+			if ($config_prop === 'core' && ! $settings instanceof EE_Network_Core_Config) {
78
+				$core = new EE_Network_Core_Config();
79
+				foreach ($settings as $prop => $setting) {
80
+					if (property_exists($core, $prop)) {
81
+						$core->{$prop} = $setting;
82
+					}
83
+				}
84
+				$settings = $core;
85
+				add_filter('FHEE__EE_Network_Config___load_config__update_network_config', '__return_true');
86
+			}
87
+			if (is_object($settings) && property_exists($this, $config_prop)) {
88
+				$this->{$config_prop} = apply_filters(
89
+					'FHEE__EE_Network_Config___load_config__config_settings',
90
+					$settings,
91
+					$config_prop,
92
+					$this
93
+				);
94
+				if (method_exists($settings, 'populate')) {
95
+					$this->{$config_prop}->populate();
96
+				}
97
+				if (method_exists($settings, 'do_hooks')) {
98
+					$this->{$config_prop}->do_hooks();
99
+				}
100
+			}
101
+		}
102
+		if (apply_filters('FHEE__EE_Network_Config___load_config__update_network_config', false)) {
103
+			$this->update_config();
104
+		}
105
+
106
+		// load network config end hook
107
+		do_action('AHEE__EE_Network_Config___load_config__end', $this);
108
+	}
109
+
110
+
111
+	/**
112
+	 * get_config
113
+	 *
114
+	 * @return array of network config stuff
115
+	 */
116
+	public function get_config()
117
+	{
118
+		// grab network configuration
119
+		$CFG = get_site_option('ee_network_config', array());
120
+		$CFG = apply_filters('FHEE__EE_Network_Config__get_config__CFG', $CFG);
121
+		return $CFG;
122
+	}
123
+
124
+
125
+	/**
126
+	 * update_config
127
+	 *
128
+	 * @param bool $add_success
129
+	 * @param bool $add_error
130
+	 * @return bool success
131
+	 */
132
+	public function update_config($add_success = false, $add_error = true)
133
+	{
134
+		do_action('AHEE__EE_Network_Config__update_config__begin', $this);
135
+
136
+		// need to bust cache for comparing original if this is a multisite install
137
+		if (is_multisite()) {
138
+			global $current_site;
139
+			$cache_key = $current_site->id . ':ee_network_config';
140
+			wp_cache_delete($cache_key, 'site-options');
141
+		}
142
+
143
+		// we have to compare existing saved config with config in memory because if there is no difference that means
144
+		// that the method executed fine but there just was no update.  WordPress doesn't distinguish between false because
145
+		// there were 0 records updated because of no change vs false because some error produced problems with the update.
146
+		$original = get_site_option('ee_network_config');
147
+
148
+		if ($original == $this) {
149
+			return true;
150
+		}
151
+		// update
152
+		$saved = update_site_option('ee_network_config', $this);
153
+
154
+		do_action('AHEE__EE_Network_Config__update_config__end', $this, $saved);
155
+		// if config remains the same or was updated successfully
156
+		if ($saved) {
157
+			if ($add_success) {
158
+				$msg = is_multisite() ? __(
159
+					'The Event Espresso Network Configuration Settings have been successfully updated.',
160
+					'event_espresso'
161
+				) : __('Extra Event Espresso Configuration settings were successfully updated.', 'event_espresso');
162
+				EE_Error::add_success($msg);
163
+			}
164
+			return true;
165
+		}
166
+		if ($add_error) {
167
+			$msg = is_multisite() ? __(
168
+				'The Event Espresso Network Configuration Settings were not updated.',
169
+				'event_espresso'
170
+			) : __('Extra Event Espresso Network Configuration settings were not updated.', 'event_espresso');
171
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
172
+		}
173
+		return false;
174
+	}
175
+
176
+
177
+	/**
178
+	 * __sleep
179
+	 *
180
+	 * @return array
181
+	 */
182
+	public function __sleep()
183
+	{
184
+		return apply_filters(
185
+			'FHEE__EE_Network_Config__sleep',
186
+			array(
187
+				'core',
188
+			)
189
+		);
190
+	}
191 191
 }
192 192
 
193 193
 
@@ -197,27 +197,27 @@  discard block
 block discarded – undo
197 197
 class EE_Network_Core_Config extends EE_Config_Base
198 198
 {
199 199
 
200
-    /**
201
-     * PUE site license key
202
-     *
203
-     * @var string $site_license_key
204
-     */
205
-    public $site_license_key;
206
-
207
-    /**
208
-     * This indicates whether messages system processing should be done on the same request or not.
209
-     *
210
-     * @var boolean $do_messages_on_same_request
211
-     */
212
-    public $do_messages_on_same_request;
213
-
214
-
215
-    /**
216
-     * EE_Network_Core_Config constructor.
217
-     */
218
-    public function __construct()
219
-    {
220
-        $this->site_license_key = '';
221
-        $this->do_messages_on_same_request = false;
222
-    }
200
+	/**
201
+	 * PUE site license key
202
+	 *
203
+	 * @var string $site_license_key
204
+	 */
205
+	public $site_license_key;
206
+
207
+	/**
208
+	 * This indicates whether messages system processing should be done on the same request or not.
209
+	 *
210
+	 * @var boolean $do_messages_on_same_request
211
+	 */
212
+	public $do_messages_on_same_request;
213
+
214
+
215
+	/**
216
+	 * EE_Network_Core_Config constructor.
217
+	 */
218
+	public function __construct()
219
+	{
220
+		$this->site_license_key = '';
221
+		$this->do_messages_on_same_request = false;
222
+	}
223 223
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
     public static function instance()
40 40
     {
41 41
         // check if class object is instantiated, and instantiated properly
42
-        if (! self::$_instance instanceof EE_Network_Config) {
42
+        if ( ! self::$_instance instanceof EE_Network_Config) {
43 43
             self::$_instance = new self();
44 44
         }
45 45
         return self::$_instance;
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
         // need to bust cache for comparing original if this is a multisite install
137 137
         if (is_multisite()) {
138 138
             global $current_site;
139
-            $cache_key = $current_site->id . ':ee_network_config';
139
+            $cache_key = $current_site->id.':ee_network_config';
140 140
             wp_cache_delete($cache_key, 'site-options');
141 141
         }
142 142
 
Please login to merge, or discard this patch.
core/EE_Registry.core.php 2 patches
Indentation   +1665 added lines, -1665 removed lines patch added patch discarded remove patch
@@ -23,1669 +23,1669 @@
 block discarded – undo
23 23
 class EE_Registry implements ResettableInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Registry $_instance
28
-     */
29
-    private static $_instance;
30
-
31
-    /**
32
-     * @var EE_Dependency_Map $_dependency_map
33
-     */
34
-    protected $_dependency_map;
35
-
36
-    /**
37
-     * @var Mirror
38
-     */
39
-    private $mirror;
40
-
41
-    /**
42
-     * @var ClassInterfaceCache $class_cache
43
-     */
44
-    private $class_cache;
45
-
46
-    /**
47
-     * @var array $_class_abbreviations
48
-     */
49
-    protected $_class_abbreviations = array();
50
-
51
-    /**
52
-     * @var CommandBusInterface $BUS
53
-     */
54
-    public $BUS;
55
-
56
-    /**
57
-     * @var EE_Cart $CART
58
-     */
59
-    public $CART;
60
-
61
-    /**
62
-     * @var EE_Config $CFG
63
-     */
64
-    public $CFG;
65
-
66
-    /**
67
-     * @var EE_Network_Config $NET_CFG
68
-     */
69
-    public $NET_CFG;
70
-
71
-    /**
72
-     * StdClass object for storing library classes in
73
-     *
74
-     * @var RegistryContainer $LIB
75
-     */
76
-    public $LIB;
77
-
78
-    /**
79
-     * @var EE_Request_Handler $REQ
80
-     */
81
-    public $REQ;
82
-
83
-    /**
84
-     * @var EE_Session $SSN
85
-     */
86
-    public $SSN;
87
-
88
-    /**
89
-     * @since 4.5.0
90
-     * @var EE_Capabilities $CAP
91
-     */
92
-    public $CAP;
93
-
94
-    /**
95
-     * @since 4.9.0
96
-     * @var EE_Message_Resource_Manager $MRM
97
-     */
98
-    public $MRM;
99
-
100
-    /**
101
-     * @var Registry $AssetsRegistry
102
-     */
103
-    public $AssetsRegistry;
104
-
105
-    /**
106
-     * StdClass object for holding addons which have registered themselves to work with EE core
107
-     *
108
-     * @var EE_Addon[] $addons
109
-     */
110
-    public $addons;
111
-
112
-    /**
113
-     * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
114
-     *
115
-     * @var EEM_Base[] $models
116
-     */
117
-    public $models = array();
118
-
119
-    /**
120
-     * @var EED_Module[] $modules
121
-     */
122
-    public $modules;
123
-
124
-    /**
125
-     * @var EES_Shortcode[] $shortcodes
126
-     */
127
-    public $shortcodes;
128
-
129
-    /**
130
-     * @var WP_Widget[] $widgets
131
-     */
132
-    public $widgets;
133
-
134
-    /**
135
-     * this is an array of all implemented model names (i.e. not the parent abstract models, or models
136
-     * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
137
-     * Keys are model "short names" (eg "Event") as used in model relations, and values are
138
-     * classnames (eg "EEM_Event")
139
-     *
140
-     * @var array $non_abstract_db_models
141
-     */
142
-    public $non_abstract_db_models = array();
143
-
144
-    /**
145
-     * internationalization for JS strings
146
-     *    usage:   EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' );
147
-     *    in js file:  var translatedString = eei18n.string_key;
148
-     *
149
-     * @var array $i18n_js_strings
150
-     */
151
-    public static $i18n_js_strings = array();
152
-
153
-    /**
154
-     * $main_file - path to espresso.php
155
-     *
156
-     * @var array $main_file
157
-     */
158
-    public $main_file;
159
-
160
-    /**
161
-     * array of ReflectionClass objects where the key is the class name
162
-     *
163
-     * @deprecated 4.9.62.p
164
-     * @var ReflectionClass[] $_reflectors
165
-     */
166
-    public $_reflectors;
167
-
168
-    /**
169
-     * boolean flag to indicate whether or not to load/save dependencies from/to the cache
170
-     *
171
-     * @var boolean $_cache_on
172
-     */
173
-    protected $_cache_on = true;
174
-
175
-    /**
176
-     * @var ObjectIdentifier
177
-     */
178
-    private $object_identifier;
179
-
180
-
181
-    /**
182
-     * @singleton method used to instantiate class object
183
-     * @param EE_Dependency_Map|null   $dependency_map
184
-     * @param Mirror|null              $mirror
185
-     * @param ClassInterfaceCache|null $class_cache
186
-     * @param ObjectIdentifier|null    $object_identifier
187
-     * @return EE_Registry instance
188
-     */
189
-    public static function instance(
190
-        EE_Dependency_Map $dependency_map = null,
191
-        Mirror $mirror = null,
192
-        ClassInterfaceCache $class_cache = null,
193
-        ObjectIdentifier $object_identifier = null
194
-    ) {
195
-        // check if class object is instantiated
196
-        if (! self::$_instance instanceof EE_Registry
197
-            && $dependency_map instanceof EE_Dependency_Map
198
-            && $mirror instanceof Mirror
199
-            && $class_cache instanceof ClassInterfaceCache
200
-            && $object_identifier instanceof ObjectIdentifier
201
-        ) {
202
-            self::$_instance = new self(
203
-                $dependency_map,
204
-                $mirror,
205
-                $class_cache,
206
-                $object_identifier
207
-            );
208
-        }
209
-        return self::$_instance;
210
-    }
211
-
212
-
213
-    /**
214
-     * protected constructor to prevent direct creation
215
-     *
216
-     * @Constructor
217
-     * @param  EE_Dependency_Map  $dependency_map
218
-     * @param Mirror              $mirror
219
-     * @param ClassInterfaceCache $class_cache
220
-     * @param ObjectIdentifier    $object_identifier
221
-     */
222
-    protected function __construct(
223
-        EE_Dependency_Map $dependency_map,
224
-        Mirror $mirror,
225
-        ClassInterfaceCache $class_cache,
226
-        ObjectIdentifier $object_identifier
227
-    ) {
228
-        $this->_dependency_map = $dependency_map;
229
-        $this->mirror = $mirror;
230
-        $this->class_cache = $class_cache;
231
-        $this->object_identifier = $object_identifier;
232
-        // $registry_container = new RegistryContainer();
233
-        $this->LIB = new RegistryContainer();
234
-        $this->addons = new RegistryContainer();
235
-        $this->modules = new RegistryContainer();
236
-        $this->shortcodes = new RegistryContainer();
237
-        $this->widgets = new RegistryContainer();
238
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
239
-    }
240
-
241
-
242
-    /**
243
-     * initialize
244
-     *
245
-     * @throws OutOfBoundsException
246
-     * @throws InvalidArgumentException
247
-     * @throws InvalidInterfaceException
248
-     * @throws InvalidDataTypeException
249
-     * @throws EE_Error
250
-     * @throws ReflectionException
251
-     */
252
-    public function initialize()
253
-    {
254
-        $this->_class_abbreviations = apply_filters(
255
-            'FHEE__EE_Registry____construct___class_abbreviations',
256
-            array(
257
-                'EE_Config'                                       => 'CFG',
258
-                'EE_Session'                                      => 'SSN',
259
-                'EE_Capabilities'                                 => 'CAP',
260
-                'EE_Cart'                                         => 'CART',
261
-                'EE_Network_Config'                               => 'NET_CFG',
262
-                'EE_Request_Handler'                              => 'REQ',
263
-                'EE_Message_Resource_Manager'                     => 'MRM',
264
-                'EventEspresso\core\services\commands\CommandBus' => 'BUS',
265
-                'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
266
-            )
267
-        );
268
-        $this->load_core('Base', array(), true);
269
-        // add our request and response objects to the cache
270
-        $request_loader = $this->_dependency_map->class_loader(
271
-            'EventEspresso\core\services\request\Request'
272
-        );
273
-        $this->_set_cached_class(
274
-            $request_loader(),
275
-            'EventEspresso\core\services\request\Request'
276
-        );
277
-        $response_loader = $this->_dependency_map->class_loader(
278
-            'EventEspresso\core\services\request\Response'
279
-        );
280
-        $this->_set_cached_class(
281
-            $response_loader(),
282
-            'EventEspresso\core\services\request\Response'
283
-        );
284
-        add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
285
-    }
286
-
287
-
288
-    /**
289
-     * @return void
290
-     */
291
-    public function init()
292
-    {
293
-        // Get current page protocol
294
-        $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
295
-        // Output admin-ajax.php URL with same protocol as current page
296
-        self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
297
-        self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
298
-    }
299
-
300
-
301
-    /**
302
-     * localize_i18n_js_strings
303
-     *
304
-     * @return string
305
-     */
306
-    public static function localize_i18n_js_strings()
307
-    {
308
-        $i18n_js_strings = (array) self::$i18n_js_strings;
309
-        foreach ($i18n_js_strings as $key => $value) {
310
-            if (is_scalar($value)) {
311
-                $i18n_js_strings[ $key ] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
312
-            }
313
-        }
314
-        return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
315
-    }
316
-
317
-
318
-    /**
319
-     * @param mixed string | EED_Module $module
320
-     * @throws OutOfBoundsException
321
-     * @throws InvalidArgumentException
322
-     * @throws InvalidInterfaceException
323
-     * @throws InvalidDataTypeException
324
-     * @throws EE_Error
325
-     * @throws ReflectionException
326
-     */
327
-    public function add_module($module)
328
-    {
329
-        if ($module instanceof EED_Module) {
330
-            $module_class = get_class($module);
331
-            $this->modules->{$module_class} = $module;
332
-        } else {
333
-            if (! class_exists('EE_Module_Request_Router', false)) {
334
-                $this->load_core('Module_Request_Router');
335
-            }
336
-            EE_Module_Request_Router::module_factory($module);
337
-        }
338
-    }
339
-
340
-
341
-    /**
342
-     * @param string $module_name
343
-     * @return mixed EED_Module | NULL
344
-     */
345
-    public function get_module($module_name = '')
346
-    {
347
-        return isset($this->modules->{$module_name})
348
-            ? $this->modules->{$module_name}
349
-            : null;
350
-    }
351
-
352
-
353
-    /**
354
-     * loads core classes - must be singletons
355
-     *
356
-     * @param string $class_name - simple class name ie: session
357
-     * @param mixed  $arguments
358
-     * @param bool   $load_only
359
-     * @return mixed
360
-     * @throws InvalidInterfaceException
361
-     * @throws InvalidDataTypeException
362
-     * @throws EE_Error
363
-     * @throws ReflectionException
364
-     * @throws InvalidArgumentException
365
-     */
366
-    public function load_core($class_name, $arguments = array(), $load_only = false)
367
-    {
368
-        $core_paths = apply_filters(
369
-            'FHEE__EE_Registry__load_core__core_paths',
370
-            array(
371
-                EE_CORE,
372
-                EE_ADMIN,
373
-                EE_CPTS,
374
-                EE_CORE . 'data_migration_scripts' . DS,
375
-                EE_CORE . 'capabilities' . DS,
376
-                EE_CORE . 'request_stack' . DS,
377
-                EE_CORE . 'middleware' . DS,
378
-            )
379
-        );
380
-        // retrieve instantiated class
381
-        return $this->_load(
382
-            $core_paths,
383
-            'EE_',
384
-            $class_name,
385
-            'core',
386
-            $arguments,
387
-            false,
388
-            true,
389
-            $load_only
390
-        );
391
-    }
392
-
393
-
394
-    /**
395
-     * loads service classes
396
-     *
397
-     * @param string $class_name - simple class name ie: session
398
-     * @param mixed  $arguments
399
-     * @param bool   $load_only
400
-     * @return mixed
401
-     * @throws InvalidInterfaceException
402
-     * @throws InvalidDataTypeException
403
-     * @throws EE_Error
404
-     * @throws ReflectionException
405
-     * @throws InvalidArgumentException
406
-     */
407
-    public function load_service($class_name, $arguments = array(), $load_only = false)
408
-    {
409
-        $service_paths = apply_filters(
410
-            'FHEE__EE_Registry__load_service__service_paths',
411
-            array(
412
-                EE_CORE . 'services' . DS,
413
-            )
414
-        );
415
-        // retrieve instantiated class
416
-        return $this->_load(
417
-            $service_paths,
418
-            'EE_',
419
-            $class_name,
420
-            'class',
421
-            $arguments,
422
-            false,
423
-            true,
424
-            $load_only
425
-        );
426
-    }
427
-
428
-
429
-    /**
430
-     * loads data_migration_scripts
431
-     *
432
-     * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
433
-     * @param mixed  $arguments
434
-     * @return EE_Data_Migration_Script_Base|mixed
435
-     * @throws InvalidInterfaceException
436
-     * @throws InvalidDataTypeException
437
-     * @throws EE_Error
438
-     * @throws ReflectionException
439
-     * @throws InvalidArgumentException
440
-     */
441
-    public function load_dms($class_name, $arguments = array())
442
-    {
443
-        // retrieve instantiated class
444
-        return $this->_load(
445
-            EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(),
446
-            'EE_DMS_',
447
-            $class_name,
448
-            'dms',
449
-            $arguments,
450
-            false,
451
-            false
452
-        );
453
-    }
454
-
455
-
456
-    /**
457
-     * loads object creating classes - must be singletons
458
-     *
459
-     * @param string $class_name - simple class name ie: attendee
460
-     * @param mixed  $arguments  - an array of arguments to pass to the class
461
-     * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to
462
-     *                           instantiate
463
-     * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then
464
-     *                           set this to FALSE (ie. when instantiating model objects from client in a loop)
465
-     * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate
466
-     *                           (default)
467
-     * @return EE_Base_Class | bool
468
-     * @throws InvalidInterfaceException
469
-     * @throws InvalidDataTypeException
470
-     * @throws EE_Error
471
-     * @throws ReflectionException
472
-     * @throws InvalidArgumentException
473
-     */
474
-    public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
475
-    {
476
-        $paths = apply_filters(
477
-            'FHEE__EE_Registry__load_class__paths',
478
-            array(
479
-                EE_CORE,
480
-                EE_CLASSES,
481
-                EE_BUSINESS,
482
-            )
483
-        );
484
-        // retrieve instantiated class
485
-        return $this->_load(
486
-            $paths,
487
-            'EE_',
488
-            $class_name,
489
-            'class',
490
-            $arguments,
491
-            $from_db,
492
-            $cache,
493
-            $load_only
494
-        );
495
-    }
496
-
497
-
498
-    /**
499
-     * loads helper classes - must be singletons
500
-     *
501
-     * @param string $class_name - simple class name ie: price
502
-     * @param mixed  $arguments
503
-     * @param bool   $load_only
504
-     * @return EEH_Base | bool
505
-     * @throws InvalidInterfaceException
506
-     * @throws InvalidDataTypeException
507
-     * @throws EE_Error
508
-     * @throws ReflectionException
509
-     * @throws InvalidArgumentException
510
-     */
511
-    public function load_helper($class_name, $arguments = array(), $load_only = true)
512
-    {
513
-        // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
514
-        $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
515
-        // retrieve instantiated class
516
-        return $this->_load(
517
-            $helper_paths,
518
-            'EEH_',
519
-            $class_name,
520
-            'helper',
521
-            $arguments,
522
-            false,
523
-            true,
524
-            $load_only
525
-        );
526
-    }
527
-
528
-
529
-    /**
530
-     * loads core classes - must be singletons
531
-     *
532
-     * @param string $class_name - simple class name ie: session
533
-     * @param mixed  $arguments
534
-     * @param bool   $load_only
535
-     * @param bool   $cache      whether to cache the object or not.
536
-     * @return mixed
537
-     * @throws InvalidInterfaceException
538
-     * @throws InvalidDataTypeException
539
-     * @throws EE_Error
540
-     * @throws ReflectionException
541
-     * @throws InvalidArgumentException
542
-     */
543
-    public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
544
-    {
545
-        $paths = array(
546
-            EE_LIBRARIES,
547
-            EE_LIBRARIES . 'messages' . DS,
548
-            EE_LIBRARIES . 'shortcodes' . DS,
549
-            EE_LIBRARIES . 'qtips' . DS,
550
-            EE_LIBRARIES . 'payment_methods' . DS,
551
-        );
552
-        // retrieve instantiated class
553
-        return $this->_load(
554
-            $paths,
555
-            'EE_',
556
-            $class_name,
557
-            'lib',
558
-            $arguments,
559
-            false,
560
-            $cache,
561
-            $load_only
562
-        );
563
-    }
564
-
565
-
566
-    /**
567
-     * loads model classes - must be singletons
568
-     *
569
-     * @param string $class_name - simple class name ie: price
570
-     * @param mixed  $arguments
571
-     * @param bool   $load_only
572
-     * @return EEM_Base | bool
573
-     * @throws InvalidInterfaceException
574
-     * @throws InvalidDataTypeException
575
-     * @throws EE_Error
576
-     * @throws ReflectionException
577
-     * @throws InvalidArgumentException
578
-     */
579
-    public function load_model($class_name, $arguments = array(), $load_only = false)
580
-    {
581
-        $paths = apply_filters(
582
-            'FHEE__EE_Registry__load_model__paths',
583
-            array(
584
-                EE_MODELS,
585
-                EE_CORE,
586
-            )
587
-        );
588
-        // retrieve instantiated class
589
-        return $this->_load(
590
-            $paths,
591
-            'EEM_',
592
-            $class_name,
593
-            'model',
594
-            $arguments,
595
-            false,
596
-            true,
597
-            $load_only
598
-        );
599
-    }
600
-
601
-
602
-    /**
603
-     * loads model classes - must be singletons
604
-     *
605
-     * @param string $class_name - simple class name ie: price
606
-     * @param mixed  $arguments
607
-     * @param bool   $load_only
608
-     * @return mixed | bool
609
-     * @throws InvalidInterfaceException
610
-     * @throws InvalidDataTypeException
611
-     * @throws EE_Error
612
-     * @throws ReflectionException
613
-     * @throws InvalidArgumentException
614
-     */
615
-    public function load_model_class($class_name, $arguments = array(), $load_only = true)
616
-    {
617
-        $paths = array(
618
-            EE_MODELS . 'fields' . DS,
619
-            EE_MODELS . 'helpers' . DS,
620
-            EE_MODELS . 'relations' . DS,
621
-            EE_MODELS . 'strategies' . DS,
622
-        );
623
-        // retrieve instantiated class
624
-        return $this->_load(
625
-            $paths,
626
-            'EE_',
627
-            $class_name,
628
-            '',
629
-            $arguments,
630
-            false,
631
-            true,
632
-            $load_only
633
-        );
634
-    }
635
-
636
-
637
-    /**
638
-     * Determines if $model_name is the name of an actual EE model.
639
-     *
640
-     * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
641
-     * @return boolean
642
-     */
643
-    public function is_model_name($model_name)
644
-    {
645
-        return isset($this->models[ $model_name ]);
646
-    }
647
-
648
-
649
-    /**
650
-     * generic class loader
651
-     *
652
-     * @param string $path_to_file - directory path to file location, not including filename
653
-     * @param string $file_name    - file name  ie:  my_file.php, including extension
654
-     * @param string $type         - file type - core? class? helper? model?
655
-     * @param mixed  $arguments
656
-     * @param bool   $load_only
657
-     * @return mixed
658
-     * @throws InvalidInterfaceException
659
-     * @throws InvalidDataTypeException
660
-     * @throws EE_Error
661
-     * @throws ReflectionException
662
-     * @throws InvalidArgumentException
663
-     */
664
-    public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
665
-    {
666
-        // retrieve instantiated class
667
-        return $this->_load(
668
-            $path_to_file,
669
-            '',
670
-            $file_name,
671
-            $type,
672
-            $arguments,
673
-            false,
674
-            true,
675
-            $load_only
676
-        );
677
-    }
678
-
679
-
680
-    /**
681
-     * @param string $path_to_file - directory path to file location, not including filename
682
-     * @param string $class_name   - full class name  ie:  My_Class
683
-     * @param string $type         - file type - core? class? helper? model?
684
-     * @param mixed  $arguments
685
-     * @param bool   $load_only
686
-     * @return bool|EE_Addon|object
687
-     * @throws InvalidInterfaceException
688
-     * @throws InvalidDataTypeException
689
-     * @throws EE_Error
690
-     * @throws ReflectionException
691
-     * @throws InvalidArgumentException
692
-     */
693
-    public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
694
-    {
695
-        // retrieve instantiated class
696
-        return $this->_load(
697
-            $path_to_file,
698
-            'addon',
699
-            $class_name,
700
-            $type,
701
-            $arguments,
702
-            false,
703
-            true,
704
-            $load_only
705
-        );
706
-    }
707
-
708
-
709
-    /**
710
-     * instantiates, caches, and automatically resolves dependencies
711
-     * for classes that use a Fully Qualified Class Name.
712
-     * if the class is not capable of being loaded using PSR-4 autoloading,
713
-     * then you need to use one of the existing load_*() methods
714
-     * which can resolve the classname and filepath from the passed arguments
715
-     *
716
-     * @param bool|string $class_name   Fully Qualified Class Name
717
-     * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
718
-     * @param bool        $cache        whether to cache the instantiated object for reuse
719
-     * @param bool        $from_db      some classes are instantiated from the db
720
-     *                                  and thus call a different method to instantiate
721
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
722
-     * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
723
-     * @return bool|null|mixed          null = failure to load or instantiate class object.
724
-     *                                  object = class loaded and instantiated successfully.
725
-     *                                  bool = fail or success when $load_only is true
726
-     * @throws InvalidInterfaceException
727
-     * @throws InvalidDataTypeException
728
-     * @throws EE_Error
729
-     * @throws ReflectionException
730
-     * @throws InvalidArgumentException
731
-     */
732
-    public function create(
733
-        $class_name = false,
734
-        $arguments = array(),
735
-        $cache = false,
736
-        $from_db = false,
737
-        $load_only = false,
738
-        $addon = false
739
-    ) {
740
-        $class_name = ltrim($class_name, '\\');
741
-        $class_name = $this->class_cache->getFqnForAlias($class_name);
742
-        $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
743
-        // if a non-FQCN was passed, then
744
-        // verifyClassExists() might return an object
745
-        // or it could return null if the class just could not be found anywhere
746
-        if ($class_exists instanceof $class_name || $class_exists === null) {
747
-            // either way, return the results
748
-            return $class_exists;
749
-        }
750
-        $class_name = $class_exists;
751
-        // if we're only loading the class and it already exists, then let's just return true immediately
752
-        if ($load_only) {
753
-            return true;
754
-        }
755
-        $addon = $addon ? 'addon' : '';
756
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
757
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
758
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
759
-        if ($this->_cache_on && $cache && ! $load_only) {
760
-            // return object if it's already cached
761
-            $cached_class = $this->_get_cached_class($class_name, $addon, $arguments);
762
-            if ($cached_class !== null) {
763
-                return $cached_class;
764
-            }
765
-        }// obtain the loader method from the dependency map
766
-        $loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object
767
-        if ($loader instanceof Closure) {
768
-            $class_obj = $loader($arguments);
769
-        } else {
770
-            if ($loader && method_exists($this, $loader)) {
771
-                $class_obj = $this->{$loader}($class_name, $arguments);
772
-            } else {
773
-                $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
774
-            }
775
-        }
776
-        if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) {
777
-            // save it for later... kinda like gum  { : $
778
-            $this->_set_cached_class(
779
-                $class_obj,
780
-                $class_name,
781
-                $addon,
782
-                $from_db,
783
-                $arguments
784
-            );
785
-        }
786
-        $this->_cache_on = true;
787
-        return $class_obj;
788
-    }
789
-
790
-
791
-    /**
792
-     * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
793
-     *
794
-     * @param string|object $class_name
795
-     * @param array         $arguments
796
-     * @param int           $attempt
797
-     * @return mixed
798
-     */
799
-    private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1)
800
-    {
801
-        if (is_object($class_name) || class_exists($class_name)) {
802
-            return $class_name;
803
-        }
804
-        switch ($attempt) {
805
-            case 1:
806
-                // if it's a FQCN then maybe the class is registered with a preceding \
807
-                $class_name = strpos($class_name, '\\') !== false
808
-                    ? '\\' . ltrim($class_name, '\\')
809
-                    : $class_name;
810
-                break;
811
-            case 2:
812
-                //
813
-                $loader = $this->_dependency_map->class_loader($class_name);
814
-                if ($loader && method_exists($this, $loader)) {
815
-                    return $this->{$loader}($class_name, $arguments);
816
-                }
817
-                break;
818
-            case 3:
819
-            default:
820
-                return null;
821
-        }
822
-        $attempt++;
823
-        return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt);
824
-    }
825
-
826
-
827
-    /**
828
-     * instantiates, caches, and injects dependencies for classes
829
-     *
830
-     * @param array       $file_paths   an array of paths to folders to look in
831
-     * @param string      $class_prefix EE  or EEM or... ???
832
-     * @param bool|string $class_name   $class name
833
-     * @param string      $type         file type - core? class? helper? model?
834
-     * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
835
-     * @param bool        $from_db      some classes are instantiated from the db
836
-     *                                  and thus call a different method to instantiate
837
-     * @param bool        $cache        whether to cache the instantiated object for reuse
838
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
839
-     * @return bool|null|object null = failure to load or instantiate class object.
840
-     *                                  object = class loaded and instantiated successfully.
841
-     *                                  bool = fail or success when $load_only is true
842
-     * @throws EE_Error
843
-     * @throws ReflectionException
844
-     * @throws InvalidInterfaceException
845
-     * @throws InvalidDataTypeException
846
-     * @throws InvalidArgumentException
847
-     */
848
-    protected function _load(
849
-        $file_paths = array(),
850
-        $class_prefix = 'EE_',
851
-        $class_name = false,
852
-        $type = 'class',
853
-        $arguments = array(),
854
-        $from_db = false,
855
-        $cache = true,
856
-        $load_only = false
857
-    ) {
858
-        $class_name = ltrim($class_name, '\\');
859
-        // strip php file extension
860
-        $class_name = str_replace('.php', '', trim($class_name));
861
-        // does the class have a prefix ?
862
-        if (! empty($class_prefix) && $class_prefix !== 'addon') {
863
-            // make sure $class_prefix is uppercase
864
-            $class_prefix = strtoupper(trim($class_prefix));
865
-            // add class prefix ONCE!!!
866
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
867
-        }
868
-        $class_name = $this->class_cache->getFqnForAlias($class_name);
869
-        $class_exists = class_exists($class_name, false);
870
-        // if we're only loading the class and it already exists, then let's just return true immediately
871
-        if ($load_only && $class_exists) {
872
-            return true;
873
-        }
874
-        $arguments = is_array($arguments) ? $arguments : array($arguments);
875
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
876
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
877
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
878
-        if ($this->_cache_on && $cache && ! $load_only) {
879
-            // return object if it's already cached
880
-            $cached_class = $this->_get_cached_class($class_name, $class_prefix, $arguments);
881
-            if ($cached_class !== null) {
882
-                return $cached_class;
883
-            }
884
-        }
885
-        // if the class doesn't already exist.. then we need to try and find the file and load it
886
-        if (! $class_exists) {
887
-            // get full path to file
888
-            $path = $this->_resolve_path($class_name, $type, $file_paths);
889
-            // load the file
890
-            $loaded = $this->_require_file($path, $class_name, $type, $file_paths);
891
-            // if we are only loading a file but NOT instantiating an object
892
-            // then return boolean for whether class was loaded or not
893
-            if ($load_only) {
894
-                return $loaded;
895
-            }
896
-            // if an object was expected but loading failed, then return nothing
897
-            if (! $loaded) {
898
-                return null;
899
-            }
900
-        }
901
-        // instantiate the requested object
902
-        $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
903
-        if ($this->_cache_on && $cache) {
904
-            // save it for later... kinda like gum  { : $
905
-            $this->_set_cached_class(
906
-                $class_obj,
907
-                $class_name,
908
-                $class_prefix,
909
-                $from_db,
910
-                $arguments
911
-            );
912
-        }
913
-        $this->_cache_on = true;
914
-        return $class_obj;
915
-    }
916
-
917
-
918
-    /**
919
-     * @param string $class_name
920
-     * @param string $default have to specify something, but not anything that will conflict
921
-     * @return mixed|string
922
-     */
923
-    protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS')
924
-    {
925
-        return isset($this->_class_abbreviations[ $class_name ])
926
-            ? $this->_class_abbreviations[ $class_name ]
927
-            : $default;
928
-    }
929
-
930
-
931
-    /**
932
-     * attempts to find a cached version of the requested class
933
-     * by looking in the following places:
934
-     *        $this->{$class_abbreviation}            ie:    $this->CART
935
-     *        $this->{$class_name}                        ie:    $this->Some_Class
936
-     *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
937
-     *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
938
-     *
939
-     * @param string $class_name
940
-     * @param string $class_prefix
941
-     * @param array  $arguments
942
-     * @return mixed
943
-     */
944
-    protected function _get_cached_class(
945
-        $class_name,
946
-        $class_prefix = '',
947
-        $arguments = array()
948
-    ) {
949
-        if ($class_name === 'EE_Registry') {
950
-            return $this;
951
-        }
952
-        $class_abbreviation = $this->get_class_abbreviation($class_name);
953
-        // check if class has already been loaded, and return it if it has been
954
-        if (isset($this->{$class_abbreviation})) {
955
-            return $this->{$class_abbreviation};
956
-        }
957
-        $class_name = str_replace('\\', '_', $class_name);
958
-        if (isset($this->{$class_name})) {
959
-            return $this->{$class_name};
960
-        }
961
-        if ($class_prefix === 'addon' && isset($this->addons->{$class_name})) {
962
-            return $this->addons->{$class_name};
963
-        }
964
-        $object_identifier = $this->object_identifier->getIdentifier($class_name, $arguments);
965
-        if (isset($this->LIB->{$object_identifier})) {
966
-            return $this->LIB->{$object_identifier};
967
-        }
968
-        foreach ($this->LIB as $key => $object) {
969
-            if (// request does not contain new arguments and therefore no args identifier
970
-                ! $this->object_identifier->hasArguments($object_identifier)
971
-                // but previously cached class with args was found
972
-                && $this->object_identifier->fqcnMatchesObjectIdentifier($class_name, $key)
973
-            ) {
974
-                return $object;
975
-            }
976
-        }
977
-        return null;
978
-    }
979
-
980
-
981
-    /**
982
-     * removes a cached version of the requested class
983
-     *
984
-     * @param string  $class_name
985
-     * @param boolean $addon
986
-     * @param array   $arguments
987
-     * @return boolean
988
-     */
989
-    public function clear_cached_class(
990
-        $class_name,
991
-        $addon = false,
992
-        $arguments = array()
993
-    ) {
994
-        $class_abbreviation = $this->get_class_abbreviation($class_name);
995
-        // check if class has already been loaded, and return it if it has been
996
-        if (isset($this->{$class_abbreviation})) {
997
-            $this->{$class_abbreviation} = null;
998
-            return true;
999
-        }
1000
-        $class_name = str_replace('\\', '_', $class_name);
1001
-        if (isset($this->{$class_name})) {
1002
-            $this->{$class_name} = null;
1003
-            return true;
1004
-        }
1005
-        if ($addon && isset($this->addons->{$class_name})) {
1006
-            unset($this->addons->{$class_name});
1007
-            return true;
1008
-        }
1009
-        $class_name = $this->object_identifier->getIdentifier($class_name, $arguments);
1010
-        if (isset($this->LIB->{$class_name})) {
1011
-            unset($this->LIB->{$class_name});
1012
-            return true;
1013
-        }
1014
-        return false;
1015
-    }
1016
-
1017
-
1018
-    /**
1019
-     * _set_cached_class
1020
-     * attempts to cache the instantiated class locally
1021
-     * in one of the following places, in the following order:
1022
-     *        $this->{class_abbreviation}   ie:    $this->CART
1023
-     *        $this->{$class_name}          ie:    $this->Some_Class
1024
-     *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1025
-     *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1026
-     *
1027
-     * @param object $class_obj
1028
-     * @param string $class_name
1029
-     * @param string $class_prefix
1030
-     * @param bool   $from_db
1031
-     * @param array  $arguments
1032
-     * @return void
1033
-     */
1034
-    protected function _set_cached_class(
1035
-        $class_obj,
1036
-        $class_name,
1037
-        $class_prefix = '',
1038
-        $from_db = false,
1039
-        $arguments = array()
1040
-    ) {
1041
-        if ($class_name === 'EE_Registry' || empty($class_obj)) {
1042
-            return;
1043
-        }
1044
-        // return newly instantiated class
1045
-        $class_abbreviation = $this->get_class_abbreviation($class_name, '');
1046
-        if ($class_abbreviation) {
1047
-            $this->{$class_abbreviation} = $class_obj;
1048
-            return;
1049
-        }
1050
-        $class_name = str_replace('\\', '_', $class_name);
1051
-        if (property_exists($this, $class_name)) {
1052
-            $this->{$class_name} = $class_obj;
1053
-            return;
1054
-        }
1055
-        if ($class_prefix === 'addon') {
1056
-            $this->addons->{$class_name} = $class_obj;
1057
-            return;
1058
-        }
1059
-        if (! $from_db) {
1060
-            $class_name = $this->object_identifier->getIdentifier($class_name, $arguments);
1061
-            $this->LIB->{$class_name} = $class_obj;
1062
-        }
1063
-    }
1064
-
1065
-
1066
-    /**
1067
-     * attempts to find a full valid filepath for the requested class.
1068
-     * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
1069
-     * then returns that path if the target file has been found and is readable
1070
-     *
1071
-     * @param string $class_name
1072
-     * @param string $type
1073
-     * @param array  $file_paths
1074
-     * @return string | bool
1075
-     */
1076
-    protected function _resolve_path($class_name, $type = '', $file_paths = array())
1077
-    {
1078
-        // make sure $file_paths is an array
1079
-        $file_paths = is_array($file_paths)
1080
-            ? $file_paths
1081
-            : array($file_paths);
1082
-        // cycle thru paths
1083
-        foreach ($file_paths as $key => $file_path) {
1084
-            // convert all separators to proper DS, if no filepath, then use EE_CLASSES
1085
-            $file_path = $file_path
1086
-                ? str_replace(array('/', '\\'), DS, $file_path)
1087
-                : EE_CLASSES;
1088
-            // prep file type
1089
-            $type = ! empty($type)
1090
-                ? trim($type, '.') . '.'
1091
-                : '';
1092
-            // build full file path
1093
-            $file_paths[ $key ] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
1094
-            // does the file exist and can be read ?
1095
-            if (is_readable($file_paths[ $key ])) {
1096
-                return $file_paths[ $key ];
1097
-            }
1098
-        }
1099
-        return false;
1100
-    }
1101
-
1102
-
1103
-    /**
1104
-     * basically just performs a require_once()
1105
-     * but with some error handling
1106
-     *
1107
-     * @param  string $path
1108
-     * @param  string $class_name
1109
-     * @param  string $type
1110
-     * @param  array  $file_paths
1111
-     * @return bool
1112
-     * @throws EE_Error
1113
-     * @throws ReflectionException
1114
-     */
1115
-    protected function _require_file($path, $class_name, $type = '', $file_paths = array())
1116
-    {
1117
-        $this->resolve_legacy_class_parent($class_name);
1118
-        // don't give up! you gotta...
1119
-        try {
1120
-            // does the file exist and can it be read ?
1121
-            if (! $path) {
1122
-                // just in case the file has already been autoloaded,
1123
-                // but discrepancies in the naming schema are preventing it from
1124
-                // being loaded via one of the EE_Registry::load_*() methods,
1125
-                // then let's try one last hail mary before throwing an exception
1126
-                // and call class_exists() again, but with autoloading turned ON
1127
-                if (class_exists($class_name)) {
1128
-                    return true;
1129
-                }
1130
-                // so sorry, can't find the file
1131
-                throw new EE_Error(
1132
-                    sprintf(
1133
-                        esc_html__(
1134
-                            'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s',
1135
-                            'event_espresso'
1136
-                        ),
1137
-                        trim($type, '.'),
1138
-                        $class_name,
1139
-                        '<br />' . implode(',<br />', $file_paths)
1140
-                    )
1141
-                );
1142
-            }
1143
-            // get the file
1144
-            require_once($path);
1145
-            // if the class isn't already declared somewhere
1146
-            if (class_exists($class_name, false) === false) {
1147
-                // so sorry, not a class
1148
-                throw new EE_Error(
1149
-                    sprintf(
1150
-                        esc_html__(
1151
-                            'The %s file %s does not appear to contain the %s Class.',
1152
-                            'event_espresso'
1153
-                        ),
1154
-                        $type,
1155
-                        $path,
1156
-                        $class_name
1157
-                    )
1158
-                );
1159
-            }
1160
-        } catch (EE_Error $e) {
1161
-            $e->get_error();
1162
-            return false;
1163
-        }
1164
-        return true;
1165
-    }
1166
-
1167
-
1168
-    /**
1169
-     * Some of our legacy classes that extended a parent class would simply use a require() statement
1170
-     * before their class declaration in order to ensure that the parent class was loaded.
1171
-     * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class,
1172
-     * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist.
1173
-     *
1174
-     * @param string $class_name
1175
-     */
1176
-    protected function resolve_legacy_class_parent($class_name = '')
1177
-    {
1178
-        try {
1179
-            $legacy_parent_class_map = array(
1180
-                'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php',
1181
-            );
1182
-            if (isset($legacy_parent_class_map[ $class_name ])) {
1183
-                require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ];
1184
-            }
1185
-        } catch (Exception $exception) {
1186
-        }
1187
-    }
1188
-
1189
-
1190
-    /**
1191
-     * _create_object
1192
-     * Attempts to instantiate the requested class via any of the
1193
-     * commonly used instantiation methods employed throughout EE.
1194
-     * The priority for instantiation is as follows:
1195
-     *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
1196
-     *        - model objects via their 'new_instance_from_db' method
1197
-     *        - model objects via their 'new_instance' method
1198
-     *        - "singleton" classes" via their 'instance' method
1199
-     *    - standard instantiable classes via their __constructor
1200
-     * Prior to instantiation, if the classname exists in the dependency_map,
1201
-     * then the constructor for the requested class will be examined to determine
1202
-     * if any dependencies exist, and if they can be injected.
1203
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1204
-     *
1205
-     * @param string $class_name
1206
-     * @param array  $arguments
1207
-     * @param string $type
1208
-     * @param bool   $from_db
1209
-     * @return null|object|bool
1210
-     * @throws InvalidArgumentException
1211
-     * @throws InvalidInterfaceException
1212
-     * @throws EE_Error
1213
-     * @throws ReflectionException
1214
-     * @throws InvalidDataTypeException
1215
-     */
1216
-    protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
1217
-    {
1218
-        // create reflection
1219
-        $reflector = $this->mirror->getReflectionClass($class_name);
1220
-        // make sure arguments are an array
1221
-        $arguments = is_array($arguments)
1222
-            ? $arguments
1223
-            : array($arguments);
1224
-        // and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
1225
-        // else wrap it in an additional array so that it doesn't get split into multiple parameters
1226
-        $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
1227
-            ? $arguments
1228
-            : array($arguments);
1229
-        // attempt to inject dependencies ?
1230
-        if ($this->_dependency_map->has($class_name)) {
1231
-            $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
1232
-        }
1233
-        // instantiate the class if possible
1234
-        if ($reflector->isAbstract()) {
1235
-            // nothing to instantiate, loading file was enough
1236
-            // does not throw an exception so $instantiation_mode is unused
1237
-            // $instantiation_mode = "1) no constructor abstract class";
1238
-            return true;
1239
-        }
1240
-        if (empty($arguments)
1241
-            && $this->mirror->getConstructorFromReflection($reflector) === null
1242
-            && $reflector->isInstantiable()
1243
-        ) {
1244
-            // no constructor = static methods only... nothing to instantiate, loading file was enough
1245
-            // $instantiation_mode = "2) no constructor but instantiable";
1246
-            return $reflector->newInstance();
1247
-        }
1248
-        if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
1249
-            // $instantiation_mode = "3) new_instance_from_db()";
1250
-            return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
1251
-        }
1252
-        if (method_exists($class_name, 'new_instance')) {
1253
-            // $instantiation_mode = "4) new_instance()";
1254
-            return call_user_func_array(array($class_name, 'new_instance'), $arguments);
1255
-        }
1256
-        if (method_exists($class_name, 'instance')) {
1257
-            // $instantiation_mode = "5) instance()";
1258
-            return call_user_func_array(array($class_name, 'instance'), $arguments);
1259
-        }
1260
-        if ($reflector->isInstantiable()) {
1261
-            // $instantiation_mode = "6) constructor";
1262
-            return $reflector->newInstanceArgs($arguments);
1263
-        }
1264
-        // heh ? something's not right !
1265
-        throw new EE_Error(
1266
-            sprintf(
1267
-                __('The %s file %s could not be instantiated.', 'event_espresso'),
1268
-                $type,
1269
-                $class_name
1270
-            )
1271
-        );
1272
-    }
1273
-
1274
-
1275
-    /**
1276
-     * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1277
-     * @param array $array
1278
-     * @return bool
1279
-     */
1280
-    protected function _array_is_numerically_and_sequentially_indexed(array $array)
1281
-    {
1282
-        return ! empty($array)
1283
-            ? array_keys($array) === range(0, count($array) - 1)
1284
-            : true;
1285
-    }
1286
-
1287
-
1288
-    /**
1289
-     * _resolve_dependencies
1290
-     * examines the constructor for the requested class to determine
1291
-     * if any dependencies exist, and if they can be injected.
1292
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1293
-     * PLZ NOTE: this is achieved by type hinting the constructor params
1294
-     * For example:
1295
-     *        if attempting to load a class "Foo" with the following constructor:
1296
-     *        __construct( Bar $bar_class, Fighter $grohl_class )
1297
-     *        then $bar_class and $grohl_class will be added to the $arguments array,
1298
-     *        but only IF they are NOT already present in the incoming arguments array,
1299
-     *        and the correct classes can be loaded
1300
-     *
1301
-     * @param ReflectionClass $reflector
1302
-     * @param string          $class_name
1303
-     * @param array           $arguments
1304
-     * @return array
1305
-     * @throws InvalidArgumentException
1306
-     * @throws InvalidDataTypeException
1307
-     * @throws InvalidInterfaceException
1308
-     * @throws ReflectionException
1309
-     */
1310
-    protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, array $arguments = array())
1311
-    {
1312
-        // let's examine the constructor
1313
-        $constructor = $this->mirror->getConstructorFromReflection($reflector);
1314
-        // whu? huh? nothing?
1315
-        if (! $constructor) {
1316
-            return $arguments;
1317
-        }
1318
-        // get constructor parameters
1319
-        $params = $this->mirror->getParametersFromReflection($reflector);
1320
-        // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1321
-        $argument_keys = array_keys($arguments);
1322
-        // now loop thru all of the constructors expected parameters
1323
-        foreach ($params as $index => $param) {
1324
-            // is this a dependency for a specific class ?
1325
-            $param_class = $this->mirror->getParameterClassName($param, $class_name, $index);
1326
-            // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1327
-            $param_class = $this->class_cache->isAlias($param_class, $class_name)
1328
-                ? $this->class_cache->getFqnForAlias($param_class, $class_name)
1329
-                : $param_class;
1330
-            if (// param is not even a class
1331
-                $param_class === null
1332
-                // and something already exists in the incoming arguments for this param
1333
-                && array_key_exists($index, $argument_keys)
1334
-                && array_key_exists($argument_keys[ $index ], $arguments)
1335
-            ) {
1336
-                // so let's skip this argument and move on to the next
1337
-                continue;
1338
-            }
1339
-            if (// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1340
-                $param_class !== null
1341
-                && isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ])
1342
-                && $arguments[ $argument_keys[ $index ] ] instanceof $param_class
1343
-            ) {
1344
-                // skip this argument and move on to the next
1345
-                continue;
1346
-            }
1347
-            if (// parameter is type hinted as a class, and should be injected
1348
-                $param_class !== null
1349
-                && $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1350
-            ) {
1351
-                $arguments = $this->_resolve_dependency(
1352
-                    $class_name,
1353
-                    $param_class,
1354
-                    $arguments,
1355
-                    $index
1356
-                );
1357
-            }
1358
-            if (empty($arguments[ $index ])) {
1359
-                $arguments[ $index ] = $this->mirror->getParameterDefaultValue(
1360
-                    $param,
1361
-                    $class_name,
1362
-                    $index
1363
-                );
1364
-            }
1365
-        }
1366
-        return $arguments;
1367
-    }
1368
-
1369
-
1370
-    /**
1371
-     * @param string $class_name
1372
-     * @param string $param_class
1373
-     * @param array  $arguments
1374
-     * @param mixed  $index
1375
-     * @return array
1376
-     * @throws InvalidArgumentException
1377
-     * @throws InvalidInterfaceException
1378
-     * @throws InvalidDataTypeException
1379
-     */
1380
-    protected function _resolve_dependency($class_name, $param_class, $arguments, $index)
1381
-    {
1382
-        $dependency = null;
1383
-        // should dependency be loaded from cache ?
1384
-        $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency(
1385
-            $class_name,
1386
-            $param_class
1387
-        );
1388
-        $cache_on = $cache_on !== EE_Dependency_Map::load_new_object;
1389
-        // we might have a dependency...
1390
-        // let's MAYBE try and find it in our cache if that's what's been requested
1391
-        $cached_class = $cache_on
1392
-            ? $this->_get_cached_class($param_class)
1393
-            : null;
1394
-        // and grab it if it exists
1395
-        if ($cached_class instanceof $param_class) {
1396
-            $dependency = $cached_class;
1397
-        } elseif ($param_class !== $class_name) {
1398
-            // obtain the loader method from the dependency map
1399
-            $loader = $this->_dependency_map->class_loader($param_class);
1400
-            // is loader a custom closure ?
1401
-            if ($loader instanceof Closure) {
1402
-                $dependency = $loader($arguments);
1403
-            } else {
1404
-                // set the cache on property for the recursive loading call
1405
-                $this->_cache_on = $cache_on;
1406
-                // if not, then let's try and load it via the registry
1407
-                if ($loader && method_exists($this, $loader)) {
1408
-                    $dependency = $this->{$loader}($param_class);
1409
-                } else {
1410
-                    $dependency = LoaderFactory::getLoader()->load(
1411
-                        $param_class,
1412
-                        array(),
1413
-                        $cache_on
1414
-                    );
1415
-                }
1416
-            }
1417
-        }
1418
-        // did we successfully find the correct dependency ?
1419
-        if ($dependency instanceof $param_class) {
1420
-            // then let's inject it into the incoming array of arguments at the correct location
1421
-            $arguments[ $index ] = $dependency;
1422
-        }
1423
-        return $arguments;
1424
-    }
1425
-
1426
-
1427
-    /**
1428
-     * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1429
-     *
1430
-     * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1431
-     *                          in the EE_Dependency_Map::$_class_loaders array,
1432
-     *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1433
-     * @param array  $arguments
1434
-     * @return object
1435
-     */
1436
-    public static function factory($classname, $arguments = array())
1437
-    {
1438
-        $loader = self::instance()->_dependency_map->class_loader($classname);
1439
-        if ($loader instanceof Closure) {
1440
-            return $loader($arguments);
1441
-        }
1442
-        if (method_exists(self::instance(), $loader)) {
1443
-            return self::instance()->{$loader}($classname, $arguments);
1444
-        }
1445
-        return null;
1446
-    }
1447
-
1448
-
1449
-    /**
1450
-     * Gets the addon by its class name
1451
-     *
1452
-     * @param string $class_name
1453
-     * @return EE_Addon
1454
-     */
1455
-    public function getAddon($class_name)
1456
-    {
1457
-        $class_name = str_replace('\\', '_', $class_name);
1458
-        if (isset($this->addons->{$class_name})) {
1459
-            return $this->addons->{$class_name};
1460
-        } else {
1461
-            return null;
1462
-        }
1463
-    }
1464
-
1465
-
1466
-    /**
1467
-     * removes the addon from the internal cache
1468
-     *
1469
-     * @param string $class_name
1470
-     * @return void
1471
-     */
1472
-    public function removeAddon($class_name)
1473
-    {
1474
-        $class_name = str_replace('\\', '_', $class_name);
1475
-        unset($this->addons->{$class_name});
1476
-    }
1477
-
1478
-
1479
-    /**
1480
-     * Gets the addon by its name/slug (not classname. For that, just
1481
-     * use the get_addon() method above
1482
-     *
1483
-     * @param string $name
1484
-     * @return EE_Addon
1485
-     */
1486
-    public function get_addon_by_name($name)
1487
-    {
1488
-        foreach ($this->addons as $addon) {
1489
-            if ($addon->name() === $name) {
1490
-                return $addon;
1491
-            }
1492
-        }
1493
-        return null;
1494
-    }
1495
-
1496
-
1497
-    /**
1498
-     * Gets an array of all the registered addons, where the keys are their names.
1499
-     * (ie, what each returns for their name() function)
1500
-     * They're already available on EE_Registry::instance()->addons as properties,
1501
-     * where each property's name is the addon's classname,
1502
-     * So if you just want to get the addon by classname,
1503
-     * OR use the get_addon() method above.
1504
-     * PLEASE  NOTE:
1505
-     * addons with Fully Qualified Class Names
1506
-     * have had the namespace separators converted to underscores,
1507
-     * so a classname like Fully\Qualified\ClassName
1508
-     * would have been converted to Fully_Qualified_ClassName
1509
-     *
1510
-     * @return EE_Addon[] where the KEYS are the addon's name()
1511
-     */
1512
-    public function get_addons_by_name()
1513
-    {
1514
-        $addons = array();
1515
-        foreach ($this->addons as $addon) {
1516
-            $addons[ $addon->name() ] = $addon;
1517
-        }
1518
-        return $addons;
1519
-    }
1520
-
1521
-
1522
-    /**
1523
-     * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1524
-     * a stale copy of it around
1525
-     *
1526
-     * @param string $model_name
1527
-     * @return \EEM_Base
1528
-     * @throws \EE_Error
1529
-     */
1530
-    public function reset_model($model_name)
1531
-    {
1532
-        $model_class_name = strpos($model_name, 'EEM_') !== 0
1533
-            ? "EEM_{$model_name}"
1534
-            : $model_name;
1535
-        if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1536
-            return null;
1537
-        }
1538
-        // get that model reset it and make sure we nuke the old reference to it
1539
-        if ($this->LIB->{$model_class_name} instanceof $model_class_name
1540
-            && is_callable(
1541
-                array($model_class_name, 'reset')
1542
-            )) {
1543
-            $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1544
-        } else {
1545
-            throw new EE_Error(
1546
-                sprintf(
1547
-                    esc_html__('Model %s does not have a method "reset"', 'event_espresso'),
1548
-                    $model_name
1549
-                )
1550
-            );
1551
-        }
1552
-        return $this->LIB->{$model_class_name};
1553
-    }
1554
-
1555
-
1556
-    /**
1557
-     * Resets the registry.
1558
-     * The criteria for what gets reset is based on what can be shared between sites on the same request when
1559
-     * switch_to_blog is used in a multisite install.  Here is a list of things that are NOT reset.
1560
-     * - $_dependency_map
1561
-     * - $_class_abbreviations
1562
-     * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1563
-     * - $REQ:  Still on the same request so no need to change.
1564
-     * - $CAP: There is no site specific state in the EE_Capability class.
1565
-     * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only
1566
-     * one Session can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1567
-     * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1568
-     *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1569
-     *             switch or on the restore.
1570
-     * - $modules
1571
-     * - $shortcodes
1572
-     * - $widgets
1573
-     *
1574
-     * @param boolean $hard             [deprecated]
1575
-     * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1576
-     *                                  or just reset without re-instantiating (handy to set to FALSE if you're not
1577
-     *                                  sure if you CAN currently reinstantiate the singletons at the moment)
1578
-     * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so
1579
-     *                                  client
1580
-     *                                  code instead can just change the model context to a different blog id if
1581
-     *                                  necessary
1582
-     * @return EE_Registry
1583
-     * @throws InvalidInterfaceException
1584
-     * @throws InvalidDataTypeException
1585
-     * @throws EE_Error
1586
-     * @throws ReflectionException
1587
-     * @throws InvalidArgumentException
1588
-     */
1589
-    public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1590
-    {
1591
-        $instance = self::instance();
1592
-        $instance->_cache_on = true;
1593
-        // reset some "special" classes
1594
-        EEH_Activation::reset();
1595
-        $hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard);
1596
-        $instance->CFG = EE_Config::reset($hard, $reinstantiate);
1597
-        $instance->CART = null;
1598
-        $instance->MRM = null;
1599
-        $instance->AssetsRegistry = LoaderFactory::getLoader()->getShared(
1600
-            'EventEspresso\core\services\assets\Registry'
1601
-        );
1602
-        // messages reset
1603
-        EED_Messages::reset();
1604
-        // handle of objects cached on LIB
1605
-        foreach (array('LIB', 'modules') as $cache) {
1606
-            foreach ($instance->{$cache} as $class_name => $class) {
1607
-                if (self::_reset_and_unset_object($class, $reset_models)) {
1608
-                    unset($instance->{$cache}->{$class_name});
1609
-                }
1610
-            }
1611
-        }
1612
-        return $instance;
1613
-    }
1614
-
1615
-
1616
-    /**
1617
-     * if passed object implements ResettableInterface, then call it's reset() method
1618
-     * if passed object implements InterminableInterface, then return false,
1619
-     * to indicate that it should NOT be cleared from the Registry cache
1620
-     *
1621
-     * @param      $object
1622
-     * @param bool $reset_models
1623
-     * @return bool returns true if cached object should be unset
1624
-     */
1625
-    private static function _reset_and_unset_object($object, $reset_models)
1626
-    {
1627
-        if (! is_object($object)) {
1628
-            // don't unset anything that's not an object
1629
-            return false;
1630
-        }
1631
-        if ($object instanceof EED_Module) {
1632
-            $object::reset();
1633
-            // don't unset modules
1634
-            return false;
1635
-        }
1636
-        if ($object instanceof ResettableInterface) {
1637
-            if ($object instanceof EEM_Base) {
1638
-                if ($reset_models) {
1639
-                    $object->reset();
1640
-                    return true;
1641
-                }
1642
-                return false;
1643
-            }
1644
-            $object->reset();
1645
-            return true;
1646
-        }
1647
-        if (! $object instanceof InterminableInterface) {
1648
-            return true;
1649
-        }
1650
-        return false;
1651
-    }
1652
-
1653
-
1654
-    /**
1655
-     * Gets all the custom post type models defined
1656
-     *
1657
-     * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1658
-     */
1659
-    public function cpt_models()
1660
-    {
1661
-        $cpt_models = array();
1662
-        foreach ($this->non_abstract_db_models as $short_name => $classname) {
1663
-            if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1664
-                $cpt_models[ $short_name ] = $classname;
1665
-            }
1666
-        }
1667
-        return $cpt_models;
1668
-    }
1669
-
1670
-
1671
-    /**
1672
-     * @return \EE_Config
1673
-     */
1674
-    public static function CFG()
1675
-    {
1676
-        return self::instance()->CFG;
1677
-    }
1678
-
1679
-
1680
-    /**
1681
-     * @deprecated 4.9.62.p
1682
-     * @param string $class_name
1683
-     * @return ReflectionClass
1684
-     * @throws ReflectionException
1685
-     * @throws InvalidDataTypeException
1686
-     */
1687
-    public function get_ReflectionClass($class_name)
1688
-    {
1689
-        return $this->mirror->getReflectionClass($class_name);
1690
-    }
26
+	/**
27
+	 * @var EE_Registry $_instance
28
+	 */
29
+	private static $_instance;
30
+
31
+	/**
32
+	 * @var EE_Dependency_Map $_dependency_map
33
+	 */
34
+	protected $_dependency_map;
35
+
36
+	/**
37
+	 * @var Mirror
38
+	 */
39
+	private $mirror;
40
+
41
+	/**
42
+	 * @var ClassInterfaceCache $class_cache
43
+	 */
44
+	private $class_cache;
45
+
46
+	/**
47
+	 * @var array $_class_abbreviations
48
+	 */
49
+	protected $_class_abbreviations = array();
50
+
51
+	/**
52
+	 * @var CommandBusInterface $BUS
53
+	 */
54
+	public $BUS;
55
+
56
+	/**
57
+	 * @var EE_Cart $CART
58
+	 */
59
+	public $CART;
60
+
61
+	/**
62
+	 * @var EE_Config $CFG
63
+	 */
64
+	public $CFG;
65
+
66
+	/**
67
+	 * @var EE_Network_Config $NET_CFG
68
+	 */
69
+	public $NET_CFG;
70
+
71
+	/**
72
+	 * StdClass object for storing library classes in
73
+	 *
74
+	 * @var RegistryContainer $LIB
75
+	 */
76
+	public $LIB;
77
+
78
+	/**
79
+	 * @var EE_Request_Handler $REQ
80
+	 */
81
+	public $REQ;
82
+
83
+	/**
84
+	 * @var EE_Session $SSN
85
+	 */
86
+	public $SSN;
87
+
88
+	/**
89
+	 * @since 4.5.0
90
+	 * @var EE_Capabilities $CAP
91
+	 */
92
+	public $CAP;
93
+
94
+	/**
95
+	 * @since 4.9.0
96
+	 * @var EE_Message_Resource_Manager $MRM
97
+	 */
98
+	public $MRM;
99
+
100
+	/**
101
+	 * @var Registry $AssetsRegistry
102
+	 */
103
+	public $AssetsRegistry;
104
+
105
+	/**
106
+	 * StdClass object for holding addons which have registered themselves to work with EE core
107
+	 *
108
+	 * @var EE_Addon[] $addons
109
+	 */
110
+	public $addons;
111
+
112
+	/**
113
+	 * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
114
+	 *
115
+	 * @var EEM_Base[] $models
116
+	 */
117
+	public $models = array();
118
+
119
+	/**
120
+	 * @var EED_Module[] $modules
121
+	 */
122
+	public $modules;
123
+
124
+	/**
125
+	 * @var EES_Shortcode[] $shortcodes
126
+	 */
127
+	public $shortcodes;
128
+
129
+	/**
130
+	 * @var WP_Widget[] $widgets
131
+	 */
132
+	public $widgets;
133
+
134
+	/**
135
+	 * this is an array of all implemented model names (i.e. not the parent abstract models, or models
136
+	 * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
137
+	 * Keys are model "short names" (eg "Event") as used in model relations, and values are
138
+	 * classnames (eg "EEM_Event")
139
+	 *
140
+	 * @var array $non_abstract_db_models
141
+	 */
142
+	public $non_abstract_db_models = array();
143
+
144
+	/**
145
+	 * internationalization for JS strings
146
+	 *    usage:   EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' );
147
+	 *    in js file:  var translatedString = eei18n.string_key;
148
+	 *
149
+	 * @var array $i18n_js_strings
150
+	 */
151
+	public static $i18n_js_strings = array();
152
+
153
+	/**
154
+	 * $main_file - path to espresso.php
155
+	 *
156
+	 * @var array $main_file
157
+	 */
158
+	public $main_file;
159
+
160
+	/**
161
+	 * array of ReflectionClass objects where the key is the class name
162
+	 *
163
+	 * @deprecated 4.9.62.p
164
+	 * @var ReflectionClass[] $_reflectors
165
+	 */
166
+	public $_reflectors;
167
+
168
+	/**
169
+	 * boolean flag to indicate whether or not to load/save dependencies from/to the cache
170
+	 *
171
+	 * @var boolean $_cache_on
172
+	 */
173
+	protected $_cache_on = true;
174
+
175
+	/**
176
+	 * @var ObjectIdentifier
177
+	 */
178
+	private $object_identifier;
179
+
180
+
181
+	/**
182
+	 * @singleton method used to instantiate class object
183
+	 * @param EE_Dependency_Map|null   $dependency_map
184
+	 * @param Mirror|null              $mirror
185
+	 * @param ClassInterfaceCache|null $class_cache
186
+	 * @param ObjectIdentifier|null    $object_identifier
187
+	 * @return EE_Registry instance
188
+	 */
189
+	public static function instance(
190
+		EE_Dependency_Map $dependency_map = null,
191
+		Mirror $mirror = null,
192
+		ClassInterfaceCache $class_cache = null,
193
+		ObjectIdentifier $object_identifier = null
194
+	) {
195
+		// check if class object is instantiated
196
+		if (! self::$_instance instanceof EE_Registry
197
+			&& $dependency_map instanceof EE_Dependency_Map
198
+			&& $mirror instanceof Mirror
199
+			&& $class_cache instanceof ClassInterfaceCache
200
+			&& $object_identifier instanceof ObjectIdentifier
201
+		) {
202
+			self::$_instance = new self(
203
+				$dependency_map,
204
+				$mirror,
205
+				$class_cache,
206
+				$object_identifier
207
+			);
208
+		}
209
+		return self::$_instance;
210
+	}
211
+
212
+
213
+	/**
214
+	 * protected constructor to prevent direct creation
215
+	 *
216
+	 * @Constructor
217
+	 * @param  EE_Dependency_Map  $dependency_map
218
+	 * @param Mirror              $mirror
219
+	 * @param ClassInterfaceCache $class_cache
220
+	 * @param ObjectIdentifier    $object_identifier
221
+	 */
222
+	protected function __construct(
223
+		EE_Dependency_Map $dependency_map,
224
+		Mirror $mirror,
225
+		ClassInterfaceCache $class_cache,
226
+		ObjectIdentifier $object_identifier
227
+	) {
228
+		$this->_dependency_map = $dependency_map;
229
+		$this->mirror = $mirror;
230
+		$this->class_cache = $class_cache;
231
+		$this->object_identifier = $object_identifier;
232
+		// $registry_container = new RegistryContainer();
233
+		$this->LIB = new RegistryContainer();
234
+		$this->addons = new RegistryContainer();
235
+		$this->modules = new RegistryContainer();
236
+		$this->shortcodes = new RegistryContainer();
237
+		$this->widgets = new RegistryContainer();
238
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
239
+	}
240
+
241
+
242
+	/**
243
+	 * initialize
244
+	 *
245
+	 * @throws OutOfBoundsException
246
+	 * @throws InvalidArgumentException
247
+	 * @throws InvalidInterfaceException
248
+	 * @throws InvalidDataTypeException
249
+	 * @throws EE_Error
250
+	 * @throws ReflectionException
251
+	 */
252
+	public function initialize()
253
+	{
254
+		$this->_class_abbreviations = apply_filters(
255
+			'FHEE__EE_Registry____construct___class_abbreviations',
256
+			array(
257
+				'EE_Config'                                       => 'CFG',
258
+				'EE_Session'                                      => 'SSN',
259
+				'EE_Capabilities'                                 => 'CAP',
260
+				'EE_Cart'                                         => 'CART',
261
+				'EE_Network_Config'                               => 'NET_CFG',
262
+				'EE_Request_Handler'                              => 'REQ',
263
+				'EE_Message_Resource_Manager'                     => 'MRM',
264
+				'EventEspresso\core\services\commands\CommandBus' => 'BUS',
265
+				'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
266
+			)
267
+		);
268
+		$this->load_core('Base', array(), true);
269
+		// add our request and response objects to the cache
270
+		$request_loader = $this->_dependency_map->class_loader(
271
+			'EventEspresso\core\services\request\Request'
272
+		);
273
+		$this->_set_cached_class(
274
+			$request_loader(),
275
+			'EventEspresso\core\services\request\Request'
276
+		);
277
+		$response_loader = $this->_dependency_map->class_loader(
278
+			'EventEspresso\core\services\request\Response'
279
+		);
280
+		$this->_set_cached_class(
281
+			$response_loader(),
282
+			'EventEspresso\core\services\request\Response'
283
+		);
284
+		add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
285
+	}
286
+
287
+
288
+	/**
289
+	 * @return void
290
+	 */
291
+	public function init()
292
+	{
293
+		// Get current page protocol
294
+		$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
295
+		// Output admin-ajax.php URL with same protocol as current page
296
+		self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
297
+		self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
298
+	}
299
+
300
+
301
+	/**
302
+	 * localize_i18n_js_strings
303
+	 *
304
+	 * @return string
305
+	 */
306
+	public static function localize_i18n_js_strings()
307
+	{
308
+		$i18n_js_strings = (array) self::$i18n_js_strings;
309
+		foreach ($i18n_js_strings as $key => $value) {
310
+			if (is_scalar($value)) {
311
+				$i18n_js_strings[ $key ] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
312
+			}
313
+		}
314
+		return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
315
+	}
316
+
317
+
318
+	/**
319
+	 * @param mixed string | EED_Module $module
320
+	 * @throws OutOfBoundsException
321
+	 * @throws InvalidArgumentException
322
+	 * @throws InvalidInterfaceException
323
+	 * @throws InvalidDataTypeException
324
+	 * @throws EE_Error
325
+	 * @throws ReflectionException
326
+	 */
327
+	public function add_module($module)
328
+	{
329
+		if ($module instanceof EED_Module) {
330
+			$module_class = get_class($module);
331
+			$this->modules->{$module_class} = $module;
332
+		} else {
333
+			if (! class_exists('EE_Module_Request_Router', false)) {
334
+				$this->load_core('Module_Request_Router');
335
+			}
336
+			EE_Module_Request_Router::module_factory($module);
337
+		}
338
+	}
339
+
340
+
341
+	/**
342
+	 * @param string $module_name
343
+	 * @return mixed EED_Module | NULL
344
+	 */
345
+	public function get_module($module_name = '')
346
+	{
347
+		return isset($this->modules->{$module_name})
348
+			? $this->modules->{$module_name}
349
+			: null;
350
+	}
351
+
352
+
353
+	/**
354
+	 * loads core classes - must be singletons
355
+	 *
356
+	 * @param string $class_name - simple class name ie: session
357
+	 * @param mixed  $arguments
358
+	 * @param bool   $load_only
359
+	 * @return mixed
360
+	 * @throws InvalidInterfaceException
361
+	 * @throws InvalidDataTypeException
362
+	 * @throws EE_Error
363
+	 * @throws ReflectionException
364
+	 * @throws InvalidArgumentException
365
+	 */
366
+	public function load_core($class_name, $arguments = array(), $load_only = false)
367
+	{
368
+		$core_paths = apply_filters(
369
+			'FHEE__EE_Registry__load_core__core_paths',
370
+			array(
371
+				EE_CORE,
372
+				EE_ADMIN,
373
+				EE_CPTS,
374
+				EE_CORE . 'data_migration_scripts' . DS,
375
+				EE_CORE . 'capabilities' . DS,
376
+				EE_CORE . 'request_stack' . DS,
377
+				EE_CORE . 'middleware' . DS,
378
+			)
379
+		);
380
+		// retrieve instantiated class
381
+		return $this->_load(
382
+			$core_paths,
383
+			'EE_',
384
+			$class_name,
385
+			'core',
386
+			$arguments,
387
+			false,
388
+			true,
389
+			$load_only
390
+		);
391
+	}
392
+
393
+
394
+	/**
395
+	 * loads service classes
396
+	 *
397
+	 * @param string $class_name - simple class name ie: session
398
+	 * @param mixed  $arguments
399
+	 * @param bool   $load_only
400
+	 * @return mixed
401
+	 * @throws InvalidInterfaceException
402
+	 * @throws InvalidDataTypeException
403
+	 * @throws EE_Error
404
+	 * @throws ReflectionException
405
+	 * @throws InvalidArgumentException
406
+	 */
407
+	public function load_service($class_name, $arguments = array(), $load_only = false)
408
+	{
409
+		$service_paths = apply_filters(
410
+			'FHEE__EE_Registry__load_service__service_paths',
411
+			array(
412
+				EE_CORE . 'services' . DS,
413
+			)
414
+		);
415
+		// retrieve instantiated class
416
+		return $this->_load(
417
+			$service_paths,
418
+			'EE_',
419
+			$class_name,
420
+			'class',
421
+			$arguments,
422
+			false,
423
+			true,
424
+			$load_only
425
+		);
426
+	}
427
+
428
+
429
+	/**
430
+	 * loads data_migration_scripts
431
+	 *
432
+	 * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
433
+	 * @param mixed  $arguments
434
+	 * @return EE_Data_Migration_Script_Base|mixed
435
+	 * @throws InvalidInterfaceException
436
+	 * @throws InvalidDataTypeException
437
+	 * @throws EE_Error
438
+	 * @throws ReflectionException
439
+	 * @throws InvalidArgumentException
440
+	 */
441
+	public function load_dms($class_name, $arguments = array())
442
+	{
443
+		// retrieve instantiated class
444
+		return $this->_load(
445
+			EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(),
446
+			'EE_DMS_',
447
+			$class_name,
448
+			'dms',
449
+			$arguments,
450
+			false,
451
+			false
452
+		);
453
+	}
454
+
455
+
456
+	/**
457
+	 * loads object creating classes - must be singletons
458
+	 *
459
+	 * @param string $class_name - simple class name ie: attendee
460
+	 * @param mixed  $arguments  - an array of arguments to pass to the class
461
+	 * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to
462
+	 *                           instantiate
463
+	 * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then
464
+	 *                           set this to FALSE (ie. when instantiating model objects from client in a loop)
465
+	 * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate
466
+	 *                           (default)
467
+	 * @return EE_Base_Class | bool
468
+	 * @throws InvalidInterfaceException
469
+	 * @throws InvalidDataTypeException
470
+	 * @throws EE_Error
471
+	 * @throws ReflectionException
472
+	 * @throws InvalidArgumentException
473
+	 */
474
+	public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
475
+	{
476
+		$paths = apply_filters(
477
+			'FHEE__EE_Registry__load_class__paths',
478
+			array(
479
+				EE_CORE,
480
+				EE_CLASSES,
481
+				EE_BUSINESS,
482
+			)
483
+		);
484
+		// retrieve instantiated class
485
+		return $this->_load(
486
+			$paths,
487
+			'EE_',
488
+			$class_name,
489
+			'class',
490
+			$arguments,
491
+			$from_db,
492
+			$cache,
493
+			$load_only
494
+		);
495
+	}
496
+
497
+
498
+	/**
499
+	 * loads helper classes - must be singletons
500
+	 *
501
+	 * @param string $class_name - simple class name ie: price
502
+	 * @param mixed  $arguments
503
+	 * @param bool   $load_only
504
+	 * @return EEH_Base | bool
505
+	 * @throws InvalidInterfaceException
506
+	 * @throws InvalidDataTypeException
507
+	 * @throws EE_Error
508
+	 * @throws ReflectionException
509
+	 * @throws InvalidArgumentException
510
+	 */
511
+	public function load_helper($class_name, $arguments = array(), $load_only = true)
512
+	{
513
+		// todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
514
+		$helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
515
+		// retrieve instantiated class
516
+		return $this->_load(
517
+			$helper_paths,
518
+			'EEH_',
519
+			$class_name,
520
+			'helper',
521
+			$arguments,
522
+			false,
523
+			true,
524
+			$load_only
525
+		);
526
+	}
527
+
528
+
529
+	/**
530
+	 * loads core classes - must be singletons
531
+	 *
532
+	 * @param string $class_name - simple class name ie: session
533
+	 * @param mixed  $arguments
534
+	 * @param bool   $load_only
535
+	 * @param bool   $cache      whether to cache the object or not.
536
+	 * @return mixed
537
+	 * @throws InvalidInterfaceException
538
+	 * @throws InvalidDataTypeException
539
+	 * @throws EE_Error
540
+	 * @throws ReflectionException
541
+	 * @throws InvalidArgumentException
542
+	 */
543
+	public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
544
+	{
545
+		$paths = array(
546
+			EE_LIBRARIES,
547
+			EE_LIBRARIES . 'messages' . DS,
548
+			EE_LIBRARIES . 'shortcodes' . DS,
549
+			EE_LIBRARIES . 'qtips' . DS,
550
+			EE_LIBRARIES . 'payment_methods' . DS,
551
+		);
552
+		// retrieve instantiated class
553
+		return $this->_load(
554
+			$paths,
555
+			'EE_',
556
+			$class_name,
557
+			'lib',
558
+			$arguments,
559
+			false,
560
+			$cache,
561
+			$load_only
562
+		);
563
+	}
564
+
565
+
566
+	/**
567
+	 * loads model classes - must be singletons
568
+	 *
569
+	 * @param string $class_name - simple class name ie: price
570
+	 * @param mixed  $arguments
571
+	 * @param bool   $load_only
572
+	 * @return EEM_Base | bool
573
+	 * @throws InvalidInterfaceException
574
+	 * @throws InvalidDataTypeException
575
+	 * @throws EE_Error
576
+	 * @throws ReflectionException
577
+	 * @throws InvalidArgumentException
578
+	 */
579
+	public function load_model($class_name, $arguments = array(), $load_only = false)
580
+	{
581
+		$paths = apply_filters(
582
+			'FHEE__EE_Registry__load_model__paths',
583
+			array(
584
+				EE_MODELS,
585
+				EE_CORE,
586
+			)
587
+		);
588
+		// retrieve instantiated class
589
+		return $this->_load(
590
+			$paths,
591
+			'EEM_',
592
+			$class_name,
593
+			'model',
594
+			$arguments,
595
+			false,
596
+			true,
597
+			$load_only
598
+		);
599
+	}
600
+
601
+
602
+	/**
603
+	 * loads model classes - must be singletons
604
+	 *
605
+	 * @param string $class_name - simple class name ie: price
606
+	 * @param mixed  $arguments
607
+	 * @param bool   $load_only
608
+	 * @return mixed | bool
609
+	 * @throws InvalidInterfaceException
610
+	 * @throws InvalidDataTypeException
611
+	 * @throws EE_Error
612
+	 * @throws ReflectionException
613
+	 * @throws InvalidArgumentException
614
+	 */
615
+	public function load_model_class($class_name, $arguments = array(), $load_only = true)
616
+	{
617
+		$paths = array(
618
+			EE_MODELS . 'fields' . DS,
619
+			EE_MODELS . 'helpers' . DS,
620
+			EE_MODELS . 'relations' . DS,
621
+			EE_MODELS . 'strategies' . DS,
622
+		);
623
+		// retrieve instantiated class
624
+		return $this->_load(
625
+			$paths,
626
+			'EE_',
627
+			$class_name,
628
+			'',
629
+			$arguments,
630
+			false,
631
+			true,
632
+			$load_only
633
+		);
634
+	}
635
+
636
+
637
+	/**
638
+	 * Determines if $model_name is the name of an actual EE model.
639
+	 *
640
+	 * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
641
+	 * @return boolean
642
+	 */
643
+	public function is_model_name($model_name)
644
+	{
645
+		return isset($this->models[ $model_name ]);
646
+	}
647
+
648
+
649
+	/**
650
+	 * generic class loader
651
+	 *
652
+	 * @param string $path_to_file - directory path to file location, not including filename
653
+	 * @param string $file_name    - file name  ie:  my_file.php, including extension
654
+	 * @param string $type         - file type - core? class? helper? model?
655
+	 * @param mixed  $arguments
656
+	 * @param bool   $load_only
657
+	 * @return mixed
658
+	 * @throws InvalidInterfaceException
659
+	 * @throws InvalidDataTypeException
660
+	 * @throws EE_Error
661
+	 * @throws ReflectionException
662
+	 * @throws InvalidArgumentException
663
+	 */
664
+	public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
665
+	{
666
+		// retrieve instantiated class
667
+		return $this->_load(
668
+			$path_to_file,
669
+			'',
670
+			$file_name,
671
+			$type,
672
+			$arguments,
673
+			false,
674
+			true,
675
+			$load_only
676
+		);
677
+	}
678
+
679
+
680
+	/**
681
+	 * @param string $path_to_file - directory path to file location, not including filename
682
+	 * @param string $class_name   - full class name  ie:  My_Class
683
+	 * @param string $type         - file type - core? class? helper? model?
684
+	 * @param mixed  $arguments
685
+	 * @param bool   $load_only
686
+	 * @return bool|EE_Addon|object
687
+	 * @throws InvalidInterfaceException
688
+	 * @throws InvalidDataTypeException
689
+	 * @throws EE_Error
690
+	 * @throws ReflectionException
691
+	 * @throws InvalidArgumentException
692
+	 */
693
+	public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
694
+	{
695
+		// retrieve instantiated class
696
+		return $this->_load(
697
+			$path_to_file,
698
+			'addon',
699
+			$class_name,
700
+			$type,
701
+			$arguments,
702
+			false,
703
+			true,
704
+			$load_only
705
+		);
706
+	}
707
+
708
+
709
+	/**
710
+	 * instantiates, caches, and automatically resolves dependencies
711
+	 * for classes that use a Fully Qualified Class Name.
712
+	 * if the class is not capable of being loaded using PSR-4 autoloading,
713
+	 * then you need to use one of the existing load_*() methods
714
+	 * which can resolve the classname and filepath from the passed arguments
715
+	 *
716
+	 * @param bool|string $class_name   Fully Qualified Class Name
717
+	 * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
718
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
719
+	 * @param bool        $from_db      some classes are instantiated from the db
720
+	 *                                  and thus call a different method to instantiate
721
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
722
+	 * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
723
+	 * @return bool|null|mixed          null = failure to load or instantiate class object.
724
+	 *                                  object = class loaded and instantiated successfully.
725
+	 *                                  bool = fail or success when $load_only is true
726
+	 * @throws InvalidInterfaceException
727
+	 * @throws InvalidDataTypeException
728
+	 * @throws EE_Error
729
+	 * @throws ReflectionException
730
+	 * @throws InvalidArgumentException
731
+	 */
732
+	public function create(
733
+		$class_name = false,
734
+		$arguments = array(),
735
+		$cache = false,
736
+		$from_db = false,
737
+		$load_only = false,
738
+		$addon = false
739
+	) {
740
+		$class_name = ltrim($class_name, '\\');
741
+		$class_name = $this->class_cache->getFqnForAlias($class_name);
742
+		$class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
743
+		// if a non-FQCN was passed, then
744
+		// verifyClassExists() might return an object
745
+		// or it could return null if the class just could not be found anywhere
746
+		if ($class_exists instanceof $class_name || $class_exists === null) {
747
+			// either way, return the results
748
+			return $class_exists;
749
+		}
750
+		$class_name = $class_exists;
751
+		// if we're only loading the class and it already exists, then let's just return true immediately
752
+		if ($load_only) {
753
+			return true;
754
+		}
755
+		$addon = $addon ? 'addon' : '';
756
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
757
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
758
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
759
+		if ($this->_cache_on && $cache && ! $load_only) {
760
+			// return object if it's already cached
761
+			$cached_class = $this->_get_cached_class($class_name, $addon, $arguments);
762
+			if ($cached_class !== null) {
763
+				return $cached_class;
764
+			}
765
+		}// obtain the loader method from the dependency map
766
+		$loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object
767
+		if ($loader instanceof Closure) {
768
+			$class_obj = $loader($arguments);
769
+		} else {
770
+			if ($loader && method_exists($this, $loader)) {
771
+				$class_obj = $this->{$loader}($class_name, $arguments);
772
+			} else {
773
+				$class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
774
+			}
775
+		}
776
+		if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) {
777
+			// save it for later... kinda like gum  { : $
778
+			$this->_set_cached_class(
779
+				$class_obj,
780
+				$class_name,
781
+				$addon,
782
+				$from_db,
783
+				$arguments
784
+			);
785
+		}
786
+		$this->_cache_on = true;
787
+		return $class_obj;
788
+	}
789
+
790
+
791
+	/**
792
+	 * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
793
+	 *
794
+	 * @param string|object $class_name
795
+	 * @param array         $arguments
796
+	 * @param int           $attempt
797
+	 * @return mixed
798
+	 */
799
+	private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1)
800
+	{
801
+		if (is_object($class_name) || class_exists($class_name)) {
802
+			return $class_name;
803
+		}
804
+		switch ($attempt) {
805
+			case 1:
806
+				// if it's a FQCN then maybe the class is registered with a preceding \
807
+				$class_name = strpos($class_name, '\\') !== false
808
+					? '\\' . ltrim($class_name, '\\')
809
+					: $class_name;
810
+				break;
811
+			case 2:
812
+				//
813
+				$loader = $this->_dependency_map->class_loader($class_name);
814
+				if ($loader && method_exists($this, $loader)) {
815
+					return $this->{$loader}($class_name, $arguments);
816
+				}
817
+				break;
818
+			case 3:
819
+			default:
820
+				return null;
821
+		}
822
+		$attempt++;
823
+		return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt);
824
+	}
825
+
826
+
827
+	/**
828
+	 * instantiates, caches, and injects dependencies for classes
829
+	 *
830
+	 * @param array       $file_paths   an array of paths to folders to look in
831
+	 * @param string      $class_prefix EE  or EEM or... ???
832
+	 * @param bool|string $class_name   $class name
833
+	 * @param string      $type         file type - core? class? helper? model?
834
+	 * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
835
+	 * @param bool        $from_db      some classes are instantiated from the db
836
+	 *                                  and thus call a different method to instantiate
837
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
838
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
839
+	 * @return bool|null|object null = failure to load or instantiate class object.
840
+	 *                                  object = class loaded and instantiated successfully.
841
+	 *                                  bool = fail or success when $load_only is true
842
+	 * @throws EE_Error
843
+	 * @throws ReflectionException
844
+	 * @throws InvalidInterfaceException
845
+	 * @throws InvalidDataTypeException
846
+	 * @throws InvalidArgumentException
847
+	 */
848
+	protected function _load(
849
+		$file_paths = array(),
850
+		$class_prefix = 'EE_',
851
+		$class_name = false,
852
+		$type = 'class',
853
+		$arguments = array(),
854
+		$from_db = false,
855
+		$cache = true,
856
+		$load_only = false
857
+	) {
858
+		$class_name = ltrim($class_name, '\\');
859
+		// strip php file extension
860
+		$class_name = str_replace('.php', '', trim($class_name));
861
+		// does the class have a prefix ?
862
+		if (! empty($class_prefix) && $class_prefix !== 'addon') {
863
+			// make sure $class_prefix is uppercase
864
+			$class_prefix = strtoupper(trim($class_prefix));
865
+			// add class prefix ONCE!!!
866
+			$class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
867
+		}
868
+		$class_name = $this->class_cache->getFqnForAlias($class_name);
869
+		$class_exists = class_exists($class_name, false);
870
+		// if we're only loading the class and it already exists, then let's just return true immediately
871
+		if ($load_only && $class_exists) {
872
+			return true;
873
+		}
874
+		$arguments = is_array($arguments) ? $arguments : array($arguments);
875
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
876
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
877
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
878
+		if ($this->_cache_on && $cache && ! $load_only) {
879
+			// return object if it's already cached
880
+			$cached_class = $this->_get_cached_class($class_name, $class_prefix, $arguments);
881
+			if ($cached_class !== null) {
882
+				return $cached_class;
883
+			}
884
+		}
885
+		// if the class doesn't already exist.. then we need to try and find the file and load it
886
+		if (! $class_exists) {
887
+			// get full path to file
888
+			$path = $this->_resolve_path($class_name, $type, $file_paths);
889
+			// load the file
890
+			$loaded = $this->_require_file($path, $class_name, $type, $file_paths);
891
+			// if we are only loading a file but NOT instantiating an object
892
+			// then return boolean for whether class was loaded or not
893
+			if ($load_only) {
894
+				return $loaded;
895
+			}
896
+			// if an object was expected but loading failed, then return nothing
897
+			if (! $loaded) {
898
+				return null;
899
+			}
900
+		}
901
+		// instantiate the requested object
902
+		$class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
903
+		if ($this->_cache_on && $cache) {
904
+			// save it for later... kinda like gum  { : $
905
+			$this->_set_cached_class(
906
+				$class_obj,
907
+				$class_name,
908
+				$class_prefix,
909
+				$from_db,
910
+				$arguments
911
+			);
912
+		}
913
+		$this->_cache_on = true;
914
+		return $class_obj;
915
+	}
916
+
917
+
918
+	/**
919
+	 * @param string $class_name
920
+	 * @param string $default have to specify something, but not anything that will conflict
921
+	 * @return mixed|string
922
+	 */
923
+	protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS')
924
+	{
925
+		return isset($this->_class_abbreviations[ $class_name ])
926
+			? $this->_class_abbreviations[ $class_name ]
927
+			: $default;
928
+	}
929
+
930
+
931
+	/**
932
+	 * attempts to find a cached version of the requested class
933
+	 * by looking in the following places:
934
+	 *        $this->{$class_abbreviation}            ie:    $this->CART
935
+	 *        $this->{$class_name}                        ie:    $this->Some_Class
936
+	 *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
937
+	 *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
938
+	 *
939
+	 * @param string $class_name
940
+	 * @param string $class_prefix
941
+	 * @param array  $arguments
942
+	 * @return mixed
943
+	 */
944
+	protected function _get_cached_class(
945
+		$class_name,
946
+		$class_prefix = '',
947
+		$arguments = array()
948
+	) {
949
+		if ($class_name === 'EE_Registry') {
950
+			return $this;
951
+		}
952
+		$class_abbreviation = $this->get_class_abbreviation($class_name);
953
+		// check if class has already been loaded, and return it if it has been
954
+		if (isset($this->{$class_abbreviation})) {
955
+			return $this->{$class_abbreviation};
956
+		}
957
+		$class_name = str_replace('\\', '_', $class_name);
958
+		if (isset($this->{$class_name})) {
959
+			return $this->{$class_name};
960
+		}
961
+		if ($class_prefix === 'addon' && isset($this->addons->{$class_name})) {
962
+			return $this->addons->{$class_name};
963
+		}
964
+		$object_identifier = $this->object_identifier->getIdentifier($class_name, $arguments);
965
+		if (isset($this->LIB->{$object_identifier})) {
966
+			return $this->LIB->{$object_identifier};
967
+		}
968
+		foreach ($this->LIB as $key => $object) {
969
+			if (// request does not contain new arguments and therefore no args identifier
970
+				! $this->object_identifier->hasArguments($object_identifier)
971
+				// but previously cached class with args was found
972
+				&& $this->object_identifier->fqcnMatchesObjectIdentifier($class_name, $key)
973
+			) {
974
+				return $object;
975
+			}
976
+		}
977
+		return null;
978
+	}
979
+
980
+
981
+	/**
982
+	 * removes a cached version of the requested class
983
+	 *
984
+	 * @param string  $class_name
985
+	 * @param boolean $addon
986
+	 * @param array   $arguments
987
+	 * @return boolean
988
+	 */
989
+	public function clear_cached_class(
990
+		$class_name,
991
+		$addon = false,
992
+		$arguments = array()
993
+	) {
994
+		$class_abbreviation = $this->get_class_abbreviation($class_name);
995
+		// check if class has already been loaded, and return it if it has been
996
+		if (isset($this->{$class_abbreviation})) {
997
+			$this->{$class_abbreviation} = null;
998
+			return true;
999
+		}
1000
+		$class_name = str_replace('\\', '_', $class_name);
1001
+		if (isset($this->{$class_name})) {
1002
+			$this->{$class_name} = null;
1003
+			return true;
1004
+		}
1005
+		if ($addon && isset($this->addons->{$class_name})) {
1006
+			unset($this->addons->{$class_name});
1007
+			return true;
1008
+		}
1009
+		$class_name = $this->object_identifier->getIdentifier($class_name, $arguments);
1010
+		if (isset($this->LIB->{$class_name})) {
1011
+			unset($this->LIB->{$class_name});
1012
+			return true;
1013
+		}
1014
+		return false;
1015
+	}
1016
+
1017
+
1018
+	/**
1019
+	 * _set_cached_class
1020
+	 * attempts to cache the instantiated class locally
1021
+	 * in one of the following places, in the following order:
1022
+	 *        $this->{class_abbreviation}   ie:    $this->CART
1023
+	 *        $this->{$class_name}          ie:    $this->Some_Class
1024
+	 *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1025
+	 *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1026
+	 *
1027
+	 * @param object $class_obj
1028
+	 * @param string $class_name
1029
+	 * @param string $class_prefix
1030
+	 * @param bool   $from_db
1031
+	 * @param array  $arguments
1032
+	 * @return void
1033
+	 */
1034
+	protected function _set_cached_class(
1035
+		$class_obj,
1036
+		$class_name,
1037
+		$class_prefix = '',
1038
+		$from_db = false,
1039
+		$arguments = array()
1040
+	) {
1041
+		if ($class_name === 'EE_Registry' || empty($class_obj)) {
1042
+			return;
1043
+		}
1044
+		// return newly instantiated class
1045
+		$class_abbreviation = $this->get_class_abbreviation($class_name, '');
1046
+		if ($class_abbreviation) {
1047
+			$this->{$class_abbreviation} = $class_obj;
1048
+			return;
1049
+		}
1050
+		$class_name = str_replace('\\', '_', $class_name);
1051
+		if (property_exists($this, $class_name)) {
1052
+			$this->{$class_name} = $class_obj;
1053
+			return;
1054
+		}
1055
+		if ($class_prefix === 'addon') {
1056
+			$this->addons->{$class_name} = $class_obj;
1057
+			return;
1058
+		}
1059
+		if (! $from_db) {
1060
+			$class_name = $this->object_identifier->getIdentifier($class_name, $arguments);
1061
+			$this->LIB->{$class_name} = $class_obj;
1062
+		}
1063
+	}
1064
+
1065
+
1066
+	/**
1067
+	 * attempts to find a full valid filepath for the requested class.
1068
+	 * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
1069
+	 * then returns that path if the target file has been found and is readable
1070
+	 *
1071
+	 * @param string $class_name
1072
+	 * @param string $type
1073
+	 * @param array  $file_paths
1074
+	 * @return string | bool
1075
+	 */
1076
+	protected function _resolve_path($class_name, $type = '', $file_paths = array())
1077
+	{
1078
+		// make sure $file_paths is an array
1079
+		$file_paths = is_array($file_paths)
1080
+			? $file_paths
1081
+			: array($file_paths);
1082
+		// cycle thru paths
1083
+		foreach ($file_paths as $key => $file_path) {
1084
+			// convert all separators to proper DS, if no filepath, then use EE_CLASSES
1085
+			$file_path = $file_path
1086
+				? str_replace(array('/', '\\'), DS, $file_path)
1087
+				: EE_CLASSES;
1088
+			// prep file type
1089
+			$type = ! empty($type)
1090
+				? trim($type, '.') . '.'
1091
+				: '';
1092
+			// build full file path
1093
+			$file_paths[ $key ] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
1094
+			// does the file exist and can be read ?
1095
+			if (is_readable($file_paths[ $key ])) {
1096
+				return $file_paths[ $key ];
1097
+			}
1098
+		}
1099
+		return false;
1100
+	}
1101
+
1102
+
1103
+	/**
1104
+	 * basically just performs a require_once()
1105
+	 * but with some error handling
1106
+	 *
1107
+	 * @param  string $path
1108
+	 * @param  string $class_name
1109
+	 * @param  string $type
1110
+	 * @param  array  $file_paths
1111
+	 * @return bool
1112
+	 * @throws EE_Error
1113
+	 * @throws ReflectionException
1114
+	 */
1115
+	protected function _require_file($path, $class_name, $type = '', $file_paths = array())
1116
+	{
1117
+		$this->resolve_legacy_class_parent($class_name);
1118
+		// don't give up! you gotta...
1119
+		try {
1120
+			// does the file exist and can it be read ?
1121
+			if (! $path) {
1122
+				// just in case the file has already been autoloaded,
1123
+				// but discrepancies in the naming schema are preventing it from
1124
+				// being loaded via one of the EE_Registry::load_*() methods,
1125
+				// then let's try one last hail mary before throwing an exception
1126
+				// and call class_exists() again, but with autoloading turned ON
1127
+				if (class_exists($class_name)) {
1128
+					return true;
1129
+				}
1130
+				// so sorry, can't find the file
1131
+				throw new EE_Error(
1132
+					sprintf(
1133
+						esc_html__(
1134
+							'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s',
1135
+							'event_espresso'
1136
+						),
1137
+						trim($type, '.'),
1138
+						$class_name,
1139
+						'<br />' . implode(',<br />', $file_paths)
1140
+					)
1141
+				);
1142
+			}
1143
+			// get the file
1144
+			require_once($path);
1145
+			// if the class isn't already declared somewhere
1146
+			if (class_exists($class_name, false) === false) {
1147
+				// so sorry, not a class
1148
+				throw new EE_Error(
1149
+					sprintf(
1150
+						esc_html__(
1151
+							'The %s file %s does not appear to contain the %s Class.',
1152
+							'event_espresso'
1153
+						),
1154
+						$type,
1155
+						$path,
1156
+						$class_name
1157
+					)
1158
+				);
1159
+			}
1160
+		} catch (EE_Error $e) {
1161
+			$e->get_error();
1162
+			return false;
1163
+		}
1164
+		return true;
1165
+	}
1166
+
1167
+
1168
+	/**
1169
+	 * Some of our legacy classes that extended a parent class would simply use a require() statement
1170
+	 * before their class declaration in order to ensure that the parent class was loaded.
1171
+	 * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class,
1172
+	 * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist.
1173
+	 *
1174
+	 * @param string $class_name
1175
+	 */
1176
+	protected function resolve_legacy_class_parent($class_name = '')
1177
+	{
1178
+		try {
1179
+			$legacy_parent_class_map = array(
1180
+				'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php',
1181
+			);
1182
+			if (isset($legacy_parent_class_map[ $class_name ])) {
1183
+				require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ];
1184
+			}
1185
+		} catch (Exception $exception) {
1186
+		}
1187
+	}
1188
+
1189
+
1190
+	/**
1191
+	 * _create_object
1192
+	 * Attempts to instantiate the requested class via any of the
1193
+	 * commonly used instantiation methods employed throughout EE.
1194
+	 * The priority for instantiation is as follows:
1195
+	 *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
1196
+	 *        - model objects via their 'new_instance_from_db' method
1197
+	 *        - model objects via their 'new_instance' method
1198
+	 *        - "singleton" classes" via their 'instance' method
1199
+	 *    - standard instantiable classes via their __constructor
1200
+	 * Prior to instantiation, if the classname exists in the dependency_map,
1201
+	 * then the constructor for the requested class will be examined to determine
1202
+	 * if any dependencies exist, and if they can be injected.
1203
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1204
+	 *
1205
+	 * @param string $class_name
1206
+	 * @param array  $arguments
1207
+	 * @param string $type
1208
+	 * @param bool   $from_db
1209
+	 * @return null|object|bool
1210
+	 * @throws InvalidArgumentException
1211
+	 * @throws InvalidInterfaceException
1212
+	 * @throws EE_Error
1213
+	 * @throws ReflectionException
1214
+	 * @throws InvalidDataTypeException
1215
+	 */
1216
+	protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
1217
+	{
1218
+		// create reflection
1219
+		$reflector = $this->mirror->getReflectionClass($class_name);
1220
+		// make sure arguments are an array
1221
+		$arguments = is_array($arguments)
1222
+			? $arguments
1223
+			: array($arguments);
1224
+		// and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
1225
+		// else wrap it in an additional array so that it doesn't get split into multiple parameters
1226
+		$arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
1227
+			? $arguments
1228
+			: array($arguments);
1229
+		// attempt to inject dependencies ?
1230
+		if ($this->_dependency_map->has($class_name)) {
1231
+			$arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
1232
+		}
1233
+		// instantiate the class if possible
1234
+		if ($reflector->isAbstract()) {
1235
+			// nothing to instantiate, loading file was enough
1236
+			// does not throw an exception so $instantiation_mode is unused
1237
+			// $instantiation_mode = "1) no constructor abstract class";
1238
+			return true;
1239
+		}
1240
+		if (empty($arguments)
1241
+			&& $this->mirror->getConstructorFromReflection($reflector) === null
1242
+			&& $reflector->isInstantiable()
1243
+		) {
1244
+			// no constructor = static methods only... nothing to instantiate, loading file was enough
1245
+			// $instantiation_mode = "2) no constructor but instantiable";
1246
+			return $reflector->newInstance();
1247
+		}
1248
+		if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
1249
+			// $instantiation_mode = "3) new_instance_from_db()";
1250
+			return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
1251
+		}
1252
+		if (method_exists($class_name, 'new_instance')) {
1253
+			// $instantiation_mode = "4) new_instance()";
1254
+			return call_user_func_array(array($class_name, 'new_instance'), $arguments);
1255
+		}
1256
+		if (method_exists($class_name, 'instance')) {
1257
+			// $instantiation_mode = "5) instance()";
1258
+			return call_user_func_array(array($class_name, 'instance'), $arguments);
1259
+		}
1260
+		if ($reflector->isInstantiable()) {
1261
+			// $instantiation_mode = "6) constructor";
1262
+			return $reflector->newInstanceArgs($arguments);
1263
+		}
1264
+		// heh ? something's not right !
1265
+		throw new EE_Error(
1266
+			sprintf(
1267
+				__('The %s file %s could not be instantiated.', 'event_espresso'),
1268
+				$type,
1269
+				$class_name
1270
+			)
1271
+		);
1272
+	}
1273
+
1274
+
1275
+	/**
1276
+	 * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1277
+	 * @param array $array
1278
+	 * @return bool
1279
+	 */
1280
+	protected function _array_is_numerically_and_sequentially_indexed(array $array)
1281
+	{
1282
+		return ! empty($array)
1283
+			? array_keys($array) === range(0, count($array) - 1)
1284
+			: true;
1285
+	}
1286
+
1287
+
1288
+	/**
1289
+	 * _resolve_dependencies
1290
+	 * examines the constructor for the requested class to determine
1291
+	 * if any dependencies exist, and if they can be injected.
1292
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1293
+	 * PLZ NOTE: this is achieved by type hinting the constructor params
1294
+	 * For example:
1295
+	 *        if attempting to load a class "Foo" with the following constructor:
1296
+	 *        __construct( Bar $bar_class, Fighter $grohl_class )
1297
+	 *        then $bar_class and $grohl_class will be added to the $arguments array,
1298
+	 *        but only IF they are NOT already present in the incoming arguments array,
1299
+	 *        and the correct classes can be loaded
1300
+	 *
1301
+	 * @param ReflectionClass $reflector
1302
+	 * @param string          $class_name
1303
+	 * @param array           $arguments
1304
+	 * @return array
1305
+	 * @throws InvalidArgumentException
1306
+	 * @throws InvalidDataTypeException
1307
+	 * @throws InvalidInterfaceException
1308
+	 * @throws ReflectionException
1309
+	 */
1310
+	protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, array $arguments = array())
1311
+	{
1312
+		// let's examine the constructor
1313
+		$constructor = $this->mirror->getConstructorFromReflection($reflector);
1314
+		// whu? huh? nothing?
1315
+		if (! $constructor) {
1316
+			return $arguments;
1317
+		}
1318
+		// get constructor parameters
1319
+		$params = $this->mirror->getParametersFromReflection($reflector);
1320
+		// and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1321
+		$argument_keys = array_keys($arguments);
1322
+		// now loop thru all of the constructors expected parameters
1323
+		foreach ($params as $index => $param) {
1324
+			// is this a dependency for a specific class ?
1325
+			$param_class = $this->mirror->getParameterClassName($param, $class_name, $index);
1326
+			// BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1327
+			$param_class = $this->class_cache->isAlias($param_class, $class_name)
1328
+				? $this->class_cache->getFqnForAlias($param_class, $class_name)
1329
+				: $param_class;
1330
+			if (// param is not even a class
1331
+				$param_class === null
1332
+				// and something already exists in the incoming arguments for this param
1333
+				&& array_key_exists($index, $argument_keys)
1334
+				&& array_key_exists($argument_keys[ $index ], $arguments)
1335
+			) {
1336
+				// so let's skip this argument and move on to the next
1337
+				continue;
1338
+			}
1339
+			if (// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1340
+				$param_class !== null
1341
+				&& isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ])
1342
+				&& $arguments[ $argument_keys[ $index ] ] instanceof $param_class
1343
+			) {
1344
+				// skip this argument and move on to the next
1345
+				continue;
1346
+			}
1347
+			if (// parameter is type hinted as a class, and should be injected
1348
+				$param_class !== null
1349
+				&& $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1350
+			) {
1351
+				$arguments = $this->_resolve_dependency(
1352
+					$class_name,
1353
+					$param_class,
1354
+					$arguments,
1355
+					$index
1356
+				);
1357
+			}
1358
+			if (empty($arguments[ $index ])) {
1359
+				$arguments[ $index ] = $this->mirror->getParameterDefaultValue(
1360
+					$param,
1361
+					$class_name,
1362
+					$index
1363
+				);
1364
+			}
1365
+		}
1366
+		return $arguments;
1367
+	}
1368
+
1369
+
1370
+	/**
1371
+	 * @param string $class_name
1372
+	 * @param string $param_class
1373
+	 * @param array  $arguments
1374
+	 * @param mixed  $index
1375
+	 * @return array
1376
+	 * @throws InvalidArgumentException
1377
+	 * @throws InvalidInterfaceException
1378
+	 * @throws InvalidDataTypeException
1379
+	 */
1380
+	protected function _resolve_dependency($class_name, $param_class, $arguments, $index)
1381
+	{
1382
+		$dependency = null;
1383
+		// should dependency be loaded from cache ?
1384
+		$cache_on = $this->_dependency_map->loading_strategy_for_class_dependency(
1385
+			$class_name,
1386
+			$param_class
1387
+		);
1388
+		$cache_on = $cache_on !== EE_Dependency_Map::load_new_object;
1389
+		// we might have a dependency...
1390
+		// let's MAYBE try and find it in our cache if that's what's been requested
1391
+		$cached_class = $cache_on
1392
+			? $this->_get_cached_class($param_class)
1393
+			: null;
1394
+		// and grab it if it exists
1395
+		if ($cached_class instanceof $param_class) {
1396
+			$dependency = $cached_class;
1397
+		} elseif ($param_class !== $class_name) {
1398
+			// obtain the loader method from the dependency map
1399
+			$loader = $this->_dependency_map->class_loader($param_class);
1400
+			// is loader a custom closure ?
1401
+			if ($loader instanceof Closure) {
1402
+				$dependency = $loader($arguments);
1403
+			} else {
1404
+				// set the cache on property for the recursive loading call
1405
+				$this->_cache_on = $cache_on;
1406
+				// if not, then let's try and load it via the registry
1407
+				if ($loader && method_exists($this, $loader)) {
1408
+					$dependency = $this->{$loader}($param_class);
1409
+				} else {
1410
+					$dependency = LoaderFactory::getLoader()->load(
1411
+						$param_class,
1412
+						array(),
1413
+						$cache_on
1414
+					);
1415
+				}
1416
+			}
1417
+		}
1418
+		// did we successfully find the correct dependency ?
1419
+		if ($dependency instanceof $param_class) {
1420
+			// then let's inject it into the incoming array of arguments at the correct location
1421
+			$arguments[ $index ] = $dependency;
1422
+		}
1423
+		return $arguments;
1424
+	}
1425
+
1426
+
1427
+	/**
1428
+	 * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1429
+	 *
1430
+	 * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1431
+	 *                          in the EE_Dependency_Map::$_class_loaders array,
1432
+	 *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1433
+	 * @param array  $arguments
1434
+	 * @return object
1435
+	 */
1436
+	public static function factory($classname, $arguments = array())
1437
+	{
1438
+		$loader = self::instance()->_dependency_map->class_loader($classname);
1439
+		if ($loader instanceof Closure) {
1440
+			return $loader($arguments);
1441
+		}
1442
+		if (method_exists(self::instance(), $loader)) {
1443
+			return self::instance()->{$loader}($classname, $arguments);
1444
+		}
1445
+		return null;
1446
+	}
1447
+
1448
+
1449
+	/**
1450
+	 * Gets the addon by its class name
1451
+	 *
1452
+	 * @param string $class_name
1453
+	 * @return EE_Addon
1454
+	 */
1455
+	public function getAddon($class_name)
1456
+	{
1457
+		$class_name = str_replace('\\', '_', $class_name);
1458
+		if (isset($this->addons->{$class_name})) {
1459
+			return $this->addons->{$class_name};
1460
+		} else {
1461
+			return null;
1462
+		}
1463
+	}
1464
+
1465
+
1466
+	/**
1467
+	 * removes the addon from the internal cache
1468
+	 *
1469
+	 * @param string $class_name
1470
+	 * @return void
1471
+	 */
1472
+	public function removeAddon($class_name)
1473
+	{
1474
+		$class_name = str_replace('\\', '_', $class_name);
1475
+		unset($this->addons->{$class_name});
1476
+	}
1477
+
1478
+
1479
+	/**
1480
+	 * Gets the addon by its name/slug (not classname. For that, just
1481
+	 * use the get_addon() method above
1482
+	 *
1483
+	 * @param string $name
1484
+	 * @return EE_Addon
1485
+	 */
1486
+	public function get_addon_by_name($name)
1487
+	{
1488
+		foreach ($this->addons as $addon) {
1489
+			if ($addon->name() === $name) {
1490
+				return $addon;
1491
+			}
1492
+		}
1493
+		return null;
1494
+	}
1495
+
1496
+
1497
+	/**
1498
+	 * Gets an array of all the registered addons, where the keys are their names.
1499
+	 * (ie, what each returns for their name() function)
1500
+	 * They're already available on EE_Registry::instance()->addons as properties,
1501
+	 * where each property's name is the addon's classname,
1502
+	 * So if you just want to get the addon by classname,
1503
+	 * OR use the get_addon() method above.
1504
+	 * PLEASE  NOTE:
1505
+	 * addons with Fully Qualified Class Names
1506
+	 * have had the namespace separators converted to underscores,
1507
+	 * so a classname like Fully\Qualified\ClassName
1508
+	 * would have been converted to Fully_Qualified_ClassName
1509
+	 *
1510
+	 * @return EE_Addon[] where the KEYS are the addon's name()
1511
+	 */
1512
+	public function get_addons_by_name()
1513
+	{
1514
+		$addons = array();
1515
+		foreach ($this->addons as $addon) {
1516
+			$addons[ $addon->name() ] = $addon;
1517
+		}
1518
+		return $addons;
1519
+	}
1520
+
1521
+
1522
+	/**
1523
+	 * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1524
+	 * a stale copy of it around
1525
+	 *
1526
+	 * @param string $model_name
1527
+	 * @return \EEM_Base
1528
+	 * @throws \EE_Error
1529
+	 */
1530
+	public function reset_model($model_name)
1531
+	{
1532
+		$model_class_name = strpos($model_name, 'EEM_') !== 0
1533
+			? "EEM_{$model_name}"
1534
+			: $model_name;
1535
+		if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1536
+			return null;
1537
+		}
1538
+		// get that model reset it and make sure we nuke the old reference to it
1539
+		if ($this->LIB->{$model_class_name} instanceof $model_class_name
1540
+			&& is_callable(
1541
+				array($model_class_name, 'reset')
1542
+			)) {
1543
+			$this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1544
+		} else {
1545
+			throw new EE_Error(
1546
+				sprintf(
1547
+					esc_html__('Model %s does not have a method "reset"', 'event_espresso'),
1548
+					$model_name
1549
+				)
1550
+			);
1551
+		}
1552
+		return $this->LIB->{$model_class_name};
1553
+	}
1554
+
1555
+
1556
+	/**
1557
+	 * Resets the registry.
1558
+	 * The criteria for what gets reset is based on what can be shared between sites on the same request when
1559
+	 * switch_to_blog is used in a multisite install.  Here is a list of things that are NOT reset.
1560
+	 * - $_dependency_map
1561
+	 * - $_class_abbreviations
1562
+	 * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1563
+	 * - $REQ:  Still on the same request so no need to change.
1564
+	 * - $CAP: There is no site specific state in the EE_Capability class.
1565
+	 * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only
1566
+	 * one Session can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1567
+	 * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1568
+	 *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1569
+	 *             switch or on the restore.
1570
+	 * - $modules
1571
+	 * - $shortcodes
1572
+	 * - $widgets
1573
+	 *
1574
+	 * @param boolean $hard             [deprecated]
1575
+	 * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1576
+	 *                                  or just reset without re-instantiating (handy to set to FALSE if you're not
1577
+	 *                                  sure if you CAN currently reinstantiate the singletons at the moment)
1578
+	 * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so
1579
+	 *                                  client
1580
+	 *                                  code instead can just change the model context to a different blog id if
1581
+	 *                                  necessary
1582
+	 * @return EE_Registry
1583
+	 * @throws InvalidInterfaceException
1584
+	 * @throws InvalidDataTypeException
1585
+	 * @throws EE_Error
1586
+	 * @throws ReflectionException
1587
+	 * @throws InvalidArgumentException
1588
+	 */
1589
+	public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1590
+	{
1591
+		$instance = self::instance();
1592
+		$instance->_cache_on = true;
1593
+		// reset some "special" classes
1594
+		EEH_Activation::reset();
1595
+		$hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard);
1596
+		$instance->CFG = EE_Config::reset($hard, $reinstantiate);
1597
+		$instance->CART = null;
1598
+		$instance->MRM = null;
1599
+		$instance->AssetsRegistry = LoaderFactory::getLoader()->getShared(
1600
+			'EventEspresso\core\services\assets\Registry'
1601
+		);
1602
+		// messages reset
1603
+		EED_Messages::reset();
1604
+		// handle of objects cached on LIB
1605
+		foreach (array('LIB', 'modules') as $cache) {
1606
+			foreach ($instance->{$cache} as $class_name => $class) {
1607
+				if (self::_reset_and_unset_object($class, $reset_models)) {
1608
+					unset($instance->{$cache}->{$class_name});
1609
+				}
1610
+			}
1611
+		}
1612
+		return $instance;
1613
+	}
1614
+
1615
+
1616
+	/**
1617
+	 * if passed object implements ResettableInterface, then call it's reset() method
1618
+	 * if passed object implements InterminableInterface, then return false,
1619
+	 * to indicate that it should NOT be cleared from the Registry cache
1620
+	 *
1621
+	 * @param      $object
1622
+	 * @param bool $reset_models
1623
+	 * @return bool returns true if cached object should be unset
1624
+	 */
1625
+	private static function _reset_and_unset_object($object, $reset_models)
1626
+	{
1627
+		if (! is_object($object)) {
1628
+			// don't unset anything that's not an object
1629
+			return false;
1630
+		}
1631
+		if ($object instanceof EED_Module) {
1632
+			$object::reset();
1633
+			// don't unset modules
1634
+			return false;
1635
+		}
1636
+		if ($object instanceof ResettableInterface) {
1637
+			if ($object instanceof EEM_Base) {
1638
+				if ($reset_models) {
1639
+					$object->reset();
1640
+					return true;
1641
+				}
1642
+				return false;
1643
+			}
1644
+			$object->reset();
1645
+			return true;
1646
+		}
1647
+		if (! $object instanceof InterminableInterface) {
1648
+			return true;
1649
+		}
1650
+		return false;
1651
+	}
1652
+
1653
+
1654
+	/**
1655
+	 * Gets all the custom post type models defined
1656
+	 *
1657
+	 * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1658
+	 */
1659
+	public function cpt_models()
1660
+	{
1661
+		$cpt_models = array();
1662
+		foreach ($this->non_abstract_db_models as $short_name => $classname) {
1663
+			if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1664
+				$cpt_models[ $short_name ] = $classname;
1665
+			}
1666
+		}
1667
+		return $cpt_models;
1668
+	}
1669
+
1670
+
1671
+	/**
1672
+	 * @return \EE_Config
1673
+	 */
1674
+	public static function CFG()
1675
+	{
1676
+		return self::instance()->CFG;
1677
+	}
1678
+
1679
+
1680
+	/**
1681
+	 * @deprecated 4.9.62.p
1682
+	 * @param string $class_name
1683
+	 * @return ReflectionClass
1684
+	 * @throws ReflectionException
1685
+	 * @throws InvalidDataTypeException
1686
+	 */
1687
+	public function get_ReflectionClass($class_name)
1688
+	{
1689
+		return $this->mirror->getReflectionClass($class_name);
1690
+	}
1691 1691
 }
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
         ObjectIdentifier $object_identifier = null
194 194
     ) {
195 195
         // check if class object is instantiated
196
-        if (! self::$_instance instanceof EE_Registry
196
+        if ( ! self::$_instance instanceof EE_Registry
197 197
             && $dependency_map instanceof EE_Dependency_Map
198 198
             && $mirror instanceof Mirror
199 199
             && $class_cache instanceof ClassInterfaceCache
@@ -308,10 +308,10 @@  discard block
 block discarded – undo
308 308
         $i18n_js_strings = (array) self::$i18n_js_strings;
309 309
         foreach ($i18n_js_strings as $key => $value) {
310 310
             if (is_scalar($value)) {
311
-                $i18n_js_strings[ $key ] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
311
+                $i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
312 312
             }
313 313
         }
314
-        return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
314
+        return '/* <![CDATA[ */ var eei18n = '.wp_json_encode($i18n_js_strings).'; /* ]]> */';
315 315
     }
316 316
 
317 317
 
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
             $module_class = get_class($module);
331 331
             $this->modules->{$module_class} = $module;
332 332
         } else {
333
-            if (! class_exists('EE_Module_Request_Router', false)) {
333
+            if ( ! class_exists('EE_Module_Request_Router', false)) {
334 334
                 $this->load_core('Module_Request_Router');
335 335
             }
336 336
             EE_Module_Request_Router::module_factory($module);
@@ -371,10 +371,10 @@  discard block
 block discarded – undo
371 371
                 EE_CORE,
372 372
                 EE_ADMIN,
373 373
                 EE_CPTS,
374
-                EE_CORE . 'data_migration_scripts' . DS,
375
-                EE_CORE . 'capabilities' . DS,
376
-                EE_CORE . 'request_stack' . DS,
377
-                EE_CORE . 'middleware' . DS,
374
+                EE_CORE.'data_migration_scripts'.DS,
375
+                EE_CORE.'capabilities'.DS,
376
+                EE_CORE.'request_stack'.DS,
377
+                EE_CORE.'middleware'.DS,
378 378
             )
379 379
         );
380 380
         // retrieve instantiated class
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
         $service_paths = apply_filters(
410 410
             'FHEE__EE_Registry__load_service__service_paths',
411 411
             array(
412
-                EE_CORE . 'services' . DS,
412
+                EE_CORE.'services'.DS,
413 413
             )
414 414
         );
415 415
         // retrieve instantiated class
@@ -544,10 +544,10 @@  discard block
 block discarded – undo
544 544
     {
545 545
         $paths = array(
546 546
             EE_LIBRARIES,
547
-            EE_LIBRARIES . 'messages' . DS,
548
-            EE_LIBRARIES . 'shortcodes' . DS,
549
-            EE_LIBRARIES . 'qtips' . DS,
550
-            EE_LIBRARIES . 'payment_methods' . DS,
547
+            EE_LIBRARIES.'messages'.DS,
548
+            EE_LIBRARIES.'shortcodes'.DS,
549
+            EE_LIBRARIES.'qtips'.DS,
550
+            EE_LIBRARIES.'payment_methods'.DS,
551 551
         );
552 552
         // retrieve instantiated class
553 553
         return $this->_load(
@@ -615,10 +615,10 @@  discard block
 block discarded – undo
615 615
     public function load_model_class($class_name, $arguments = array(), $load_only = true)
616 616
     {
617 617
         $paths = array(
618
-            EE_MODELS . 'fields' . DS,
619
-            EE_MODELS . 'helpers' . DS,
620
-            EE_MODELS . 'relations' . DS,
621
-            EE_MODELS . 'strategies' . DS,
618
+            EE_MODELS.'fields'.DS,
619
+            EE_MODELS.'helpers'.DS,
620
+            EE_MODELS.'relations'.DS,
621
+            EE_MODELS.'strategies'.DS,
622 622
         );
623 623
         // retrieve instantiated class
624 624
         return $this->_load(
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
      */
643 643
     public function is_model_name($model_name)
644 644
     {
645
-        return isset($this->models[ $model_name ]);
645
+        return isset($this->models[$model_name]);
646 646
     }
647 647
 
648 648
 
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
                 return $cached_class;
764 764
             }
765 765
         }// obtain the loader method from the dependency map
766
-        $loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object
766
+        $loader = $this->_dependency_map->class_loader($class_name); // instantiate the requested object
767 767
         if ($loader instanceof Closure) {
768 768
             $class_obj = $loader($arguments);
769 769
         } else {
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
             case 1:
806 806
                 // if it's a FQCN then maybe the class is registered with a preceding \
807 807
                 $class_name = strpos($class_name, '\\') !== false
808
-                    ? '\\' . ltrim($class_name, '\\')
808
+                    ? '\\'.ltrim($class_name, '\\')
809 809
                     : $class_name;
810 810
                 break;
811 811
             case 2:
@@ -859,11 +859,11 @@  discard block
 block discarded – undo
859 859
         // strip php file extension
860 860
         $class_name = str_replace('.php', '', trim($class_name));
861 861
         // does the class have a prefix ?
862
-        if (! empty($class_prefix) && $class_prefix !== 'addon') {
862
+        if ( ! empty($class_prefix) && $class_prefix !== 'addon') {
863 863
             // make sure $class_prefix is uppercase
864 864
             $class_prefix = strtoupper(trim($class_prefix));
865 865
             // add class prefix ONCE!!!
866
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
866
+            $class_name = $class_prefix.str_replace($class_prefix, '', $class_name);
867 867
         }
868 868
         $class_name = $this->class_cache->getFqnForAlias($class_name);
869 869
         $class_exists = class_exists($class_name, false);
@@ -883,7 +883,7 @@  discard block
 block discarded – undo
883 883
             }
884 884
         }
885 885
         // if the class doesn't already exist.. then we need to try and find the file and load it
886
-        if (! $class_exists) {
886
+        if ( ! $class_exists) {
887 887
             // get full path to file
888 888
             $path = $this->_resolve_path($class_name, $type, $file_paths);
889 889
             // load the file
@@ -894,7 +894,7 @@  discard block
 block discarded – undo
894 894
                 return $loaded;
895 895
             }
896 896
             // if an object was expected but loading failed, then return nothing
897
-            if (! $loaded) {
897
+            if ( ! $loaded) {
898 898
                 return null;
899 899
             }
900 900
         }
@@ -922,8 +922,8 @@  discard block
 block discarded – undo
922 922
      */
923 923
     protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS')
924 924
     {
925
-        return isset($this->_class_abbreviations[ $class_name ])
926
-            ? $this->_class_abbreviations[ $class_name ]
925
+        return isset($this->_class_abbreviations[$class_name])
926
+            ? $this->_class_abbreviations[$class_name]
927 927
             : $default;
928 928
     }
929 929
 
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
             $this->addons->{$class_name} = $class_obj;
1057 1057
             return;
1058 1058
         }
1059
-        if (! $from_db) {
1059
+        if ( ! $from_db) {
1060 1060
             $class_name = $this->object_identifier->getIdentifier($class_name, $arguments);
1061 1061
             $this->LIB->{$class_name} = $class_obj;
1062 1062
         }
@@ -1087,13 +1087,13 @@  discard block
 block discarded – undo
1087 1087
                 : EE_CLASSES;
1088 1088
             // prep file type
1089 1089
             $type = ! empty($type)
1090
-                ? trim($type, '.') . '.'
1090
+                ? trim($type, '.').'.'
1091 1091
                 : '';
1092 1092
             // build full file path
1093
-            $file_paths[ $key ] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
1093
+            $file_paths[$key] = rtrim($file_path, DS).DS.$class_name.'.'.$type.'php';
1094 1094
             // does the file exist and can be read ?
1095
-            if (is_readable($file_paths[ $key ])) {
1096
-                return $file_paths[ $key ];
1095
+            if (is_readable($file_paths[$key])) {
1096
+                return $file_paths[$key];
1097 1097
             }
1098 1098
         }
1099 1099
         return false;
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
         // don't give up! you gotta...
1119 1119
         try {
1120 1120
             // does the file exist and can it be read ?
1121
-            if (! $path) {
1121
+            if ( ! $path) {
1122 1122
                 // just in case the file has already been autoloaded,
1123 1123
                 // but discrepancies in the naming schema are preventing it from
1124 1124
                 // being loaded via one of the EE_Registry::load_*() methods,
@@ -1136,7 +1136,7 @@  discard block
 block discarded – undo
1136 1136
                         ),
1137 1137
                         trim($type, '.'),
1138 1138
                         $class_name,
1139
-                        '<br />' . implode(',<br />', $file_paths)
1139
+                        '<br />'.implode(',<br />', $file_paths)
1140 1140
                     )
1141 1141
                 );
1142 1142
             }
@@ -1179,8 +1179,8 @@  discard block
 block discarded – undo
1179 1179
             $legacy_parent_class_map = array(
1180 1180
                 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php',
1181 1181
             );
1182
-            if (isset($legacy_parent_class_map[ $class_name ])) {
1183
-                require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ];
1182
+            if (isset($legacy_parent_class_map[$class_name])) {
1183
+                require_once EE_PLUGIN_DIR_PATH.$legacy_parent_class_map[$class_name];
1184 1184
             }
1185 1185
         } catch (Exception $exception) {
1186 1186
         }
@@ -1312,7 +1312,7 @@  discard block
 block discarded – undo
1312 1312
         // let's examine the constructor
1313 1313
         $constructor = $this->mirror->getConstructorFromReflection($reflector);
1314 1314
         // whu? huh? nothing?
1315
-        if (! $constructor) {
1315
+        if ( ! $constructor) {
1316 1316
             return $arguments;
1317 1317
         }
1318 1318
         // get constructor parameters
@@ -1331,15 +1331,15 @@  discard block
 block discarded – undo
1331 1331
                 $param_class === null
1332 1332
                 // and something already exists in the incoming arguments for this param
1333 1333
                 && array_key_exists($index, $argument_keys)
1334
-                && array_key_exists($argument_keys[ $index ], $arguments)
1334
+                && array_key_exists($argument_keys[$index], $arguments)
1335 1335
             ) {
1336 1336
                 // so let's skip this argument and move on to the next
1337 1337
                 continue;
1338 1338
             }
1339 1339
             if (// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1340 1340
                 $param_class !== null
1341
-                && isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ])
1342
-                && $arguments[ $argument_keys[ $index ] ] instanceof $param_class
1341
+                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1342
+                && $arguments[$argument_keys[$index]] instanceof $param_class
1343 1343
             ) {
1344 1344
                 // skip this argument and move on to the next
1345 1345
                 continue;
@@ -1355,8 +1355,8 @@  discard block
 block discarded – undo
1355 1355
                     $index
1356 1356
                 );
1357 1357
             }
1358
-            if (empty($arguments[ $index ])) {
1359
-                $arguments[ $index ] = $this->mirror->getParameterDefaultValue(
1358
+            if (empty($arguments[$index])) {
1359
+                $arguments[$index] = $this->mirror->getParameterDefaultValue(
1360 1360
                     $param,
1361 1361
                     $class_name,
1362 1362
                     $index
@@ -1418,7 +1418,7 @@  discard block
 block discarded – undo
1418 1418
         // did we successfully find the correct dependency ?
1419 1419
         if ($dependency instanceof $param_class) {
1420 1420
             // then let's inject it into the incoming array of arguments at the correct location
1421
-            $arguments[ $index ] = $dependency;
1421
+            $arguments[$index] = $dependency;
1422 1422
         }
1423 1423
         return $arguments;
1424 1424
     }
@@ -1513,7 +1513,7 @@  discard block
 block discarded – undo
1513 1513
     {
1514 1514
         $addons = array();
1515 1515
         foreach ($this->addons as $addon) {
1516
-            $addons[ $addon->name() ] = $addon;
1516
+            $addons[$addon->name()] = $addon;
1517 1517
         }
1518 1518
         return $addons;
1519 1519
     }
@@ -1532,7 +1532,7 @@  discard block
 block discarded – undo
1532 1532
         $model_class_name = strpos($model_name, 'EEM_') !== 0
1533 1533
             ? "EEM_{$model_name}"
1534 1534
             : $model_name;
1535
-        if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1535
+        if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1536 1536
             return null;
1537 1537
         }
1538 1538
         // get that model reset it and make sure we nuke the old reference to it
@@ -1624,7 +1624,7 @@  discard block
 block discarded – undo
1624 1624
      */
1625 1625
     private static function _reset_and_unset_object($object, $reset_models)
1626 1626
     {
1627
-        if (! is_object($object)) {
1627
+        if ( ! is_object($object)) {
1628 1628
             // don't unset anything that's not an object
1629 1629
             return false;
1630 1630
         }
@@ -1644,7 +1644,7 @@  discard block
 block discarded – undo
1644 1644
             $object->reset();
1645 1645
             return true;
1646 1646
         }
1647
-        if (! $object instanceof InterminableInterface) {
1647
+        if ( ! $object instanceof InterminableInterface) {
1648 1648
             return true;
1649 1649
         }
1650 1650
         return false;
@@ -1661,7 +1661,7 @@  discard block
 block discarded – undo
1661 1661
         $cpt_models = array();
1662 1662
         foreach ($this->non_abstract_db_models as $short_name => $classname) {
1663 1663
             if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1664
-                $cpt_models[ $short_name ] = $classname;
1664
+                $cpt_models[$short_name] = $classname;
1665 1665
             }
1666 1666
         }
1667 1667
         return $cpt_models;
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.71.rc.008');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.71.rc.008');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/ModelDataTranslator.php 2 patches
Indentation   +967 added lines, -967 removed lines patch added patch discarded remove patch
@@ -32,1011 +32,1011 @@
 block discarded – undo
32 32
 class ModelDataTranslator
33 33
 {
34 34
 
35
-    /**
36
-     * We used to use -1 for infinity in the rest api, but that's ambiguous for
37
-     * fields that COULD contain -1; so we use null
38
-     */
39
-    const EE_INF_IN_REST = null;
35
+	/**
36
+	 * We used to use -1 for infinity in the rest api, but that's ambiguous for
37
+	 * fields that COULD contain -1; so we use null
38
+	 */
39
+	const EE_INF_IN_REST = null;
40 40
 
41 41
 
42
-    /**
43
-     * Prepares a possible array of input values from JSON for use by the models
44
-     *
45
-     * @param EE_Model_Field_Base $field_obj
46
-     * @param mixed               $original_value_maybe_array
47
-     * @param string              $requested_version
48
-     * @param string              $timezone_string treat values as being in this timezone
49
-     * @return mixed
50
-     * @throws RestException
51
-     */
52
-    public static function prepareFieldValuesFromJson(
53
-        $field_obj,
54
-        $original_value_maybe_array,
55
-        $requested_version,
56
-        $timezone_string = 'UTC'
57
-    ) {
58
-        if (is_array($original_value_maybe_array)
59
-            && ! $field_obj instanceof EE_Serialized_Text_Field
60
-        ) {
61
-            $new_value_maybe_array = array();
62
-            foreach ($original_value_maybe_array as $array_key => $array_item) {
63
-                $new_value_maybe_array[ $array_key ] = ModelDataTranslator::prepareFieldValueFromJson(
64
-                    $field_obj,
65
-                    $array_item,
66
-                    $requested_version,
67
-                    $timezone_string
68
-                );
69
-            }
70
-        } else {
71
-            $new_value_maybe_array = ModelDataTranslator::prepareFieldValueFromJson(
72
-                $field_obj,
73
-                $original_value_maybe_array,
74
-                $requested_version,
75
-                $timezone_string
76
-            );
77
-        }
78
-        return $new_value_maybe_array;
79
-    }
42
+	/**
43
+	 * Prepares a possible array of input values from JSON for use by the models
44
+	 *
45
+	 * @param EE_Model_Field_Base $field_obj
46
+	 * @param mixed               $original_value_maybe_array
47
+	 * @param string              $requested_version
48
+	 * @param string              $timezone_string treat values as being in this timezone
49
+	 * @return mixed
50
+	 * @throws RestException
51
+	 */
52
+	public static function prepareFieldValuesFromJson(
53
+		$field_obj,
54
+		$original_value_maybe_array,
55
+		$requested_version,
56
+		$timezone_string = 'UTC'
57
+	) {
58
+		if (is_array($original_value_maybe_array)
59
+			&& ! $field_obj instanceof EE_Serialized_Text_Field
60
+		) {
61
+			$new_value_maybe_array = array();
62
+			foreach ($original_value_maybe_array as $array_key => $array_item) {
63
+				$new_value_maybe_array[ $array_key ] = ModelDataTranslator::prepareFieldValueFromJson(
64
+					$field_obj,
65
+					$array_item,
66
+					$requested_version,
67
+					$timezone_string
68
+				);
69
+			}
70
+		} else {
71
+			$new_value_maybe_array = ModelDataTranslator::prepareFieldValueFromJson(
72
+				$field_obj,
73
+				$original_value_maybe_array,
74
+				$requested_version,
75
+				$timezone_string
76
+			);
77
+		}
78
+		return $new_value_maybe_array;
79
+	}
80 80
 
81 81
 
82
-    /**
83
-     * Prepares an array of field values FOR use in JSON/REST API
84
-     *
85
-     * @param EE_Model_Field_Base $field_obj
86
-     * @param mixed               $original_value_maybe_array
87
-     * @param string              $request_version (eg 4.8.36)
88
-     * @return array
89
-     */
90
-    public static function prepareFieldValuesForJson($field_obj, $original_value_maybe_array, $request_version)
91
-    {
92
-        if (is_array($original_value_maybe_array)) {
93
-            $new_value = array();
94
-            foreach ($original_value_maybe_array as $key => $value) {
95
-                $new_value[ $key ] = ModelDataTranslator::prepareFieldValuesForJson(
96
-                    $field_obj,
97
-                    $value,
98
-                    $request_version
99
-                );
100
-            }
101
-        } else {
102
-            $new_value = ModelDataTranslator::prepareFieldValueForJson(
103
-                $field_obj,
104
-                $original_value_maybe_array,
105
-                $request_version
106
-            );
107
-        }
108
-        return $new_value;
109
-    }
82
+	/**
83
+	 * Prepares an array of field values FOR use in JSON/REST API
84
+	 *
85
+	 * @param EE_Model_Field_Base $field_obj
86
+	 * @param mixed               $original_value_maybe_array
87
+	 * @param string              $request_version (eg 4.8.36)
88
+	 * @return array
89
+	 */
90
+	public static function prepareFieldValuesForJson($field_obj, $original_value_maybe_array, $request_version)
91
+	{
92
+		if (is_array($original_value_maybe_array)) {
93
+			$new_value = array();
94
+			foreach ($original_value_maybe_array as $key => $value) {
95
+				$new_value[ $key ] = ModelDataTranslator::prepareFieldValuesForJson(
96
+					$field_obj,
97
+					$value,
98
+					$request_version
99
+				);
100
+			}
101
+		} else {
102
+			$new_value = ModelDataTranslator::prepareFieldValueForJson(
103
+				$field_obj,
104
+				$original_value_maybe_array,
105
+				$request_version
106
+			);
107
+		}
108
+		return $new_value;
109
+	}
110 110
 
111 111
 
112
-    /**
113
-     * Prepares incoming data from the json or $_REQUEST parameters for the models'
114
-     * "$query_params".
115
-     *
116
-     * @param EE_Model_Field_Base $field_obj
117
-     * @param mixed               $original_value
118
-     * @param string              $requested_version
119
-     * @param string              $timezone_string treat values as being in this timezone
120
-     * @return mixed
121
-     * @throws RestException
122
-     * @throws DomainException
123
-     * @throws EE_Error
124
-     */
125
-    public static function prepareFieldValueFromJson(
126
-        $field_obj,
127
-        $original_value,
128
-        $requested_version,
129
-        $timezone_string = 'UTC' // UTC
130
-    ) {
131
-        // check if they accidentally submitted an error value. If so throw an exception
132
-        if (is_array($original_value)
133
-            && isset($original_value['error_code'], $original_value['error_message'])) {
134
-            throw new RestException(
135
-                'rest_submitted_error_value',
136
-                sprintf(
137
-                    esc_html__(
138
-                        'You tried to submit a JSON error object as a value for %1$s. That\'s not allowed.',
139
-                        'event_espresso'
140
-                    ),
141
-                    $field_obj->get_name()
142
-                ),
143
-                array(
144
-                    'status' => 400,
145
-                )
146
-            );
147
-        }
148
-        // double-check for serialized PHP. We never accept serialized PHP. No way Jose.
149
-        ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value);
150
-        $timezone_string = $timezone_string !== '' ? $timezone_string : get_option('timezone_string', '');
151
-        $new_value = null;
152
-        // walk through the submitted data and double-check for serialized PHP. We never accept serialized PHP. No
153
-        // way Jose.
154
-        ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value);
155
-        if ($field_obj instanceof EE_Infinite_Integer_Field
156
-            && in_array($original_value, array(null, ''), true)
157
-        ) {
158
-            $new_value = EE_INF;
159
-        } elseif ($field_obj instanceof EE_Datetime_Field) {
160
-            $new_value = rest_parse_date(
161
-                self::getTimestampWithTimezoneOffset($original_value, $field_obj, $timezone_string)
162
-            );
163
-            if ($new_value === false) {
164
-                throw new RestException(
165
-                    'invalid_format_for_timestamp',
166
-                    sprintf(
167
-                        esc_html__(
168
-                            'Timestamps received on a request as the value for Date and Time fields must be in %1$s/%2$s format.  The timestamp provided (%3$s) is not that format.',
169
-                            'event_espresso'
170
-                        ),
171
-                        'RFC3339',
172
-                        'ISO8601',
173
-                        $original_value
174
-                    ),
175
-                    array(
176
-                        'status' => 400,
177
-                    )
178
-                );
179
-            }
180
-        } else {
181
-            $new_value = $original_value;
182
-        }
183
-        return $new_value;
184
-    }
112
+	/**
113
+	 * Prepares incoming data from the json or $_REQUEST parameters for the models'
114
+	 * "$query_params".
115
+	 *
116
+	 * @param EE_Model_Field_Base $field_obj
117
+	 * @param mixed               $original_value
118
+	 * @param string              $requested_version
119
+	 * @param string              $timezone_string treat values as being in this timezone
120
+	 * @return mixed
121
+	 * @throws RestException
122
+	 * @throws DomainException
123
+	 * @throws EE_Error
124
+	 */
125
+	public static function prepareFieldValueFromJson(
126
+		$field_obj,
127
+		$original_value,
128
+		$requested_version,
129
+		$timezone_string = 'UTC' // UTC
130
+	) {
131
+		// check if they accidentally submitted an error value. If so throw an exception
132
+		if (is_array($original_value)
133
+			&& isset($original_value['error_code'], $original_value['error_message'])) {
134
+			throw new RestException(
135
+				'rest_submitted_error_value',
136
+				sprintf(
137
+					esc_html__(
138
+						'You tried to submit a JSON error object as a value for %1$s. That\'s not allowed.',
139
+						'event_espresso'
140
+					),
141
+					$field_obj->get_name()
142
+				),
143
+				array(
144
+					'status' => 400,
145
+				)
146
+			);
147
+		}
148
+		// double-check for serialized PHP. We never accept serialized PHP. No way Jose.
149
+		ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value);
150
+		$timezone_string = $timezone_string !== '' ? $timezone_string : get_option('timezone_string', '');
151
+		$new_value = null;
152
+		// walk through the submitted data and double-check for serialized PHP. We never accept serialized PHP. No
153
+		// way Jose.
154
+		ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value);
155
+		if ($field_obj instanceof EE_Infinite_Integer_Field
156
+			&& in_array($original_value, array(null, ''), true)
157
+		) {
158
+			$new_value = EE_INF;
159
+		} elseif ($field_obj instanceof EE_Datetime_Field) {
160
+			$new_value = rest_parse_date(
161
+				self::getTimestampWithTimezoneOffset($original_value, $field_obj, $timezone_string)
162
+			);
163
+			if ($new_value === false) {
164
+				throw new RestException(
165
+					'invalid_format_for_timestamp',
166
+					sprintf(
167
+						esc_html__(
168
+							'Timestamps received on a request as the value for Date and Time fields must be in %1$s/%2$s format.  The timestamp provided (%3$s) is not that format.',
169
+							'event_espresso'
170
+						),
171
+						'RFC3339',
172
+						'ISO8601',
173
+						$original_value
174
+					),
175
+					array(
176
+						'status' => 400,
177
+					)
178
+				);
179
+			}
180
+		} else {
181
+			$new_value = $original_value;
182
+		}
183
+		return $new_value;
184
+	}
185 185
 
186 186
 
187
-    /**
188
-     * This checks if the incoming timestamp has timezone information already on it and if it doesn't then adds timezone
189
-     * information via details obtained from the host site.
190
-     *
191
-     * @param string            $original_timestamp
192
-     * @param EE_Datetime_Field $datetime_field
193
-     * @param                   $timezone_string
194
-     * @return string
195
-     * @throws DomainException
196
-     */
197
-    private static function getTimestampWithTimezoneOffset(
198
-        $original_timestamp,
199
-        EE_Datetime_Field $datetime_field,
200
-        $timezone_string
201
-    ) {
202
-        // already have timezone information?
203
-        if (preg_match('/Z|(\+|\-)(\d{2}:\d{2})/', $original_timestamp)) {
204
-            // yes, we're ignoring the timezone.
205
-            return $original_timestamp;
206
-        }
207
-        // need to append timezone
208
-        list($offset_sign, $offset_secs) = self::parseTimezoneOffset(
209
-            $datetime_field->get_timezone_offset(
210
-                new \DateTimeZone($timezone_string),
211
-                $original_timestamp
212
-            )
213
-        );
214
-        $offset_string =
215
-            str_pad(
216
-                floor($offset_secs / HOUR_IN_SECONDS),
217
-                2,
218
-                '0',
219
-                STR_PAD_LEFT
220
-            )
221
-            . ':'
222
-            . str_pad(
223
-                ($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS,
224
-                2,
225
-                '0',
226
-                STR_PAD_LEFT
227
-            );
228
-        return $original_timestamp . $offset_sign . $offset_string;
229
-    }
187
+	/**
188
+	 * This checks if the incoming timestamp has timezone information already on it and if it doesn't then adds timezone
189
+	 * information via details obtained from the host site.
190
+	 *
191
+	 * @param string            $original_timestamp
192
+	 * @param EE_Datetime_Field $datetime_field
193
+	 * @param                   $timezone_string
194
+	 * @return string
195
+	 * @throws DomainException
196
+	 */
197
+	private static function getTimestampWithTimezoneOffset(
198
+		$original_timestamp,
199
+		EE_Datetime_Field $datetime_field,
200
+		$timezone_string
201
+	) {
202
+		// already have timezone information?
203
+		if (preg_match('/Z|(\+|\-)(\d{2}:\d{2})/', $original_timestamp)) {
204
+			// yes, we're ignoring the timezone.
205
+			return $original_timestamp;
206
+		}
207
+		// need to append timezone
208
+		list($offset_sign, $offset_secs) = self::parseTimezoneOffset(
209
+			$datetime_field->get_timezone_offset(
210
+				new \DateTimeZone($timezone_string),
211
+				$original_timestamp
212
+			)
213
+		);
214
+		$offset_string =
215
+			str_pad(
216
+				floor($offset_secs / HOUR_IN_SECONDS),
217
+				2,
218
+				'0',
219
+				STR_PAD_LEFT
220
+			)
221
+			. ':'
222
+			. str_pad(
223
+				($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS,
224
+				2,
225
+				'0',
226
+				STR_PAD_LEFT
227
+			);
228
+		return $original_timestamp . $offset_sign . $offset_string;
229
+	}
230 230
 
231 231
 
232
-    /**
233
-     * Throws an exception if $data is a serialized PHP string (or somehow an actually PHP object, although I don't
234
-     * think that can happen). If $data is an array, recurses into its keys and values
235
-     *
236
-     * @param mixed $data
237
-     * @throws RestException
238
-     * @return void
239
-     */
240
-    public static function throwExceptionIfContainsSerializedData($data)
241
-    {
242
-        if (is_array($data)) {
243
-            foreach ($data as $key => $value) {
244
-                ModelDataTranslator::throwExceptionIfContainsSerializedData($key);
245
-                ModelDataTranslator::throwExceptionIfContainsSerializedData($value);
246
-            }
247
-        } else {
248
-            if (is_serialized($data) || is_object($data)) {
249
-                throw new RestException(
250
-                    'serialized_data_submission_prohibited',
251
-                    esc_html__(
252
-                    // @codingStandardsIgnoreStart
253
-                        'You tried to submit a string of serialized text. Serialized PHP is prohibited over the EE4 REST API.',
254
-                        // @codingStandardsIgnoreEnd
255
-                        'event_espresso'
256
-                    )
257
-                );
258
-            }
259
-        }
260
-    }
232
+	/**
233
+	 * Throws an exception if $data is a serialized PHP string (or somehow an actually PHP object, although I don't
234
+	 * think that can happen). If $data is an array, recurses into its keys and values
235
+	 *
236
+	 * @param mixed $data
237
+	 * @throws RestException
238
+	 * @return void
239
+	 */
240
+	public static function throwExceptionIfContainsSerializedData($data)
241
+	{
242
+		if (is_array($data)) {
243
+			foreach ($data as $key => $value) {
244
+				ModelDataTranslator::throwExceptionIfContainsSerializedData($key);
245
+				ModelDataTranslator::throwExceptionIfContainsSerializedData($value);
246
+			}
247
+		} else {
248
+			if (is_serialized($data) || is_object($data)) {
249
+				throw new RestException(
250
+					'serialized_data_submission_prohibited',
251
+					esc_html__(
252
+					// @codingStandardsIgnoreStart
253
+						'You tried to submit a string of serialized text. Serialized PHP is prohibited over the EE4 REST API.',
254
+						// @codingStandardsIgnoreEnd
255
+						'event_espresso'
256
+					)
257
+				);
258
+			}
259
+		}
260
+	}
261 261
 
262 262
 
263
-    /**
264
-     * determines what's going on with them timezone strings
265
-     *
266
-     * @param int $timezone_offset
267
-     * @return array
268
-     */
269
-    private static function parseTimezoneOffset($timezone_offset)
270
-    {
271
-        $first_char = substr((string) $timezone_offset, 0, 1);
272
-        if ($first_char === '+' || $first_char === '-') {
273
-            $offset_sign = $first_char;
274
-            $offset_secs = substr((string) $timezone_offset, 1);
275
-        } else {
276
-            $offset_sign = '+';
277
-            $offset_secs = $timezone_offset;
278
-        }
279
-        return array($offset_sign, $offset_secs);
280
-    }
263
+	/**
264
+	 * determines what's going on with them timezone strings
265
+	 *
266
+	 * @param int $timezone_offset
267
+	 * @return array
268
+	 */
269
+	private static function parseTimezoneOffset($timezone_offset)
270
+	{
271
+		$first_char = substr((string) $timezone_offset, 0, 1);
272
+		if ($first_char === '+' || $first_char === '-') {
273
+			$offset_sign = $first_char;
274
+			$offset_secs = substr((string) $timezone_offset, 1);
275
+		} else {
276
+			$offset_sign = '+';
277
+			$offset_secs = $timezone_offset;
278
+		}
279
+		return array($offset_sign, $offset_secs);
280
+	}
281 281
 
282 282
 
283
-    /**
284
-     * Prepares a field's value for display in the API
285
-     *
286
-     * @param EE_Model_Field_Base $field_obj
287
-     * @param mixed               $original_value
288
-     * @param string              $requested_version
289
-     * @return mixed
290
-     */
291
-    public static function prepareFieldValueForJson($field_obj, $original_value, $requested_version)
292
-    {
293
-        if ($original_value === EE_INF) {
294
-            $new_value = ModelDataTranslator::EE_INF_IN_REST;
295
-        } elseif ($field_obj instanceof EE_Datetime_Field) {
296
-            if (is_string($original_value)) {
297
-                // did they submit a string of a unix timestamp?
298
-                if (is_numeric($original_value)) {
299
-                    $datetime_obj = new \DateTime();
300
-                    $datetime_obj->setTimestamp((int) $original_value);
301
-                } else {
302
-                    // first, check if its a MySQL timestamp in GMT
303
-                    $datetime_obj = \DateTime::createFromFormat('Y-m-d H:i:s', $original_value);
304
-                }
305
-                if (! $datetime_obj instanceof \DateTime) {
306
-                    // so it's not a unix timestamp or a MySQL timestamp. Maybe its in the field's date/time format?
307
-                    $datetime_obj = $field_obj->prepare_for_set($original_value);
308
-                }
309
-                $original_value = $datetime_obj;
310
-            }
311
-            if ($original_value instanceof \DateTime) {
312
-                $new_value = $original_value->format('Y-m-d H:i:s');
313
-            } elseif (is_int($original_value) || is_float($original_value)) {
314
-                $new_value = date('Y-m-d H:i:s', $original_value);
315
-            } elseif ($original_value === null || $original_value === '') {
316
-                $new_value = null;
317
-            } else {
318
-                // so it's not a datetime object, unix timestamp (as string or int),
319
-                // MySQL timestamp, or even a string in the field object's format. So no idea what it is
320
-                throw new \EE_Error(
321
-                    sprintf(
322
-                        esc_html__(
323
-                        // @codingStandardsIgnoreStart
324
-                            'The value "%1$s" for the field "%2$s" on model "%3$s" could not be understood. It should be a PHP DateTime, unix timestamp, MySQL date, or string in the format "%4$s".',
325
-                            // @codingStandardsIgnoreEnd
326
-                            'event_espresso'
327
-                        ),
328
-                        $original_value,
329
-                        $field_obj->get_name(),
330
-                        $field_obj->get_model_name(),
331
-                        $field_obj->get_time_format() . ' ' . $field_obj->get_time_format()
332
-                    )
333
-                );
334
-            }
335
-            if ($new_value !== null) {
336
-                $new_value = mysql_to_rfc3339($new_value);
337
-            }
338
-        } else {
339
-            $new_value = $original_value;
340
-        }
341
-        // are we about to send an object? just don't. We have no good way to represent it in JSON.
342
-        // can't just check using is_object() because that missed PHP incomplete objects
343
-        if (! ModelDataTranslator::isRepresentableInJson($new_value)) {
344
-            $new_value = array(
345
-                'error_code'    => 'php_object_not_return',
346
-                'error_message' => esc_html__(
347
-                    'The value of this field in the database is a PHP object, which can\'t be represented in JSON.',
348
-                    'event_espresso'
349
-                ),
350
-            );
351
-        }
352
-        return apply_filters(
353
-            'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api',
354
-            $new_value,
355
-            $field_obj,
356
-            $original_value,
357
-            $requested_version
358
-        );
359
-    }
283
+	/**
284
+	 * Prepares a field's value for display in the API
285
+	 *
286
+	 * @param EE_Model_Field_Base $field_obj
287
+	 * @param mixed               $original_value
288
+	 * @param string              $requested_version
289
+	 * @return mixed
290
+	 */
291
+	public static function prepareFieldValueForJson($field_obj, $original_value, $requested_version)
292
+	{
293
+		if ($original_value === EE_INF) {
294
+			$new_value = ModelDataTranslator::EE_INF_IN_REST;
295
+		} elseif ($field_obj instanceof EE_Datetime_Field) {
296
+			if (is_string($original_value)) {
297
+				// did they submit a string of a unix timestamp?
298
+				if (is_numeric($original_value)) {
299
+					$datetime_obj = new \DateTime();
300
+					$datetime_obj->setTimestamp((int) $original_value);
301
+				} else {
302
+					// first, check if its a MySQL timestamp in GMT
303
+					$datetime_obj = \DateTime::createFromFormat('Y-m-d H:i:s', $original_value);
304
+				}
305
+				if (! $datetime_obj instanceof \DateTime) {
306
+					// so it's not a unix timestamp or a MySQL timestamp. Maybe its in the field's date/time format?
307
+					$datetime_obj = $field_obj->prepare_for_set($original_value);
308
+				}
309
+				$original_value = $datetime_obj;
310
+			}
311
+			if ($original_value instanceof \DateTime) {
312
+				$new_value = $original_value->format('Y-m-d H:i:s');
313
+			} elseif (is_int($original_value) || is_float($original_value)) {
314
+				$new_value = date('Y-m-d H:i:s', $original_value);
315
+			} elseif ($original_value === null || $original_value === '') {
316
+				$new_value = null;
317
+			} else {
318
+				// so it's not a datetime object, unix timestamp (as string or int),
319
+				// MySQL timestamp, or even a string in the field object's format. So no idea what it is
320
+				throw new \EE_Error(
321
+					sprintf(
322
+						esc_html__(
323
+						// @codingStandardsIgnoreStart
324
+							'The value "%1$s" for the field "%2$s" on model "%3$s" could not be understood. It should be a PHP DateTime, unix timestamp, MySQL date, or string in the format "%4$s".',
325
+							// @codingStandardsIgnoreEnd
326
+							'event_espresso'
327
+						),
328
+						$original_value,
329
+						$field_obj->get_name(),
330
+						$field_obj->get_model_name(),
331
+						$field_obj->get_time_format() . ' ' . $field_obj->get_time_format()
332
+					)
333
+				);
334
+			}
335
+			if ($new_value !== null) {
336
+				$new_value = mysql_to_rfc3339($new_value);
337
+			}
338
+		} else {
339
+			$new_value = $original_value;
340
+		}
341
+		// are we about to send an object? just don't. We have no good way to represent it in JSON.
342
+		// can't just check using is_object() because that missed PHP incomplete objects
343
+		if (! ModelDataTranslator::isRepresentableInJson($new_value)) {
344
+			$new_value = array(
345
+				'error_code'    => 'php_object_not_return',
346
+				'error_message' => esc_html__(
347
+					'The value of this field in the database is a PHP object, which can\'t be represented in JSON.',
348
+					'event_espresso'
349
+				),
350
+			);
351
+		}
352
+		return apply_filters(
353
+			'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api',
354
+			$new_value,
355
+			$field_obj,
356
+			$original_value,
357
+			$requested_version
358
+		);
359
+	}
360 360
 
361 361
 
362
-    /**
363
-     * Prepares condition-query-parameters (like what's in where and having) from
364
-     * the format expected in the API to use in the models
365
-     *
366
-     * @param array $inputted_query_params_of_this_type
367
-     * @param EEM_Base $model
368
-     * @param string $requested_version
369
-     * @param boolean $writing whether this data will be written to the DB, or if we're just building a query.
370
-     *                          If we're writing to the DB, we don't expect any operators, or any logic query
371
-     *                          parameters, and we also won't accept serialized data unless the current user has
372
-     *                          unfiltered_html.
373
-     * @return array
374
-     * @throws DomainException
375
-     * @throws EE_Error
376
-     * @throws RestException
377
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
378
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
379
-     * @throws \InvalidArgumentException
380
-     */
381
-    public static function prepareConditionsQueryParamsForModels(
382
-        $inputted_query_params_of_this_type,
383
-        EEM_Base $model,
384
-        $requested_version,
385
-        $writing = false
386
-    ) {
387
-        $query_param_for_models = array();
388
-        foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
389
-            list(
390
-                $field,
391
-                $query_param_key,
392
-                $query_param_sans_stars,
393
-                $timezone,
394
-                $is_gmt_datetime_field
395
-                ) = self::determineFieldAndTimezone(
396
-                    $model,
397
-                    $query_param_key
398
-                );
399
-            if ($field instanceof EE_Model_Field_Base) {
400
-                $translated_value = self::determineConditionsQueryParameterValue(
401
-                    $model,
402
-                    $field,
403
-                    $requested_version,
404
-                    $timezone,
405
-                    $query_param_key,
406
-                    $query_param_value,
407
-                    $writing
408
-                );
409
-                if ((isset($query_param_for_models[ $query_param_key ]) && $is_gmt_datetime_field)
410
-                    || $translated_value === null
411
-                ) {
412
-                    // they have already provided a non-gmt field, ignore the gmt one. That's what WP core
413
-                    // currently does (they might change it though). See https://core.trac.wordpress.org/ticket/39954
414
-                    // OR we couldn't create a translated value from their input
415
-                    continue;
416
-                }
417
-                $query_param_for_models[ $query_param_key ] = $translated_value;
418
-            } else {
419
-                $nested_query_params = self::determineNestedConditionQueryParameters(
420
-                    $model,
421
-                    $query_param_key,
422
-                    $query_param_sans_stars,
423
-                    $query_param_value,
424
-                    $requested_version,
425
-                    $writing
426
-                );
427
-                if ($nested_query_params) {
428
-                    $query_param_for_models[ $query_param_key ] = $nested_query_params;
429
-                }
430
-            }
431
-        }
432
-        return $query_param_for_models;
433
-    }
362
+	/**
363
+	 * Prepares condition-query-parameters (like what's in where and having) from
364
+	 * the format expected in the API to use in the models
365
+	 *
366
+	 * @param array $inputted_query_params_of_this_type
367
+	 * @param EEM_Base $model
368
+	 * @param string $requested_version
369
+	 * @param boolean $writing whether this data will be written to the DB, or if we're just building a query.
370
+	 *                          If we're writing to the DB, we don't expect any operators, or any logic query
371
+	 *                          parameters, and we also won't accept serialized data unless the current user has
372
+	 *                          unfiltered_html.
373
+	 * @return array
374
+	 * @throws DomainException
375
+	 * @throws EE_Error
376
+	 * @throws RestException
377
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
378
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
379
+	 * @throws \InvalidArgumentException
380
+	 */
381
+	public static function prepareConditionsQueryParamsForModels(
382
+		$inputted_query_params_of_this_type,
383
+		EEM_Base $model,
384
+		$requested_version,
385
+		$writing = false
386
+	) {
387
+		$query_param_for_models = array();
388
+		foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
389
+			list(
390
+				$field,
391
+				$query_param_key,
392
+				$query_param_sans_stars,
393
+				$timezone,
394
+				$is_gmt_datetime_field
395
+				) = self::determineFieldAndTimezone(
396
+					$model,
397
+					$query_param_key
398
+				);
399
+			if ($field instanceof EE_Model_Field_Base) {
400
+				$translated_value = self::determineConditionsQueryParameterValue(
401
+					$model,
402
+					$field,
403
+					$requested_version,
404
+					$timezone,
405
+					$query_param_key,
406
+					$query_param_value,
407
+					$writing
408
+				);
409
+				if ((isset($query_param_for_models[ $query_param_key ]) && $is_gmt_datetime_field)
410
+					|| $translated_value === null
411
+				) {
412
+					// they have already provided a non-gmt field, ignore the gmt one. That's what WP core
413
+					// currently does (they might change it though). See https://core.trac.wordpress.org/ticket/39954
414
+					// OR we couldn't create a translated value from their input
415
+					continue;
416
+				}
417
+				$query_param_for_models[ $query_param_key ] = $translated_value;
418
+			} else {
419
+				$nested_query_params = self::determineNestedConditionQueryParameters(
420
+					$model,
421
+					$query_param_key,
422
+					$query_param_sans_stars,
423
+					$query_param_value,
424
+					$requested_version,
425
+					$writing
426
+				);
427
+				if ($nested_query_params) {
428
+					$query_param_for_models[ $query_param_key ] = $nested_query_params;
429
+				}
430
+			}
431
+		}
432
+		return $query_param_for_models;
433
+	}
434 434
 
435
-    /**
436
-     * If the query param isn't for a field, it must be a nested query parameter which requires different logic.
437
-     * @since $VID:$
438
-     * @param EEM_Base $model
439
-     * @param $query_param_key
440
-     * @param $query_param_sans_stars
441
-     * @param $query_param_value
442
-     * @param $requested_version
443
-     * @param $writing
444
-     * @return array
445
-     * @throws DomainException
446
-     * @throws EE_Error
447
-     * @throws RestException
448
-     */
449
-    private static function determineNestedConditionQueryParameters(
450
-        EEM_Base $model,
451
-        $query_param_key,
452
-        $query_param_sans_stars,
453
-        $query_param_value,
454
-        $requested_version,
455
-        $writing
456
-    ) {
435
+	/**
436
+	 * If the query param isn't for a field, it must be a nested query parameter which requires different logic.
437
+	 * @since $VID:$
438
+	 * @param EEM_Base $model
439
+	 * @param $query_param_key
440
+	 * @param $query_param_sans_stars
441
+	 * @param $query_param_value
442
+	 * @param $requested_version
443
+	 * @param $writing
444
+	 * @return array
445
+	 * @throws DomainException
446
+	 * @throws EE_Error
447
+	 * @throws RestException
448
+	 */
449
+	private static function determineNestedConditionQueryParameters(
450
+		EEM_Base $model,
451
+		$query_param_key,
452
+		$query_param_sans_stars,
453
+		$query_param_value,
454
+		$requested_version,
455
+		$writing
456
+	) {
457 457
 
458
-        // so this param doesn't correspond to a field eh?
459
-        if ($writing) {
460
-            // always tell API clients about invalid parameters when they're creating data. Otherwise,
461
-            // they are probably going to create invalid data
462
-            throw new RestException(
463
-                'invalid_field',
464
-                sprintf(
465
-                    /* translators: 1: variable name */
466
-                    esc_html__('You have provided an invalid parameter: "%1$s"', 'event_espresso'),
467
-                    $query_param_key
468
-                )
469
-            );
470
-        } else {
471
-            // so it's not for a field, is it a logic query param key?
472
-            if (in_array(
473
-                $query_param_sans_stars,
474
-                $model->logic_query_param_keys()
475
-            )) {
476
-                return ModelDataTranslator::prepareConditionsQueryParamsForModels(
477
-                    $query_param_value,
478
-                    $model,
479
-                    $requested_version
480
-                );
481
-            } elseif (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) {
482
-                // only tell API clients they got it wrong if we're in debug mode
483
-                // otherwise try our best ot fulfill their request by ignoring this invalid data
484
-                throw new RestException(
485
-                    'invalid_parameter',
486
-                    sprintf(
487
-                        /* translators: 1: variable name */
488
-                        esc_html__(
489
-                            'You provided an invalid parameter, with key "%1$s"',
490
-                            'event_espresso'
491
-                        ),
492
-                        $query_param_key
493
-                    ),
494
-                    array(
495
-                        'status' => 400,
496
-                    )
497
-                );
498
-            }
499
-        }
500
-        return null;
501
-    }
458
+		// so this param doesn't correspond to a field eh?
459
+		if ($writing) {
460
+			// always tell API clients about invalid parameters when they're creating data. Otherwise,
461
+			// they are probably going to create invalid data
462
+			throw new RestException(
463
+				'invalid_field',
464
+				sprintf(
465
+					/* translators: 1: variable name */
466
+					esc_html__('You have provided an invalid parameter: "%1$s"', 'event_espresso'),
467
+					$query_param_key
468
+				)
469
+			);
470
+		} else {
471
+			// so it's not for a field, is it a logic query param key?
472
+			if (in_array(
473
+				$query_param_sans_stars,
474
+				$model->logic_query_param_keys()
475
+			)) {
476
+				return ModelDataTranslator::prepareConditionsQueryParamsForModels(
477
+					$query_param_value,
478
+					$model,
479
+					$requested_version
480
+				);
481
+			} elseif (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) {
482
+				// only tell API clients they got it wrong if we're in debug mode
483
+				// otherwise try our best ot fulfill their request by ignoring this invalid data
484
+				throw new RestException(
485
+					'invalid_parameter',
486
+					sprintf(
487
+						/* translators: 1: variable name */
488
+						esc_html__(
489
+							'You provided an invalid parameter, with key "%1$s"',
490
+							'event_espresso'
491
+						),
492
+						$query_param_key
493
+					),
494
+					array(
495
+						'status' => 400,
496
+					)
497
+				);
498
+			}
499
+		}
500
+		return null;
501
+	}
502 502
 
503
-    /**
504
-     * Determines what field, query param name, and query param name without stars, and timezone to use.
505
-     * @since $VID:$
506
-     * @param EEM_Base $model
507
-     * @param $query_param_sans_stars
508
-     * @return array {
509
-     * @type EE_Model_Field_Base $field
510
-     * @type string $query_param_key
511
-     * @type string $query_param_sans_stars
512
-     * @type string $timezone
513
-     * @type boolean $is_gmt_datetime_field
514
-     * }
515
-     * @throws EE_Error
516
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
517
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
518
-     * @throws \InvalidArgumentException
519
-     */
520
-    private static function determineFieldAndTimezone(EEM_Base $model, $query_param_key)
521
-    {
522
-        $query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey(
523
-            $query_param_key
524
-        );
525
-        $is_gmt_datetime_field = false;
526
-        $field = ModelDataTranslator::deduceFieldFromQueryParam(
527
-            $query_param_sans_stars,
528
-            $model
529
-        );
530
-        // double-check is it a *_gmt field?
531
-        if (! $field instanceof EE_Model_Field_Base
532
-            && ModelDataTranslator::isGmtDateFieldName($query_param_sans_stars)
533
-        ) {
534
-            // yep, take off '_gmt', and find the field
535
-            $query_param_key = ModelDataTranslator::removeGmtFromFieldName($query_param_sans_stars);
536
-            $field = ModelDataTranslator::deduceFieldFromQueryParam(
537
-                $query_param_key,
538
-                $model
539
-            );
540
-            $timezone = 'UTC';
541
-            $is_gmt_datetime_field = true;
542
-        } elseif ($field instanceof EE_Datetime_Field) {
543
-            // so it's not a GMT field. Set the timezone on the model to the default
544
-            $timezone = \EEH_DTT_Helper::get_valid_timezone_string();
545
-        } else {
546
-            // just keep using what's already set for the timezone
547
-            $timezone = $model->get_timezone();
548
-        }
549
-        return array(
550
-            $field,
551
-            $query_param_key,
552
-            $query_param_sans_stars,
553
-            $timezone,
554
-            $is_gmt_datetime_field
555
-        );
556
-    }
503
+	/**
504
+	 * Determines what field, query param name, and query param name without stars, and timezone to use.
505
+	 * @since $VID:$
506
+	 * @param EEM_Base $model
507
+	 * @param $query_param_sans_stars
508
+	 * @return array {
509
+	 * @type EE_Model_Field_Base $field
510
+	 * @type string $query_param_key
511
+	 * @type string $query_param_sans_stars
512
+	 * @type string $timezone
513
+	 * @type boolean $is_gmt_datetime_field
514
+	 * }
515
+	 * @throws EE_Error
516
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
517
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
518
+	 * @throws \InvalidArgumentException
519
+	 */
520
+	private static function determineFieldAndTimezone(EEM_Base $model, $query_param_key)
521
+	{
522
+		$query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey(
523
+			$query_param_key
524
+		);
525
+		$is_gmt_datetime_field = false;
526
+		$field = ModelDataTranslator::deduceFieldFromQueryParam(
527
+			$query_param_sans_stars,
528
+			$model
529
+		);
530
+		// double-check is it a *_gmt field?
531
+		if (! $field instanceof EE_Model_Field_Base
532
+			&& ModelDataTranslator::isGmtDateFieldName($query_param_sans_stars)
533
+		) {
534
+			// yep, take off '_gmt', and find the field
535
+			$query_param_key = ModelDataTranslator::removeGmtFromFieldName($query_param_sans_stars);
536
+			$field = ModelDataTranslator::deduceFieldFromQueryParam(
537
+				$query_param_key,
538
+				$model
539
+			);
540
+			$timezone = 'UTC';
541
+			$is_gmt_datetime_field = true;
542
+		} elseif ($field instanceof EE_Datetime_Field) {
543
+			// so it's not a GMT field. Set the timezone on the model to the default
544
+			$timezone = \EEH_DTT_Helper::get_valid_timezone_string();
545
+		} else {
546
+			// just keep using what's already set for the timezone
547
+			$timezone = $model->get_timezone();
548
+		}
549
+		return array(
550
+			$field,
551
+			$query_param_key,
552
+			$query_param_sans_stars,
553
+			$timezone,
554
+			$is_gmt_datetime_field
555
+		);
556
+	}
557 557
 
558
-    /**
559
-     * Given a ton of input, determines the value to use for the models.
560
-     * @since $VID:$
561
-     * @param EEM_Base $model
562
-     * @param EE_Model_Field_Base $field
563
-     * @param $requested_version
564
-     * @param $timezone
565
-     * @param $query_param_key
566
-     * @param $query_param_value
567
-     * @param bool $writing
568
-     * @return array|null
569
-     * @throws DomainException
570
-     * @throws EE_Error
571
-     * @throws RestException
572
-     */
573
-    private static function determineConditionsQueryParameterValue(
574
-        EEM_Base $model,
575
-        EE_Model_Field_Base $field,
576
-        $requested_version,
577
-        $timezone,
578
-        $query_param_key,
579
-        $query_param_value,
580
-        $writing = false
581
-    ) {
582
-        if (! $writing && is_array($query_param_value)) {
583
-            if (! \EEH_Array::is_array_numerically_and_sequentially_indexed($query_param_value)) {
584
-                if (is_array($query_param_value)
585
-                    && count($query_param_value) === 1
586
-                    && array_key_exists(
587
-                        key($query_param_value),
588
-                        $model->valid_operators()
589
-                    )
590
-                ) {
591
-                    $sub_array_value =  reset($query_param_value);
592
-                    $sub_array_key = key($query_param_value);
593
-                    if (is_array($sub_array_value) && defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) {
594
-                        throw new RestException(
595
-                            'csv_or_json_string_only',
596
-                            sprintf(
597
-                                /* translators: 1: variable name*/
598
-                                esc_html__(
599
-                                    'The value provided for the operator "%1$s" should be comma-separated value string or a JSON array.',
600
-                                    'event_espresso'
601
-                                ),
602
-                                $sub_array_key
603
-                            ),
604
-                            array(
605
-                                'status' => 400,
606
-                            )
607
-                        );
608
-                    }
609
-                    // they're doing something like "&where[EVT_ID][IN]=1,2,3" or "&where[EVT_ID][>]=5"
610
-                    if (array_key_exists(
611
-                        $sub_array_key,
612
-                        array_merge(
613
-                            $model->valid_in_style_operators(),
614
-                            $model->valid_between_style_operators()
615
-                        )
616
-                    )) {
617
-                        // the value should be JSON or CSV
618
-                        $values = json_decode($sub_array_value);
619
-                        if (! is_array($values)) {
620
-                            $values = array_filter(
621
-                                array_map(
622
-                                    'trim',
623
-                                    explode(
624
-                                        ',',
625
-                                        $sub_array_value
626
-                                    )
627
-                                )
628
-                            );
629
-                        }
630
-                        $query_param_value = array(
631
-                            $sub_array_key,
632
-                            $values
633
-                        );
634
-                    } elseif (array_key_exists(
635
-                        $sub_array_key,
636
-                        $model->valid_null_style_operators()
637
-                    )) {
638
-                        $query_param_value = array($sub_array_key);
639
-                    } else {
640
-                        $query_param_value = array($sub_array_key, $sub_array_value);
641
-                    }
642
-                } elseif (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) {
643
-                    throw new RestException(
644
-                        'numerically_indexed_array_of_values_only',
645
-                        sprintf(
646
-                            /* translators: 1: variable name*/
647
-                            esc_html__(
648
-                                'The array provided for the parameter "%1$s" should be numerically indexed.',
649
-                                'event_espresso'
650
-                            ),
651
-                            $query_param_key
652
-                        ),
653
-                        array(
654
-                            'status' => 400,
655
-                        )
656
-                    );
657
-                }
658
-            }
659
-            $valid_operators = $model->valid_operators();
660
-            // did they specify an operator?
661
-            if (isset($query_param_value[0])
662
-                && isset($valid_operators[ $query_param_value[0] ])
663
-            ) {
664
-                $sub_array_key = $query_param_value[0];
665
-                $translated_value = array($sub_array_key);
666
-                if (array_key_exists($sub_array_key, $model->valid_in_style_operators())
667
-                    && isset($query_param_value[1])
668
-                    && ! isset($query_param_value[2])
669
-                ) {
670
-                    $translated_value[] = ModelDataTranslator::prepareFieldValuesFromJson(
671
-                        $field,
672
-                        $query_param_value[1],
673
-                        $requested_version,
674
-                        $timezone
675
-                    );
676
-                } elseif (array_key_exists($sub_array_key, $model->valid_between_style_operators())
677
-                    && isset($query_param_value[1])
678
-                    && is_array($query_param_value[1])
679
-                    && isset($query_param_key[1][0], $query_param_value[1][1])
680
-                    && ! isset($query_param_value[1][2])
681
-                    && ! isset($query_param_value[2])
682
-                ) {
683
-                    $translated_value[] = array(
684
-                        ModelDataTranslator::prepareFieldValuesFromJson(
685
-                            $field,
686
-                            $query_param_value[1][0],
687
-                            $requested_version,
688
-                            $timezone
689
-                        ),
690
-                        ModelDataTranslator::prepareFieldValuesFromJson(
691
-                            $field,
692
-                            $query_param_value[1][1],
693
-                            $requested_version,
694
-                            $timezone
695
-                        )
696
-                    );
697
-                } elseif (array_key_exists($sub_array_key, $model->valid_like_style_operators())
698
-                    && isset($query_param_value[1])
699
-                    && ! isset($query_param_value[2])
700
-                ) {
701
-                    // we want to leave this value mostly-as-is (eg don't force it to be a float
702
-                    // or a boolean or an enum value. Leave it as-is with wildcards etc)
703
-                    // but do verify it at least doesn't have any serialized data
704
-                    ModelDataTranslator::throwExceptionIfContainsSerializedData($query_param_value[1]);
705
-                    $translated_value[] = $query_param_value[1];
706
-                } elseif (array_key_exists($sub_array_key, $model->valid_null_style_operators())
707
-                    && ! isset($query_param_value[1])) {
708
-                    // no arguments should have been provided, so don't look for any
709
-                } elseif (isset($query_param_value[1])
710
-                    && ! isset($query_param_value[2])
711
-                    && ! array_key_exists(
712
-                        $sub_array_key,
713
-                        array_merge(
714
-                            $model->valid_in_style_operators(),
715
-                            $model->valid_null_style_operators(),
716
-                            $model->valid_like_style_operators(),
717
-                            $model->valid_between_style_operators()
718
-                        )
719
-                    )
720
-                ) {
721
-                    // it's a valid operator, but none of the exceptions. Treat it normally.
722
-                    $translated_value[] = ModelDataTranslator::prepareFieldValuesFromJson(
723
-                        $field,
724
-                        $query_param_value[1],
725
-                        $requested_version,
726
-                        $timezone
727
-                    );
728
-                } else {
729
-                    // so they provided a valid operator, but wrong number of arguments
730
-                    if (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) {
731
-                        throw new RestException(
732
-                            'wrong_number_of_arguments',
733
-                            sprintf(
734
-                                esc_html__(
735
-                                    'The operator you provided, "%1$s" had the wrong number of arguments',
736
-                                    'event_espresso'
737
-                                ),
738
-                                $sub_array_key
739
-                            ),
740
-                            array(
741
-                                'status' => 400,
742
-                            )
743
-                        );
744
-                    }
745
-                    $translated_value = null;
746
-                }
747
-            } else {
748
-                // so they didn't provide a valid operator
749
-                if (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) {
750
-                    throw new RestException(
751
-                        'invalid_operator',
752
-                        sprintf(
753
-                            esc_html__(
754
-                                'You provided an invalid parameter, with key "%1$s" and value "%2$s"',
755
-                                'event_espresso'
756
-                            ),
757
-                            $query_param_key,
758
-                            $query_param_value
759
-                        ),
760
-                        array(
761
-                            'status' => 400,
762
-                        )
763
-                    );
764
-                }
765
-                // if we aren't in debug mode, then just try our best to fulfill the user's request
766
-                $translated_value = null;
767
-            }
768
-        } else {
769
-            $translated_value = ModelDataTranslator::prepareFieldValueFromJson(
770
-                $field,
771
-                $query_param_value,
772
-                $requested_version,
773
-                $timezone
774
-            );
775
-        }
776
-        return $translated_value;
777
-    }
558
+	/**
559
+	 * Given a ton of input, determines the value to use for the models.
560
+	 * @since $VID:$
561
+	 * @param EEM_Base $model
562
+	 * @param EE_Model_Field_Base $field
563
+	 * @param $requested_version
564
+	 * @param $timezone
565
+	 * @param $query_param_key
566
+	 * @param $query_param_value
567
+	 * @param bool $writing
568
+	 * @return array|null
569
+	 * @throws DomainException
570
+	 * @throws EE_Error
571
+	 * @throws RestException
572
+	 */
573
+	private static function determineConditionsQueryParameterValue(
574
+		EEM_Base $model,
575
+		EE_Model_Field_Base $field,
576
+		$requested_version,
577
+		$timezone,
578
+		$query_param_key,
579
+		$query_param_value,
580
+		$writing = false
581
+	) {
582
+		if (! $writing && is_array($query_param_value)) {
583
+			if (! \EEH_Array::is_array_numerically_and_sequentially_indexed($query_param_value)) {
584
+				if (is_array($query_param_value)
585
+					&& count($query_param_value) === 1
586
+					&& array_key_exists(
587
+						key($query_param_value),
588
+						$model->valid_operators()
589
+					)
590
+				) {
591
+					$sub_array_value =  reset($query_param_value);
592
+					$sub_array_key = key($query_param_value);
593
+					if (is_array($sub_array_value) && defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) {
594
+						throw new RestException(
595
+							'csv_or_json_string_only',
596
+							sprintf(
597
+								/* translators: 1: variable name*/
598
+								esc_html__(
599
+									'The value provided for the operator "%1$s" should be comma-separated value string or a JSON array.',
600
+									'event_espresso'
601
+								),
602
+								$sub_array_key
603
+							),
604
+							array(
605
+								'status' => 400,
606
+							)
607
+						);
608
+					}
609
+					// they're doing something like "&where[EVT_ID][IN]=1,2,3" or "&where[EVT_ID][>]=5"
610
+					if (array_key_exists(
611
+						$sub_array_key,
612
+						array_merge(
613
+							$model->valid_in_style_operators(),
614
+							$model->valid_between_style_operators()
615
+						)
616
+					)) {
617
+						// the value should be JSON or CSV
618
+						$values = json_decode($sub_array_value);
619
+						if (! is_array($values)) {
620
+							$values = array_filter(
621
+								array_map(
622
+									'trim',
623
+									explode(
624
+										',',
625
+										$sub_array_value
626
+									)
627
+								)
628
+							);
629
+						}
630
+						$query_param_value = array(
631
+							$sub_array_key,
632
+							$values
633
+						);
634
+					} elseif (array_key_exists(
635
+						$sub_array_key,
636
+						$model->valid_null_style_operators()
637
+					)) {
638
+						$query_param_value = array($sub_array_key);
639
+					} else {
640
+						$query_param_value = array($sub_array_key, $sub_array_value);
641
+					}
642
+				} elseif (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) {
643
+					throw new RestException(
644
+						'numerically_indexed_array_of_values_only',
645
+						sprintf(
646
+							/* translators: 1: variable name*/
647
+							esc_html__(
648
+								'The array provided for the parameter "%1$s" should be numerically indexed.',
649
+								'event_espresso'
650
+							),
651
+							$query_param_key
652
+						),
653
+						array(
654
+							'status' => 400,
655
+						)
656
+					);
657
+				}
658
+			}
659
+			$valid_operators = $model->valid_operators();
660
+			// did they specify an operator?
661
+			if (isset($query_param_value[0])
662
+				&& isset($valid_operators[ $query_param_value[0] ])
663
+			) {
664
+				$sub_array_key = $query_param_value[0];
665
+				$translated_value = array($sub_array_key);
666
+				if (array_key_exists($sub_array_key, $model->valid_in_style_operators())
667
+					&& isset($query_param_value[1])
668
+					&& ! isset($query_param_value[2])
669
+				) {
670
+					$translated_value[] = ModelDataTranslator::prepareFieldValuesFromJson(
671
+						$field,
672
+						$query_param_value[1],
673
+						$requested_version,
674
+						$timezone
675
+					);
676
+				} elseif (array_key_exists($sub_array_key, $model->valid_between_style_operators())
677
+					&& isset($query_param_value[1])
678
+					&& is_array($query_param_value[1])
679
+					&& isset($query_param_key[1][0], $query_param_value[1][1])
680
+					&& ! isset($query_param_value[1][2])
681
+					&& ! isset($query_param_value[2])
682
+				) {
683
+					$translated_value[] = array(
684
+						ModelDataTranslator::prepareFieldValuesFromJson(
685
+							$field,
686
+							$query_param_value[1][0],
687
+							$requested_version,
688
+							$timezone
689
+						),
690
+						ModelDataTranslator::prepareFieldValuesFromJson(
691
+							$field,
692
+							$query_param_value[1][1],
693
+							$requested_version,
694
+							$timezone
695
+						)
696
+					);
697
+				} elseif (array_key_exists($sub_array_key, $model->valid_like_style_operators())
698
+					&& isset($query_param_value[1])
699
+					&& ! isset($query_param_value[2])
700
+				) {
701
+					// we want to leave this value mostly-as-is (eg don't force it to be a float
702
+					// or a boolean or an enum value. Leave it as-is with wildcards etc)
703
+					// but do verify it at least doesn't have any serialized data
704
+					ModelDataTranslator::throwExceptionIfContainsSerializedData($query_param_value[1]);
705
+					$translated_value[] = $query_param_value[1];
706
+				} elseif (array_key_exists($sub_array_key, $model->valid_null_style_operators())
707
+					&& ! isset($query_param_value[1])) {
708
+					// no arguments should have been provided, so don't look for any
709
+				} elseif (isset($query_param_value[1])
710
+					&& ! isset($query_param_value[2])
711
+					&& ! array_key_exists(
712
+						$sub_array_key,
713
+						array_merge(
714
+							$model->valid_in_style_operators(),
715
+							$model->valid_null_style_operators(),
716
+							$model->valid_like_style_operators(),
717
+							$model->valid_between_style_operators()
718
+						)
719
+					)
720
+				) {
721
+					// it's a valid operator, but none of the exceptions. Treat it normally.
722
+					$translated_value[] = ModelDataTranslator::prepareFieldValuesFromJson(
723
+						$field,
724
+						$query_param_value[1],
725
+						$requested_version,
726
+						$timezone
727
+					);
728
+				} else {
729
+					// so they provided a valid operator, but wrong number of arguments
730
+					if (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) {
731
+						throw new RestException(
732
+							'wrong_number_of_arguments',
733
+							sprintf(
734
+								esc_html__(
735
+									'The operator you provided, "%1$s" had the wrong number of arguments',
736
+									'event_espresso'
737
+								),
738
+								$sub_array_key
739
+							),
740
+							array(
741
+								'status' => 400,
742
+							)
743
+						);
744
+					}
745
+					$translated_value = null;
746
+				}
747
+			} else {
748
+				// so they didn't provide a valid operator
749
+				if (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) {
750
+					throw new RestException(
751
+						'invalid_operator',
752
+						sprintf(
753
+							esc_html__(
754
+								'You provided an invalid parameter, with key "%1$s" and value "%2$s"',
755
+								'event_espresso'
756
+							),
757
+							$query_param_key,
758
+							$query_param_value
759
+						),
760
+						array(
761
+							'status' => 400,
762
+						)
763
+					);
764
+				}
765
+				// if we aren't in debug mode, then just try our best to fulfill the user's request
766
+				$translated_value = null;
767
+			}
768
+		} else {
769
+			$translated_value = ModelDataTranslator::prepareFieldValueFromJson(
770
+				$field,
771
+				$query_param_value,
772
+				$requested_version,
773
+				$timezone
774
+			);
775
+		}
776
+		return $translated_value;
777
+	}
778 778
 
779 779
 
780
-    /**
781
-     * Mostly checks if the last 4 characters are "_gmt", indicating its a
782
-     * gmt date field name
783
-     *
784
-     * @param string $field_name
785
-     * @return boolean
786
-     */
787
-    public static function isGmtDateFieldName($field_name)
788
-    {
789
-        return substr(
790
-            ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($field_name),
791
-            -4,
792
-            4
793
-        ) === '_gmt';
794
-    }
780
+	/**
781
+	 * Mostly checks if the last 4 characters are "_gmt", indicating its a
782
+	 * gmt date field name
783
+	 *
784
+	 * @param string $field_name
785
+	 * @return boolean
786
+	 */
787
+	public static function isGmtDateFieldName($field_name)
788
+	{
789
+		return substr(
790
+			ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($field_name),
791
+			-4,
792
+			4
793
+		) === '_gmt';
794
+	}
795 795
 
796 796
 
797
-    /**
798
-     * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone)
799
-     *
800
-     * @param string $field_name
801
-     * @return string
802
-     */
803
-    public static function removeGmtFromFieldName($field_name)
804
-    {
805
-        if (! ModelDataTranslator::isGmtDateFieldName($field_name)) {
806
-            return $field_name;
807
-        }
808
-        $query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey(
809
-            $field_name
810
-        );
811
-        $query_param_sans_gmt_and_sans_stars = substr(
812
-            $query_param_sans_stars,
813
-            0,
814
-            strrpos(
815
-                $field_name,
816
-                '_gmt'
817
-            )
818
-        );
819
-        return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name);
820
-    }
797
+	/**
798
+	 * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone)
799
+	 *
800
+	 * @param string $field_name
801
+	 * @return string
802
+	 */
803
+	public static function removeGmtFromFieldName($field_name)
804
+	{
805
+		if (! ModelDataTranslator::isGmtDateFieldName($field_name)) {
806
+			return $field_name;
807
+		}
808
+		$query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey(
809
+			$field_name
810
+		);
811
+		$query_param_sans_gmt_and_sans_stars = substr(
812
+			$query_param_sans_stars,
813
+			0,
814
+			strrpos(
815
+				$field_name,
816
+				'_gmt'
817
+			)
818
+		);
819
+		return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name);
820
+	}
821 821
 
822 822
 
823
-    /**
824
-     * Takes a field name from the REST API and prepares it for the model querying
825
-     *
826
-     * @param string $field_name
827
-     * @return string
828
-     */
829
-    public static function prepareFieldNameFromJson($field_name)
830
-    {
831
-        if (ModelDataTranslator::isGmtDateFieldName($field_name)) {
832
-            return ModelDataTranslator::removeGmtFromFieldName($field_name);
833
-        }
834
-        return $field_name;
835
-    }
823
+	/**
824
+	 * Takes a field name from the REST API and prepares it for the model querying
825
+	 *
826
+	 * @param string $field_name
827
+	 * @return string
828
+	 */
829
+	public static function prepareFieldNameFromJson($field_name)
830
+	{
831
+		if (ModelDataTranslator::isGmtDateFieldName($field_name)) {
832
+			return ModelDataTranslator::removeGmtFromFieldName($field_name);
833
+		}
834
+		return $field_name;
835
+	}
836 836
 
837 837
 
838
-    /**
839
-     * Takes array of field names from REST API and prepares for models
840
-     *
841
-     * @param array $field_names
842
-     * @return array of field names (possibly include model prefixes)
843
-     */
844
-    public static function prepareFieldNamesFromJson(array $field_names)
845
-    {
846
-        $new_array = array();
847
-        foreach ($field_names as $key => $field_name) {
848
-            $new_array[ $key ] = ModelDataTranslator::prepareFieldNameFromJson($field_name);
849
-        }
850
-        return $new_array;
851
-    }
838
+	/**
839
+	 * Takes array of field names from REST API and prepares for models
840
+	 *
841
+	 * @param array $field_names
842
+	 * @return array of field names (possibly include model prefixes)
843
+	 */
844
+	public static function prepareFieldNamesFromJson(array $field_names)
845
+	{
846
+		$new_array = array();
847
+		foreach ($field_names as $key => $field_name) {
848
+			$new_array[ $key ] = ModelDataTranslator::prepareFieldNameFromJson($field_name);
849
+		}
850
+		return $new_array;
851
+	}
852 852
 
853 853
 
854
-    /**
855
-     * Takes array where array keys are field names (possibly with model path prefixes)
856
-     * from the REST API and prepares them for model querying
857
-     *
858
-     * @param array $field_names_as_keys
859
-     * @return array
860
-     */
861
-    public static function prepareFieldNamesInArrayKeysFromJson(array $field_names_as_keys)
862
-    {
863
-        $new_array = array();
864
-        foreach ($field_names_as_keys as $field_name => $value) {
865
-            $new_array[ ModelDataTranslator::prepareFieldNameFromJson($field_name) ] = $value;
866
-        }
867
-        return $new_array;
868
-    }
854
+	/**
855
+	 * Takes array where array keys are field names (possibly with model path prefixes)
856
+	 * from the REST API and prepares them for model querying
857
+	 *
858
+	 * @param array $field_names_as_keys
859
+	 * @return array
860
+	 */
861
+	public static function prepareFieldNamesInArrayKeysFromJson(array $field_names_as_keys)
862
+	{
863
+		$new_array = array();
864
+		foreach ($field_names_as_keys as $field_name => $value) {
865
+			$new_array[ ModelDataTranslator::prepareFieldNameFromJson($field_name) ] = $value;
866
+		}
867
+		return $new_array;
868
+	}
869 869
 
870 870
 
871
-    /**
872
-     * Prepares an array of model query params for use in the REST API
873
-     *
874
-     * @param array    $model_query_params
875
-     * @param EEM_Base $model
876
-     * @param string   $requested_version  eg "4.8.36". If null is provided, defaults to the latest release of the EE4
877
-     *                                     REST API
878
-     * @return array which can be passed into the EE4 REST API when querying a model resource
879
-     * @throws EE_Error
880
-     */
881
-    public static function prepareQueryParamsForRestApi(
882
-        array $model_query_params,
883
-        EEM_Base $model,
884
-        $requested_version = null
885
-    ) {
886
-        if ($requested_version === null) {
887
-            $requested_version = \EED_Core_Rest_Api::latest_rest_api_version();
888
-        }
889
-        $rest_query_params = $model_query_params;
890
-        if (isset($model_query_params[0])) {
891
-            $rest_query_params['where'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
892
-                $model_query_params[0],
893
-                $model,
894
-                $requested_version
895
-            );
896
-            unset($rest_query_params[0]);
897
-        }
898
-        if (isset($model_query_params['having'])) {
899
-            $rest_query_params['having'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
900
-                $model_query_params['having'],
901
-                $model,
902
-                $requested_version
903
-            );
904
-        }
905
-        return apply_filters(
906
-            'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api',
907
-            $rest_query_params,
908
-            $model_query_params,
909
-            $model,
910
-            $requested_version
911
-        );
912
-    }
871
+	/**
872
+	 * Prepares an array of model query params for use in the REST API
873
+	 *
874
+	 * @param array    $model_query_params
875
+	 * @param EEM_Base $model
876
+	 * @param string   $requested_version  eg "4.8.36". If null is provided, defaults to the latest release of the EE4
877
+	 *                                     REST API
878
+	 * @return array which can be passed into the EE4 REST API when querying a model resource
879
+	 * @throws EE_Error
880
+	 */
881
+	public static function prepareQueryParamsForRestApi(
882
+		array $model_query_params,
883
+		EEM_Base $model,
884
+		$requested_version = null
885
+	) {
886
+		if ($requested_version === null) {
887
+			$requested_version = \EED_Core_Rest_Api::latest_rest_api_version();
888
+		}
889
+		$rest_query_params = $model_query_params;
890
+		if (isset($model_query_params[0])) {
891
+			$rest_query_params['where'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
892
+				$model_query_params[0],
893
+				$model,
894
+				$requested_version
895
+			);
896
+			unset($rest_query_params[0]);
897
+		}
898
+		if (isset($model_query_params['having'])) {
899
+			$rest_query_params['having'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
900
+				$model_query_params['having'],
901
+				$model,
902
+				$requested_version
903
+			);
904
+		}
905
+		return apply_filters(
906
+			'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api',
907
+			$rest_query_params,
908
+			$model_query_params,
909
+			$model,
910
+			$requested_version
911
+		);
912
+	}
913 913
 
914 914
 
915
-    /**
916
-     * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api
917
-     *
918
-     * @param array    $inputted_query_params_of_this_type  eg like the "where" or "having" conditions query params
919
-     *                                                      passed into EEM_Base::get_all()
920
-     * @param EEM_Base $model
921
-     * @param string   $requested_version                   eg "4.8.36"
922
-     * @return array ready for use in the rest api query params
923
-     * @throws EE_Error
924
-     * @throws ObjectDetectedException if somehow a PHP object were in the query params' values,
925
-     *                                                      (which would be really unusual)
926
-     */
927
-    public static function prepareConditionsQueryParamsForRestApi(
928
-        $inputted_query_params_of_this_type,
929
-        EEM_Base $model,
930
-        $requested_version
931
-    ) {
932
-        $query_param_for_models = array();
933
-        foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
934
-            $field = ModelDataTranslator::deduceFieldFromQueryParam(
935
-                ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($query_param_key),
936
-                $model
937
-            );
938
-            if ($field instanceof EE_Model_Field_Base) {
939
-                // did they specify an operator?
940
-                if (is_array($query_param_value)) {
941
-                    $op = $query_param_value[0];
942
-                    $translated_value = array($op);
943
-                    if (isset($query_param_value[1])) {
944
-                        $value = $query_param_value[1];
945
-                        $translated_value[1] = ModelDataTranslator::prepareFieldValuesForJson(
946
-                            $field,
947
-                            $value,
948
-                            $requested_version
949
-                        );
950
-                    }
951
-                } else {
952
-                    $translated_value = ModelDataTranslator::prepareFieldValueForJson(
953
-                        $field,
954
-                        $query_param_value,
955
-                        $requested_version
956
-                    );
957
-                }
958
-                $query_param_for_models[ $query_param_key ] = $translated_value;
959
-            } else {
960
-                // so it's not for a field, assume it's a logic query param key
961
-                $query_param_for_models[ $query_param_key ] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
962
-                    $query_param_value,
963
-                    $model,
964
-                    $requested_version
965
-                );
966
-            }
967
-        }
968
-        return $query_param_for_models;
969
-    }
915
+	/**
916
+	 * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api
917
+	 *
918
+	 * @param array    $inputted_query_params_of_this_type  eg like the "where" or "having" conditions query params
919
+	 *                                                      passed into EEM_Base::get_all()
920
+	 * @param EEM_Base $model
921
+	 * @param string   $requested_version                   eg "4.8.36"
922
+	 * @return array ready for use in the rest api query params
923
+	 * @throws EE_Error
924
+	 * @throws ObjectDetectedException if somehow a PHP object were in the query params' values,
925
+	 *                                                      (which would be really unusual)
926
+	 */
927
+	public static function prepareConditionsQueryParamsForRestApi(
928
+		$inputted_query_params_of_this_type,
929
+		EEM_Base $model,
930
+		$requested_version
931
+	) {
932
+		$query_param_for_models = array();
933
+		foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
934
+			$field = ModelDataTranslator::deduceFieldFromQueryParam(
935
+				ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($query_param_key),
936
+				$model
937
+			);
938
+			if ($field instanceof EE_Model_Field_Base) {
939
+				// did they specify an operator?
940
+				if (is_array($query_param_value)) {
941
+					$op = $query_param_value[0];
942
+					$translated_value = array($op);
943
+					if (isset($query_param_value[1])) {
944
+						$value = $query_param_value[1];
945
+						$translated_value[1] = ModelDataTranslator::prepareFieldValuesForJson(
946
+							$field,
947
+							$value,
948
+							$requested_version
949
+						);
950
+					}
951
+				} else {
952
+					$translated_value = ModelDataTranslator::prepareFieldValueForJson(
953
+						$field,
954
+						$query_param_value,
955
+						$requested_version
956
+					);
957
+				}
958
+				$query_param_for_models[ $query_param_key ] = $translated_value;
959
+			} else {
960
+				// so it's not for a field, assume it's a logic query param key
961
+				$query_param_for_models[ $query_param_key ] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
962
+					$query_param_value,
963
+					$model,
964
+					$requested_version
965
+				);
966
+			}
967
+		}
968
+		return $query_param_for_models;
969
+	}
970 970
 
971 971
 
972
-    /**
973
-     * @param $condition_query_param_key
974
-     * @return string
975
-     */
976
-    public static function removeStarsAndAnythingAfterFromConditionQueryParamKey($condition_query_param_key)
977
-    {
978
-        $pos_of_star = strpos($condition_query_param_key, '*');
979
-        if ($pos_of_star === false) {
980
-            return $condition_query_param_key;
981
-        } else {
982
-            $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
983
-            return $condition_query_param_sans_star;
984
-        }
985
-    }
972
+	/**
973
+	 * @param $condition_query_param_key
974
+	 * @return string
975
+	 */
976
+	public static function removeStarsAndAnythingAfterFromConditionQueryParamKey($condition_query_param_key)
977
+	{
978
+		$pos_of_star = strpos($condition_query_param_key, '*');
979
+		if ($pos_of_star === false) {
980
+			return $condition_query_param_key;
981
+		} else {
982
+			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
983
+			return $condition_query_param_sans_star;
984
+		}
985
+	}
986 986
 
987 987
 
988
-    /**
989
-     * Takes the input parameter and finds the model field that it indicates.
990
-     *
991
-     * @param string   $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID
992
-     * @param EEM_Base $model
993
-     * @return EE_Model_Field_Base
994
-     * @throws EE_Error
995
-     */
996
-    public static function deduceFieldFromQueryParam($query_param_name, EEM_Base $model)
997
-    {
998
-        // ok, now proceed with deducing which part is the model's name, and which is the field's name
999
-        // which will help us find the database table and column
1000
-        $query_param_parts = explode('.', $query_param_name);
1001
-        if (empty($query_param_parts)) {
1002
-            throw new EE_Error(
1003
-                sprintf(
1004
-                    __(
1005
-                        '_extract_column_name is empty when trying to extract column and table name from %s',
1006
-                        'event_espresso'
1007
-                    ),
1008
-                    $query_param_name
1009
-                )
1010
-            );
1011
-        }
1012
-        $number_of_parts = count($query_param_parts);
1013
-        $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
1014
-        if ($number_of_parts === 1) {
1015
-            $field_name = $last_query_param_part;
1016
-        } else {// $number_of_parts >= 2
1017
-            // the last part is the column name, and there are only 2parts. therefore...
1018
-            $field_name = $last_query_param_part;
1019
-            $model = \EE_Registry::instance()->load_model($query_param_parts[ $number_of_parts - 2 ]);
1020
-        }
1021
-        try {
1022
-            return $model->field_settings_for($field_name, false);
1023
-        } catch (EE_Error $e) {
1024
-            return null;
1025
-        }
1026
-    }
988
+	/**
989
+	 * Takes the input parameter and finds the model field that it indicates.
990
+	 *
991
+	 * @param string   $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID
992
+	 * @param EEM_Base $model
993
+	 * @return EE_Model_Field_Base
994
+	 * @throws EE_Error
995
+	 */
996
+	public static function deduceFieldFromQueryParam($query_param_name, EEM_Base $model)
997
+	{
998
+		// ok, now proceed with deducing which part is the model's name, and which is the field's name
999
+		// which will help us find the database table and column
1000
+		$query_param_parts = explode('.', $query_param_name);
1001
+		if (empty($query_param_parts)) {
1002
+			throw new EE_Error(
1003
+				sprintf(
1004
+					__(
1005
+						'_extract_column_name is empty when trying to extract column and table name from %s',
1006
+						'event_espresso'
1007
+					),
1008
+					$query_param_name
1009
+				)
1010
+			);
1011
+		}
1012
+		$number_of_parts = count($query_param_parts);
1013
+		$last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
1014
+		if ($number_of_parts === 1) {
1015
+			$field_name = $last_query_param_part;
1016
+		} else {// $number_of_parts >= 2
1017
+			// the last part is the column name, and there are only 2parts. therefore...
1018
+			$field_name = $last_query_param_part;
1019
+			$model = \EE_Registry::instance()->load_model($query_param_parts[ $number_of_parts - 2 ]);
1020
+		}
1021
+		try {
1022
+			return $model->field_settings_for($field_name, false);
1023
+		} catch (EE_Error $e) {
1024
+			return null;
1025
+		}
1026
+	}
1027 1027
 
1028 1028
 
1029
-    /**
1030
-     * Returns true if $data can be easily represented in JSON.
1031
-     * Basically, objects and resources can't be represented in JSON easily.
1032
-     *
1033
-     * @param mixed $data
1034
-     * @return bool
1035
-     */
1036
-    protected static function isRepresentableInJson($data)
1037
-    {
1038
-        return is_scalar($data)
1039
-               || is_array($data)
1040
-               || is_null($data);
1041
-    }
1029
+	/**
1030
+	 * Returns true if $data can be easily represented in JSON.
1031
+	 * Basically, objects and resources can't be represented in JSON easily.
1032
+	 *
1033
+	 * @param mixed $data
1034
+	 * @return bool
1035
+	 */
1036
+	protected static function isRepresentableInJson($data)
1037
+	{
1038
+		return is_scalar($data)
1039
+			   || is_array($data)
1040
+			   || is_null($data);
1041
+	}
1042 1042
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         ) {
61 61
             $new_value_maybe_array = array();
62 62
             foreach ($original_value_maybe_array as $array_key => $array_item) {
63
-                $new_value_maybe_array[ $array_key ] = ModelDataTranslator::prepareFieldValueFromJson(
63
+                $new_value_maybe_array[$array_key] = ModelDataTranslator::prepareFieldValueFromJson(
64 64
                     $field_obj,
65 65
                     $array_item,
66 66
                     $requested_version,
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
         if (is_array($original_value_maybe_array)) {
93 93
             $new_value = array();
94 94
             foreach ($original_value_maybe_array as $key => $value) {
95
-                $new_value[ $key ] = ModelDataTranslator::prepareFieldValuesForJson(
95
+                $new_value[$key] = ModelDataTranslator::prepareFieldValuesForJson(
96 96
                     $field_obj,
97 97
                     $value,
98 98
                     $request_version
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
                 '0',
226 226
                 STR_PAD_LEFT
227 227
             );
228
-        return $original_timestamp . $offset_sign . $offset_string;
228
+        return $original_timestamp.$offset_sign.$offset_string;
229 229
     }
230 230
 
231 231
 
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
                     // first, check if its a MySQL timestamp in GMT
303 303
                     $datetime_obj = \DateTime::createFromFormat('Y-m-d H:i:s', $original_value);
304 304
                 }
305
-                if (! $datetime_obj instanceof \DateTime) {
305
+                if ( ! $datetime_obj instanceof \DateTime) {
306 306
                     // so it's not a unix timestamp or a MySQL timestamp. Maybe its in the field's date/time format?
307 307
                     $datetime_obj = $field_obj->prepare_for_set($original_value);
308 308
                 }
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
                         $original_value,
329 329
                         $field_obj->get_name(),
330 330
                         $field_obj->get_model_name(),
331
-                        $field_obj->get_time_format() . ' ' . $field_obj->get_time_format()
331
+                        $field_obj->get_time_format().' '.$field_obj->get_time_format()
332 332
                     )
333 333
                 );
334 334
             }
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
         }
341 341
         // are we about to send an object? just don't. We have no good way to represent it in JSON.
342 342
         // can't just check using is_object() because that missed PHP incomplete objects
343
-        if (! ModelDataTranslator::isRepresentableInJson($new_value)) {
343
+        if ( ! ModelDataTranslator::isRepresentableInJson($new_value)) {
344 344
             $new_value = array(
345 345
                 'error_code'    => 'php_object_not_return',
346 346
                 'error_message' => esc_html__(
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
                     $query_param_value,
407 407
                     $writing
408 408
                 );
409
-                if ((isset($query_param_for_models[ $query_param_key ]) && $is_gmt_datetime_field)
409
+                if ((isset($query_param_for_models[$query_param_key]) && $is_gmt_datetime_field)
410 410
                     || $translated_value === null
411 411
                 ) {
412 412
                     // they have already provided a non-gmt field, ignore the gmt one. That's what WP core
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
                     // OR we couldn't create a translated value from their input
415 415
                     continue;
416 416
                 }
417
-                $query_param_for_models[ $query_param_key ] = $translated_value;
417
+                $query_param_for_models[$query_param_key] = $translated_value;
418 418
             } else {
419 419
                 $nested_query_params = self::determineNestedConditionQueryParameters(
420 420
                     $model,
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
                     $writing
426 426
                 );
427 427
                 if ($nested_query_params) {
428
-                    $query_param_for_models[ $query_param_key ] = $nested_query_params;
428
+                    $query_param_for_models[$query_param_key] = $nested_query_params;
429 429
                 }
430 430
             }
431 431
         }
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
             $model
529 529
         );
530 530
         // double-check is it a *_gmt field?
531
-        if (! $field instanceof EE_Model_Field_Base
531
+        if ( ! $field instanceof EE_Model_Field_Base
532 532
             && ModelDataTranslator::isGmtDateFieldName($query_param_sans_stars)
533 533
         ) {
534 534
             // yep, take off '_gmt', and find the field
@@ -579,8 +579,8 @@  discard block
 block discarded – undo
579 579
         $query_param_value,
580 580
         $writing = false
581 581
     ) {
582
-        if (! $writing && is_array($query_param_value)) {
583
-            if (! \EEH_Array::is_array_numerically_and_sequentially_indexed($query_param_value)) {
582
+        if ( ! $writing && is_array($query_param_value)) {
583
+            if ( ! \EEH_Array::is_array_numerically_and_sequentially_indexed($query_param_value)) {
584 584
                 if (is_array($query_param_value)
585 585
                     && count($query_param_value) === 1
586 586
                     && array_key_exists(
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
                         $model->valid_operators()
589 589
                     )
590 590
                 ) {
591
-                    $sub_array_value =  reset($query_param_value);
591
+                    $sub_array_value = reset($query_param_value);
592 592
                     $sub_array_key = key($query_param_value);
593 593
                     if (is_array($sub_array_value) && defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) {
594 594
                         throw new RestException(
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
                     )) {
617 617
                         // the value should be JSON or CSV
618 618
                         $values = json_decode($sub_array_value);
619
-                        if (! is_array($values)) {
619
+                        if ( ! is_array($values)) {
620 620
                             $values = array_filter(
621 621
                                 array_map(
622 622
                                     'trim',
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
             $valid_operators = $model->valid_operators();
660 660
             // did they specify an operator?
661 661
             if (isset($query_param_value[0])
662
-                && isset($valid_operators[ $query_param_value[0] ])
662
+                && isset($valid_operators[$query_param_value[0]])
663 663
             ) {
664 664
                 $sub_array_key = $query_param_value[0];
665 665
                 $translated_value = array($sub_array_key);
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
      */
803 803
     public static function removeGmtFromFieldName($field_name)
804 804
     {
805
-        if (! ModelDataTranslator::isGmtDateFieldName($field_name)) {
805
+        if ( ! ModelDataTranslator::isGmtDateFieldName($field_name)) {
806 806
             return $field_name;
807 807
         }
808 808
         $query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey(
@@ -845,7 +845,7 @@  discard block
 block discarded – undo
845 845
     {
846 846
         $new_array = array();
847 847
         foreach ($field_names as $key => $field_name) {
848
-            $new_array[ $key ] = ModelDataTranslator::prepareFieldNameFromJson($field_name);
848
+            $new_array[$key] = ModelDataTranslator::prepareFieldNameFromJson($field_name);
849 849
         }
850 850
         return $new_array;
851 851
     }
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
     {
863 863
         $new_array = array();
864 864
         foreach ($field_names_as_keys as $field_name => $value) {
865
-            $new_array[ ModelDataTranslator::prepareFieldNameFromJson($field_name) ] = $value;
865
+            $new_array[ModelDataTranslator::prepareFieldNameFromJson($field_name)] = $value;
866 866
         }
867 867
         return $new_array;
868 868
     }
@@ -955,10 +955,10 @@  discard block
 block discarded – undo
955 955
                         $requested_version
956 956
                     );
957 957
                 }
958
-                $query_param_for_models[ $query_param_key ] = $translated_value;
958
+                $query_param_for_models[$query_param_key] = $translated_value;
959 959
             } else {
960 960
                 // so it's not for a field, assume it's a logic query param key
961
-                $query_param_for_models[ $query_param_key ] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
961
+                $query_param_for_models[$query_param_key] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
962 962
                     $query_param_value,
963 963
                     $model,
964 964
                     $requested_version
@@ -1010,13 +1010,13 @@  discard block
 block discarded – undo
1010 1010
             );
1011 1011
         }
1012 1012
         $number_of_parts = count($query_param_parts);
1013
-        $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
1013
+        $last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
1014 1014
         if ($number_of_parts === 1) {
1015 1015
             $field_name = $last_query_param_part;
1016 1016
         } else {// $number_of_parts >= 2
1017 1017
             // the last part is the column name, and there are only 2parts. therefore...
1018 1018
             $field_name = $last_query_param_part;
1019
-            $model = \EE_Registry::instance()->load_model($query_param_parts[ $number_of_parts - 2 ]);
1019
+            $model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]);
1020 1020
         }
1021 1021
         try {
1022 1022
             return $model->field_settings_for($field_name, false);
Please login to merge, or discard this patch.