Completed
Pull Request — master (#331)
by Darren
16:18
created
core/services/bootstrap/BootstrapCore.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
         // load interfaces
209 209
         espresso_load_required(
210 210
             'EEH_Autoloader',
211
-            EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php'
211
+            EE_CORE.'helpers'.DS.'EEH_Autoloader.helper.php'
212 212
         );
213 213
         EEH_Autoloader::instance();
214 214
     }
@@ -223,13 +223,13 @@  discard block
 block discarded – undo
223 223
     protected function setAutoloadersForRequiredFiles()
224 224
     {
225 225
         // load interfaces
226
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true);
226
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'interfaces', true);
227 227
         // load helpers
228 228
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
229 229
         // register legacy request stack classes just in case
230
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS);
230
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'request_stack'.DS);
231 231
         // register legacy middleware classes just in case
232
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS);
232
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'middleware'.DS);
233 233
     }
234 234
 
235 235
 
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
          * so items at the beginning of the final middleware stack will run last.
248 248
          * First parameter is the middleware classname, second is an array of arguments
249 249
          */
250
-        $stack_apps            = apply_filters(
250
+        $stack_apps = apply_filters(
251 251
             'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps',
252 252
             array(
253 253
                 // first in last out
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
             )
261 261
         );
262 262
         // legacy filter for backwards compatibility
263
-        $stack_apps            = apply_filters(
263
+        $stack_apps = apply_filters(
264 264
             'FHEE__EE_Bootstrap__build_request_stack__stack_apps',
265 265
             $stack_apps
266 266
         );
Please login to merge, or discard this patch.
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -50,229 +50,229 @@
 block discarded – undo
50 50
 class BootstrapCore
51 51
 {
52 52
 
53
-    /**
54
-     * @type LoaderInterface $loader
55
-     */
56
-    private $loader;
57
-
58
-    /**
59
-     * @var RequestInterface $request
60
-     */
61
-    protected $request;
62
-
63
-    /**
64
-     * @var ResponseInterface $response
65
-     */
66
-    protected $response;
67
-
68
-    /**
69
-     * @var RequestStackBuilder $request_stack_builder
70
-     */
71
-    protected $request_stack_builder;
72
-
73
-    /**
74
-     * @var RequestStack $request_stack
75
-     */
76
-    protected $request_stack;
77
-
78
-
79
-    /**
80
-     * BootstrapCore constructor.
81
-     */
82
-    public function __construct()
83
-    {
84
-        do_action('AHEE__EventEspresso_core_services_bootstrap_BootstrapCore___construct');
85
-        // construct request stack and run middleware apps as soon as all WP plugins are loaded
86
-        add_action('plugins_loaded', array($this, 'initialize'), 0);
87
-    }
88
-
89
-
90
-    /**
91
-     * @throws DomainException
92
-     * @throws EE_Error
93
-     * @throws Exception
94
-     * @throws InvalidArgumentException
95
-     * @throws InvalidClassException
96
-     * @throws InvalidDataTypeException
97
-     * @throws InvalidFilePathException
98
-     * @throws InvalidInterfaceException
99
-     * @throws InvalidRequestStackMiddlewareException
100
-     * @throws OutOfBoundsException
101
-     * @throws ReflectionException
102
-     */
103
-    public function initialize()
104
-    {
105
-        $this->bootstrapDependencyInjectionContainer();
106
-        $this->bootstrapDomain();
107
-        $bootstrap_request = $this->bootstrapRequestResponseObjects();
108
-        add_action(
109
-            'EE_Load_Espresso_Core__handle_request__initialize_core_loading',
110
-            array($bootstrap_request, 'setupLegacyRequest')
111
-        );
112
-        $this->runRequestStack();
113
-    }
114
-
115
-
116
-    /**
117
-     * @throws ReflectionException
118
-     * @throws EE_Error
119
-     * @throws InvalidArgumentException
120
-     * @throws InvalidDataTypeException
121
-     * @throws InvalidInterfaceException
122
-     * @throws OutOfBoundsException
123
-     */
124
-    private function bootstrapDependencyInjectionContainer()
125
-    {
126
-        $bootstrap_di = new BootstrapDependencyInjectionContainer();
127
-        $bootstrap_di->buildLegacyDependencyInjectionContainer();
128
-        $bootstrap_di->buildLoader();
129
-        $registry = $bootstrap_di->getRegistry();
130
-        $dependency_map = $bootstrap_di->getDependencyMap();
131
-        $dependency_map->initialize();
132
-        $registry->initialize();
133
-        $this->loader = $bootstrap_di->getLoader();
134
-    }
135
-
136
-
137
-    /**
138
-     * configures the Domain object for core
139
-     *
140
-     * @return void
141
-     * @throws DomainException
142
-     * @throws InvalidArgumentException
143
-     * @throws InvalidDataTypeException
144
-     * @throws InvalidClassException
145
-     * @throws InvalidFilePathException
146
-     * @throws InvalidInterfaceException
147
-     */
148
-    private function bootstrapDomain()
149
-    {
150
-        DomainFactory::getEventEspressoCoreDomain();
151
-    }
152
-
153
-
154
-    /**
155
-     * sets up the request and response objects
156
-     *
157
-     * @return BootstrapRequestResponseObjects
158
-     * @throws InvalidArgumentException
159
-     */
160
-    private function bootstrapRequestResponseObjects()
161
-    {
162
-        /** @var BootstrapRequestResponseObjects $bootstrap_request */
163
-        $bootstrap_request = $this->loader->getShared(
164
-            'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects',
165
-            array($this->loader)
166
-        );
167
-        $bootstrap_request->buildRequestResponse();
168
-        $bootstrap_request->shareRequestResponse();
169
-        $this->request  = $this->loader->getShared('EventEspresso\core\services\request\Request');
170
-        $this->response = $this->loader->getShared('EventEspresso\core\services\request\Response');
171
-        return $bootstrap_request;
172
-    }
173
-
174
-
175
-    /**
176
-     * run_request_stack
177
-     * construct request stack and run middleware apps
178
-     *
179
-     * @throws EE_Error
180
-     * @throws Exception
181
-     */
182
-    public function runRequestStack()
183
-    {
184
-        $this->loadAutoloader();
185
-        $this->setAutoloadersForRequiredFiles();
186
-        $this->request_stack_builder = $this->buildRequestStack();
187
-        $this->request_stack         = $this->request_stack_builder->resolve(
188
-            new RequestStackCoreApp()
189
-        );
190
-        $this->request_stack->handleRequest($this->request, $this->response);
191
-        $this->request_stack->handleResponse();
192
-    }
193
-
194
-
195
-    /**
196
-     * load_autoloader
197
-     *
198
-     * @throws EE_Error
199
-     */
200
-    protected function loadAutoloader()
201
-    {
202
-        // load interfaces
203
-        espresso_load_required(
204
-            'EEH_Autoloader',
205
-            EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php'
206
-        );
207
-        EEH_Autoloader::instance();
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     * load_required_files
214
-     *
215
-     * @throws EE_Error
216
-     */
217
-    protected function setAutoloadersForRequiredFiles()
218
-    {
219
-        // load interfaces
220
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true);
221
-        // load helpers
222
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
223
-        // register legacy request stack classes just in case
224
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS);
225
-        // register legacy middleware classes just in case
226
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS);
227
-    }
228
-
229
-
230
-
231
-    /**
232
-     * build_request_stack
233
-     *
234
-     * @return RequestStackBuilder
235
-     */
236
-    public function buildRequestStack()
237
-    {
238
-        $request_stack_builder = new RequestStackBuilder($this->loader);
239
-        /**
240
-         * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT
241
-         * so items at the beginning of the final middleware stack will run last.
242
-         * First parameter is the middleware classname, second is an array of arguments
243
-         */
244
-        $stack_apps            = apply_filters(
245
-            'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps',
246
-            array(
247
-                // first in last out
248
-                'EventEspresso\core\services\request\middleware\BotDetector' => array(),
249
-                'EventEspresso\core\services\request\middleware\DetectFileEditorRequest' => array(),
250
-                'EventEspresso\core\services\request\middleware\PreProductionVersionWarning' => array(),
251
-                'EventEspresso\core\services\request\middleware\RecommendedVersions' => array(),
252
-                // last in first out
253
-                'EventEspresso\core\services\request\middleware\DetectLogin' => array(),
254
-            )
255
-        );
256
-        // legacy filter for backwards compatibility
257
-        $stack_apps            = apply_filters(
258
-            'FHEE__EE_Bootstrap__build_request_stack__stack_apps',
259
-            $stack_apps
260
-        );
261
-        // load middleware onto stack : FILO (First In Last Out)
262
-        // items at the beginning of the $stack_apps array will run last
263
-        foreach ((array) $stack_apps as $stack_app => $stack_app_args) {
264
-            $request_stack_builder->push(array($stack_app, $stack_app_args));
265
-        }
266
-        // finally, we'll add this on its own because we need it to always be part of the stack
267
-        // and we also need it to always run first because the rest of the system relies on it
268
-        $request_stack_builder->push(
269
-            array('EventEspresso\core\services\request\middleware\SetRequestTypeContextChecker', array())
270
-        );
271
-        return apply_filters(
272
-            'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder',
273
-            $request_stack_builder
274
-        );
275
-    }
53
+	/**
54
+	 * @type LoaderInterface $loader
55
+	 */
56
+	private $loader;
57
+
58
+	/**
59
+	 * @var RequestInterface $request
60
+	 */
61
+	protected $request;
62
+
63
+	/**
64
+	 * @var ResponseInterface $response
65
+	 */
66
+	protected $response;
67
+
68
+	/**
69
+	 * @var RequestStackBuilder $request_stack_builder
70
+	 */
71
+	protected $request_stack_builder;
72
+
73
+	/**
74
+	 * @var RequestStack $request_stack
75
+	 */
76
+	protected $request_stack;
77
+
78
+
79
+	/**
80
+	 * BootstrapCore constructor.
81
+	 */
82
+	public function __construct()
83
+	{
84
+		do_action('AHEE__EventEspresso_core_services_bootstrap_BootstrapCore___construct');
85
+		// construct request stack and run middleware apps as soon as all WP plugins are loaded
86
+		add_action('plugins_loaded', array($this, 'initialize'), 0);
87
+	}
88
+
89
+
90
+	/**
91
+	 * @throws DomainException
92
+	 * @throws EE_Error
93
+	 * @throws Exception
94
+	 * @throws InvalidArgumentException
95
+	 * @throws InvalidClassException
96
+	 * @throws InvalidDataTypeException
97
+	 * @throws InvalidFilePathException
98
+	 * @throws InvalidInterfaceException
99
+	 * @throws InvalidRequestStackMiddlewareException
100
+	 * @throws OutOfBoundsException
101
+	 * @throws ReflectionException
102
+	 */
103
+	public function initialize()
104
+	{
105
+		$this->bootstrapDependencyInjectionContainer();
106
+		$this->bootstrapDomain();
107
+		$bootstrap_request = $this->bootstrapRequestResponseObjects();
108
+		add_action(
109
+			'EE_Load_Espresso_Core__handle_request__initialize_core_loading',
110
+			array($bootstrap_request, 'setupLegacyRequest')
111
+		);
112
+		$this->runRequestStack();
113
+	}
114
+
115
+
116
+	/**
117
+	 * @throws ReflectionException
118
+	 * @throws EE_Error
119
+	 * @throws InvalidArgumentException
120
+	 * @throws InvalidDataTypeException
121
+	 * @throws InvalidInterfaceException
122
+	 * @throws OutOfBoundsException
123
+	 */
124
+	private function bootstrapDependencyInjectionContainer()
125
+	{
126
+		$bootstrap_di = new BootstrapDependencyInjectionContainer();
127
+		$bootstrap_di->buildLegacyDependencyInjectionContainer();
128
+		$bootstrap_di->buildLoader();
129
+		$registry = $bootstrap_di->getRegistry();
130
+		$dependency_map = $bootstrap_di->getDependencyMap();
131
+		$dependency_map->initialize();
132
+		$registry->initialize();
133
+		$this->loader = $bootstrap_di->getLoader();
134
+	}
135
+
136
+
137
+	/**
138
+	 * configures the Domain object for core
139
+	 *
140
+	 * @return void
141
+	 * @throws DomainException
142
+	 * @throws InvalidArgumentException
143
+	 * @throws InvalidDataTypeException
144
+	 * @throws InvalidClassException
145
+	 * @throws InvalidFilePathException
146
+	 * @throws InvalidInterfaceException
147
+	 */
148
+	private function bootstrapDomain()
149
+	{
150
+		DomainFactory::getEventEspressoCoreDomain();
151
+	}
152
+
153
+
154
+	/**
155
+	 * sets up the request and response objects
156
+	 *
157
+	 * @return BootstrapRequestResponseObjects
158
+	 * @throws InvalidArgumentException
159
+	 */
160
+	private function bootstrapRequestResponseObjects()
161
+	{
162
+		/** @var BootstrapRequestResponseObjects $bootstrap_request */
163
+		$bootstrap_request = $this->loader->getShared(
164
+			'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects',
165
+			array($this->loader)
166
+		);
167
+		$bootstrap_request->buildRequestResponse();
168
+		$bootstrap_request->shareRequestResponse();
169
+		$this->request  = $this->loader->getShared('EventEspresso\core\services\request\Request');
170
+		$this->response = $this->loader->getShared('EventEspresso\core\services\request\Response');
171
+		return $bootstrap_request;
172
+	}
173
+
174
+
175
+	/**
176
+	 * run_request_stack
177
+	 * construct request stack and run middleware apps
178
+	 *
179
+	 * @throws EE_Error
180
+	 * @throws Exception
181
+	 */
182
+	public function runRequestStack()
183
+	{
184
+		$this->loadAutoloader();
185
+		$this->setAutoloadersForRequiredFiles();
186
+		$this->request_stack_builder = $this->buildRequestStack();
187
+		$this->request_stack         = $this->request_stack_builder->resolve(
188
+			new RequestStackCoreApp()
189
+		);
190
+		$this->request_stack->handleRequest($this->request, $this->response);
191
+		$this->request_stack->handleResponse();
192
+	}
193
+
194
+
195
+	/**
196
+	 * load_autoloader
197
+	 *
198
+	 * @throws EE_Error
199
+	 */
200
+	protected function loadAutoloader()
201
+	{
202
+		// load interfaces
203
+		espresso_load_required(
204
+			'EEH_Autoloader',
205
+			EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php'
206
+		);
207
+		EEH_Autoloader::instance();
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 * load_required_files
214
+	 *
215
+	 * @throws EE_Error
216
+	 */
217
+	protected function setAutoloadersForRequiredFiles()
218
+	{
219
+		// load interfaces
220
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true);
221
+		// load helpers
222
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
223
+		// register legacy request stack classes just in case
224
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS);
225
+		// register legacy middleware classes just in case
226
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS);
227
+	}
228
+
229
+
230
+
231
+	/**
232
+	 * build_request_stack
233
+	 *
234
+	 * @return RequestStackBuilder
235
+	 */
236
+	public function buildRequestStack()
237
+	{
238
+		$request_stack_builder = new RequestStackBuilder($this->loader);
239
+		/**
240
+		 * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT
241
+		 * so items at the beginning of the final middleware stack will run last.
242
+		 * First parameter is the middleware classname, second is an array of arguments
243
+		 */
244
+		$stack_apps            = apply_filters(
245
+			'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps',
246
+			array(
247
+				// first in last out
248
+				'EventEspresso\core\services\request\middleware\BotDetector' => array(),
249
+				'EventEspresso\core\services\request\middleware\DetectFileEditorRequest' => array(),
250
+				'EventEspresso\core\services\request\middleware\PreProductionVersionWarning' => array(),
251
+				'EventEspresso\core\services\request\middleware\RecommendedVersions' => array(),
252
+				// last in first out
253
+				'EventEspresso\core\services\request\middleware\DetectLogin' => array(),
254
+			)
255
+		);
256
+		// legacy filter for backwards compatibility
257
+		$stack_apps            = apply_filters(
258
+			'FHEE__EE_Bootstrap__build_request_stack__stack_apps',
259
+			$stack_apps
260
+		);
261
+		// load middleware onto stack : FILO (First In Last Out)
262
+		// items at the beginning of the $stack_apps array will run last
263
+		foreach ((array) $stack_apps as $stack_app => $stack_app_args) {
264
+			$request_stack_builder->push(array($stack_app, $stack_app_args));
265
+		}
266
+		// finally, we'll add this on its own because we need it to always be part of the stack
267
+		// and we also need it to always run first because the rest of the system relies on it
268
+		$request_stack_builder->push(
269
+			array('EventEspresso\core\services\request\middleware\SetRequestTypeContextChecker', array())
270
+		);
271
+		return apply_filters(
272
+			'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder',
273
+			$request_stack_builder
274
+		);
275
+	}
276 276
 
277 277
 
278 278
 }
Please login to merge, or discard this patch.
core/EE_Registry.core.php 3 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -322,6 +322,7 @@  discard block
 block discarded – undo
322 322
 
323 323
     /**
324 324
      * @param mixed string | EED_Module $module
325
+     * @param string $module
325 326
      * @throws OutOfBoundsException
326 327
      * @throws InvalidArgumentException
327 328
      * @throws InvalidInterfaceException
@@ -794,7 +795,7 @@  discard block
 block discarded – undo
794 795
     /**
795 796
      * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
796 797
      *
797
-     * @param string|object $class_name
798
+     * @param string $class_name
798 799
      * @param array         $arguments
799 800
      * @param int           $attempt
800 801
      * @return mixed
@@ -1377,7 +1378,7 @@  discard block
 block discarded – undo
1377 1378
      * @param string $class_name
1378 1379
      * @param string $param_class
1379 1380
      * @param array  $arguments
1380
-     * @param mixed  $index
1381
+     * @param integer  $index
1381 1382
      * @return array
1382 1383
      * @throws InvalidArgumentException
1383 1384
      * @throws InvalidInterfaceException
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -313,10 +313,10 @@  discard block
 block discarded – undo
313 313
         $i18n_js_strings = (array) self::$i18n_js_strings;
314 314
         foreach ($i18n_js_strings as $key => $value) {
315 315
             if (is_scalar($value)) {
316
-                $i18n_js_strings[ $key ] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
316
+                $i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
317 317
             }
318 318
         }
319
-        return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
319
+        return '/* <![CDATA[ */ var eei18n = '.wp_json_encode($i18n_js_strings).'; /* ]]> */';
320 320
     }
321 321
 
322 322
 
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
             $module_class                   = get_class($module);
336 336
             $this->modules->{$module_class} = $module;
337 337
         } else {
338
-            if (! class_exists('EE_Module_Request_Router', false)) {
338
+            if ( ! class_exists('EE_Module_Request_Router', false)) {
339 339
                 $this->load_core('Module_Request_Router');
340 340
             }
341 341
             EE_Module_Request_Router::module_factory($module);
@@ -376,10 +376,10 @@  discard block
 block discarded – undo
376 376
                 EE_CORE,
377 377
                 EE_ADMIN,
378 378
                 EE_CPTS,
379
-                EE_CORE . 'data_migration_scripts' . DS,
380
-                EE_CORE . 'capabilities' . DS,
381
-                EE_CORE . 'request_stack' . DS,
382
-                EE_CORE . 'middleware' . DS,
379
+                EE_CORE.'data_migration_scripts'.DS,
380
+                EE_CORE.'capabilities'.DS,
381
+                EE_CORE.'request_stack'.DS,
382
+                EE_CORE.'middleware'.DS,
383 383
             )
384 384
         );
385 385
         // retrieve instantiated class
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
         $service_paths = apply_filters(
415 415
             'FHEE__EE_Registry__load_service__service_paths',
416 416
             array(
417
-                EE_CORE . 'services' . DS,
417
+                EE_CORE.'services'.DS,
418 418
             )
419 419
         );
420 420
         // retrieve instantiated class
@@ -548,10 +548,10 @@  discard block
 block discarded – undo
548 548
     {
549 549
         $paths = array(
550 550
             EE_LIBRARIES,
551
-            EE_LIBRARIES . 'messages' . DS,
552
-            EE_LIBRARIES . 'shortcodes' . DS,
553
-            EE_LIBRARIES . 'qtips' . DS,
554
-            EE_LIBRARIES . 'payment_methods' . DS,
551
+            EE_LIBRARIES.'messages'.DS,
552
+            EE_LIBRARIES.'shortcodes'.DS,
553
+            EE_LIBRARIES.'qtips'.DS,
554
+            EE_LIBRARIES.'payment_methods'.DS,
555 555
         );
556 556
         // retrieve instantiated class
557 557
         return $this->_load(
@@ -618,10 +618,10 @@  discard block
 block discarded – undo
618 618
     public function load_model_class($class_name, $arguments = array(), $load_only = true)
619 619
     {
620 620
         $paths = array(
621
-            EE_MODELS . 'fields' . DS,
622
-            EE_MODELS . 'helpers' . DS,
623
-            EE_MODELS . 'relations' . DS,
624
-            EE_MODELS . 'strategies' . DS,
621
+            EE_MODELS.'fields'.DS,
622
+            EE_MODELS.'helpers'.DS,
623
+            EE_MODELS.'relations'.DS,
624
+            EE_MODELS.'strategies'.DS,
625 625
         );
626 626
         // retrieve instantiated class
627 627
         return $this->_load(
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
      */
646 646
     public function is_model_name($model_name)
647 647
     {
648
-        return isset($this->models[ $model_name ]);
648
+        return isset($this->models[$model_name]);
649 649
     }
650 650
 
651 651
 
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
                 return $cached_class;
767 767
             }
768 768
         }// obtain the loader method from the dependency map
769
-        $loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object
769
+        $loader = $this->_dependency_map->class_loader($class_name); // instantiate the requested object
770 770
         if ($loader instanceof Closure) {
771 771
             $class_obj = $loader($arguments);
772 772
         } else {
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
             case 1:
809 809
                 // if it's a FQCN then maybe the class is registered with a preceding \
810 810
                 $class_name = strpos($class_name, '\\') !== false
811
-                    ? '\\' . ltrim($class_name, '\\')
811
+                    ? '\\'.ltrim($class_name, '\\')
812 812
                     : $class_name;
813 813
                 break;
814 814
             case 2:
@@ -862,11 +862,11 @@  discard block
 block discarded – undo
862 862
         // strip php file extension
863 863
         $class_name = str_replace('.php', '', trim($class_name));
864 864
         // does the class have a prefix ?
865
-        if (! empty($class_prefix) && $class_prefix !== 'addon') {
865
+        if ( ! empty($class_prefix) && $class_prefix !== 'addon') {
866 866
             // make sure $class_prefix is uppercase
867 867
             $class_prefix = strtoupper(trim($class_prefix));
868 868
             // add class prefix ONCE!!!
869
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
869
+            $class_name = $class_prefix.str_replace($class_prefix, '', $class_name);
870 870
         }
871 871
         $class_name   = $this->class_cache->getFqnForAlias($class_name);
872 872
         $class_exists = class_exists($class_name, false);
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
             }
886 886
         }
887 887
         // if the class doesn't already exist.. then we need to try and find the file and load it
888
-        if (! $class_exists) {
888
+        if ( ! $class_exists) {
889 889
             // get full path to file
890 890
             $path = $this->_resolve_path($class_name, $type, $file_paths);
891 891
             // load the file
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
                 return $loaded;
897 897
             }
898 898
             // if an object was expected but loading failed, then return nothing
899
-            if (! $loaded) {
899
+            if ( ! $loaded) {
900 900
                 return null;
901 901
             }
902 902
         }
@@ -924,8 +924,8 @@  discard block
 block discarded – undo
924 924
      */
925 925
     protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS')
926 926
     {
927
-        return isset($this->_class_abbreviations[ $class_name ])
928
-            ? $this->_class_abbreviations[ $class_name ]
927
+        return isset($this->_class_abbreviations[$class_name])
928
+            ? $this->_class_abbreviations[$class_name]
929 929
             : $default;
930 930
     }
931 931
 
@@ -1059,7 +1059,7 @@  discard block
 block discarded – undo
1059 1059
             $this->addons->{$class_name} = $class_obj;
1060 1060
             return;
1061 1061
         }
1062
-        if (! $from_db) {
1062
+        if ( ! $from_db) {
1063 1063
             $class_name               = $this->object_identifier->getIdentifier($class_name, $arguments);
1064 1064
             $this->LIB->{$class_name} = $class_obj;
1065 1065
         }
@@ -1090,13 +1090,13 @@  discard block
 block discarded – undo
1090 1090
                 : EE_CLASSES;
1091 1091
             // prep file type
1092 1092
             $type = ! empty($type)
1093
-                ? trim($type, '.') . '.'
1093
+                ? trim($type, '.').'.'
1094 1094
                 : '';
1095 1095
             // build full file path
1096
-            $file_paths[ $key ] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
1096
+            $file_paths[$key] = rtrim($file_path, DS).DS.$class_name.'.'.$type.'php';
1097 1097
             //does the file exist and can be read ?
1098
-            if (is_readable($file_paths[ $key ])) {
1099
-                return $file_paths[ $key ];
1098
+            if (is_readable($file_paths[$key])) {
1099
+                return $file_paths[$key];
1100 1100
             }
1101 1101
         }
1102 1102
         return false;
@@ -1121,7 +1121,7 @@  discard block
 block discarded – undo
1121 1121
         // don't give up! you gotta...
1122 1122
         try {
1123 1123
             //does the file exist and can it be read ?
1124
-            if (! $path) {
1124
+            if ( ! $path) {
1125 1125
                 // just in case the file has already been autoloaded,
1126 1126
                 // but discrepancies in the naming schema are preventing it from
1127 1127
                 // being loaded via one of the EE_Registry::load_*() methods,
@@ -1131,7 +1131,7 @@  discard block
 block discarded – undo
1131 1131
                     return true;
1132 1132
                 }
1133 1133
                 // so sorry, can't find the file
1134
-                throw new EE_Error (
1134
+                throw new EE_Error(
1135 1135
                     sprintf(
1136 1136
                         esc_html__(
1137 1137
                             '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',
@@ -1139,7 +1139,7 @@  discard block
 block discarded – undo
1139 1139
                         ),
1140 1140
                         trim($type, '.'),
1141 1141
                         $class_name,
1142
-                        '<br />' . implode(',<br />', $file_paths)
1142
+                        '<br />'.implode(',<br />', $file_paths)
1143 1143
                     )
1144 1144
                 );
1145 1145
             }
@@ -1182,8 +1182,8 @@  discard block
 block discarded – undo
1182 1182
             $legacy_parent_class_map = array(
1183 1183
                 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php',
1184 1184
             );
1185
-            if (isset($legacy_parent_class_map[ $class_name ])) {
1186
-                require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ];
1185
+            if (isset($legacy_parent_class_map[$class_name])) {
1186
+                require_once EE_PLUGIN_DIR_PATH.$legacy_parent_class_map[$class_name];
1187 1187
             }
1188 1188
         } catch (Exception $exception) {
1189 1189
         }
@@ -1316,7 +1316,7 @@  discard block
 block discarded – undo
1316 1316
         // let's examine the constructor
1317 1317
         $constructor = $this->mirror->getConstructorFromReflection($reflector);
1318 1318
         // whu? huh? nothing?
1319
-        if (! $constructor) {
1319
+        if ( ! $constructor) {
1320 1320
             return $arguments;
1321 1321
         }
1322 1322
         // get constructor parameters
@@ -1336,7 +1336,7 @@  discard block
 block discarded – undo
1336 1336
                 $param_class === null
1337 1337
                 // and something already exists in the incoming arguments for this param
1338 1338
                 && array_key_exists($index, $argument_keys)
1339
-                && array_key_exists($argument_keys[ $index ], $arguments)
1339
+                && array_key_exists($argument_keys[$index], $arguments)
1340 1340
             ) {
1341 1341
                 // so let's skip this argument and move on to the next
1342 1342
                 continue;
@@ -1344,8 +1344,8 @@  discard block
 block discarded – undo
1344 1344
             if (
1345 1345
                 // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1346 1346
                 $param_class !== null
1347
-                && isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ])
1348
-                && $arguments[ $argument_keys[ $index ] ] instanceof $param_class
1347
+                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1348
+                && $arguments[$argument_keys[$index]] instanceof $param_class
1349 1349
             ) {
1350 1350
                 // skip this argument and move on to the next
1351 1351
                 continue;
@@ -1362,7 +1362,7 @@  discard block
 block discarded – undo
1362 1362
                     $index
1363 1363
                 );
1364 1364
             } else {
1365
-                $arguments[ $index ] = $this->mirror->getParameterDefaultValue(
1365
+                $arguments[$index] = $this->mirror->getParameterDefaultValue(
1366 1366
                     $param,
1367 1367
                     $class_name,
1368 1368
                     $index
@@ -1424,7 +1424,7 @@  discard block
 block discarded – undo
1424 1424
         // did we successfully find the correct dependency ?
1425 1425
         if ($dependency instanceof $param_class) {
1426 1426
             // then let's inject it into the incoming array of arguments at the correct location
1427
-            $arguments[ $index ] = $dependency;
1427
+            $arguments[$index] = $dependency;
1428 1428
         }
1429 1429
         return $arguments;
1430 1430
     }
@@ -1515,7 +1515,7 @@  discard block
 block discarded – undo
1515 1515
     {
1516 1516
         $addons = array();
1517 1517
         foreach ($this->addons as $addon) {
1518
-            $addons[ $addon->name() ] = $addon;
1518
+            $addons[$addon->name()] = $addon;
1519 1519
         }
1520 1520
         return $addons;
1521 1521
     }
@@ -1534,7 +1534,7 @@  discard block
 block discarded – undo
1534 1534
         $model_class_name = strpos($model_name, 'EEM_') !== 0
1535 1535
             ? "EEM_{$model_name}"
1536 1536
             : $model_name;
1537
-        if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1537
+        if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1538 1538
             return null;
1539 1539
         }
1540 1540
         //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.
Indentation   +1664 added lines, -1664 removed lines patch added patch discarded remove patch
@@ -27,1670 +27,1670 @@
 block discarded – undo
27 27
 class EE_Registry implements ResettableInterface
28 28
 {
29 29
 
30
-    /**
31
-     * @var EE_Registry $_instance
32
-     */
33
-    private static $_instance;
34
-
35
-    /**
36
-     * @var EE_Dependency_Map $_dependency_map
37
-     */
38
-    protected $_dependency_map;
39
-
40
-    /**
41
-     * @var Mirror
42
-     */
43
-    private $mirror;
44
-
45
-    /**
46
-     * @var ClassInterfaceCache $class_cache
47
-     */
48
-    private $class_cache;
49
-
50
-    /**
51
-     * @var array $_class_abbreviations
52
-     */
53
-    protected $_class_abbreviations = array();
54
-
55
-    /**
56
-     * @var CommandBusInterface $BUS
57
-     */
58
-    public $BUS;
59
-
60
-    /**
61
-     * @var EE_Cart $CART
62
-     */
63
-    public $CART;
64
-
65
-    /**
66
-     * @var EE_Config $CFG
67
-     */
68
-    public $CFG;
69
-
70
-    /**
71
-     * @var EE_Network_Config $NET_CFG
72
-     */
73
-    public $NET_CFG;
74
-
75
-    /**
76
-     * StdClass object for storing library classes in
77
-     *
78
-     * @var RegistryContainer $LIB
79
-     */
80
-    public $LIB;
81
-
82
-    /**
83
-     * @var EE_Request_Handler $REQ
84
-     */
85
-    public $REQ;
86
-
87
-    /**
88
-     * @var EE_Session $SSN
89
-     */
90
-    public $SSN;
91
-
92
-    /**
93
-     * @since 4.5.0
94
-     * @var EE_Capabilities $CAP
95
-     */
96
-    public $CAP;
97
-
98
-    /**
99
-     * @since 4.9.0
100
-     * @var EE_Message_Resource_Manager $MRM
101
-     */
102
-    public $MRM;
103
-
104
-    /**
105
-     * @var Registry $AssetsRegistry
106
-     */
107
-    public $AssetsRegistry;
108
-
109
-    /**
110
-     * StdClass object for holding addons which have registered themselves to work with EE core
111
-     *
112
-     * @var EE_Addon[] $addons
113
-     */
114
-    public $addons;
115
-
116
-    /**
117
-     * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
118
-     *
119
-     * @var EEM_Base[] $models
120
-     */
121
-    public $models = array();
122
-
123
-    /**
124
-     * @var EED_Module[] $modules
125
-     */
126
-    public $modules;
127
-
128
-    /**
129
-     * @var EES_Shortcode[] $shortcodes
130
-     */
131
-    public $shortcodes;
132
-
133
-    /**
134
-     * @var WP_Widget[] $widgets
135
-     */
136
-    public $widgets;
137
-
138
-    /**
139
-     * this is an array of all implemented model names (i.e. not the parent abstract models, or models
140
-     * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
141
-     * Keys are model "short names" (eg "Event") as used in model relations, and values are
142
-     * classnames (eg "EEM_Event")
143
-     *
144
-     * @var array $non_abstract_db_models
145
-     */
146
-    public $non_abstract_db_models = array();
147
-
148
-    /**
149
-     * internationalization for JS strings
150
-     *    usage:   EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' );
151
-     *    in js file:  var translatedString = eei18n.string_key;
152
-     *
153
-     * @var array $i18n_js_strings
154
-     */
155
-    public static $i18n_js_strings = array();
156
-
157
-    /**
158
-     * $main_file - path to espresso.php
159
-     *
160
-     * @var array $main_file
161
-     */
162
-    public $main_file;
163
-
164
-    /**
165
-     * array of ReflectionClass objects where the key is the class name
166
-     *
167
-     * @deprecated $VID:$
168
-     * @var ReflectionClass[] $_reflectors
169
-     */
170
-    public $_reflectors;
171
-
172
-    /**
173
-     * boolean flag to indicate whether or not to load/save dependencies from/to the cache
174
-     *
175
-     * @var boolean $_cache_on
176
-     */
177
-    protected $_cache_on = true;
178
-
179
-    /**
180
-     * @var ObjectIdentifier
181
-     */
182
-    private $object_identifier;
183
-
184
-
185
-    /**
186
-     * @singleton method used to instantiate class object
187
-     * @param EE_Dependency_Map|null   $dependency_map
188
-     * @param Mirror|null              $mirror
189
-     * @param ClassInterfaceCache|null $class_cache
190
-     * @param ObjectIdentifier|null    $object_identifier
191
-     * @return EE_Registry instance
192
-     */
193
-    public static function instance(
194
-        EE_Dependency_Map $dependency_map = null,
195
-        Mirror $mirror = null,
196
-        ClassInterfaceCache $class_cache = null,
197
-        ObjectIdentifier $object_identifier = null
198
-    ) {
199
-        // check if class object is instantiated
200
-        if (
201
-            ! self::$_instance instanceof EE_Registry
202
-            && $dependency_map instanceof EE_Dependency_Map
203
-            && $mirror instanceof Mirror
204
-            && $class_cache instanceof ClassInterfaceCache
205
-            && $object_identifier instanceof ObjectIdentifier
206
-        ) {
207
-            self::$_instance = new self(
208
-                $dependency_map,
209
-                $mirror,
210
-                $class_cache,
211
-                $object_identifier
212
-            );
213
-        }
214
-        return self::$_instance;
215
-    }
216
-
217
-
218
-    /**
219
-     * protected constructor to prevent direct creation
220
-     *
221
-     * @Constructor
222
-     * @param  EE_Dependency_Map  $dependency_map
223
-     * @param Mirror              $mirror
224
-     * @param ClassInterfaceCache $class_cache
225
-     * @param ObjectIdentifier    $object_identifier
226
-     */
227
-    protected function __construct(
228
-        EE_Dependency_Map $dependency_map,
229
-        Mirror $mirror,
230
-        ClassInterfaceCache $class_cache,
231
-        ObjectIdentifier $object_identifier
232
-    ) {
233
-        $this->_dependency_map   = $dependency_map;
234
-        $this->mirror            = $mirror;
235
-        $this->class_cache       = $class_cache;
236
-        $this->object_identifier = $object_identifier;
237
-        // $registry_container = new RegistryContainer();
238
-        $this->LIB        = new RegistryContainer();
239
-        $this->addons     = new RegistryContainer();
240
-        $this->modules    = new RegistryContainer();
241
-        $this->shortcodes = new RegistryContainer();
242
-        $this->widgets    = new RegistryContainer();
243
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
244
-    }
245
-
246
-
247
-    /**
248
-     * initialize
249
-     *
250
-     * @throws OutOfBoundsException
251
-     * @throws InvalidArgumentException
252
-     * @throws InvalidInterfaceException
253
-     * @throws InvalidDataTypeException
254
-     * @throws EE_Error
255
-     * @throws ReflectionException
256
-     */
257
-    public function initialize()
258
-    {
259
-        $this->_class_abbreviations = apply_filters(
260
-            'FHEE__EE_Registry____construct___class_abbreviations',
261
-            array(
262
-                'EE_Config'                                       => 'CFG',
263
-                'EE_Session'                                      => 'SSN',
264
-                'EE_Capabilities'                                 => 'CAP',
265
-                'EE_Cart'                                         => 'CART',
266
-                'EE_Network_Config'                               => 'NET_CFG',
267
-                'EE_Request_Handler'                              => 'REQ',
268
-                'EE_Message_Resource_Manager'                     => 'MRM',
269
-                'EventEspresso\core\services\commands\CommandBus' => 'BUS',
270
-                'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
271
-            )
272
-        );
273
-        $this->load_core('Base', array(), true);
274
-        // add our request and response objects to the cache
275
-        $request_loader = $this->_dependency_map->class_loader(
276
-            'EventEspresso\core\services\request\Request'
277
-        );
278
-        $this->_set_cached_class(
279
-            $request_loader(),
280
-            'EventEspresso\core\services\request\Request'
281
-        );
282
-        $response_loader = $this->_dependency_map->class_loader(
283
-            'EventEspresso\core\services\request\Response'
284
-        );
285
-        $this->_set_cached_class(
286
-            $response_loader(),
287
-            'EventEspresso\core\services\request\Response'
288
-        );
289
-        add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
290
-    }
291
-
292
-
293
-    /**
294
-     * @return void
295
-     */
296
-    public function init()
297
-    {
298
-        // Get current page protocol
299
-        $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
300
-        // Output admin-ajax.php URL with same protocol as current page
301
-        self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
302
-        self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
303
-    }
304
-
305
-
306
-    /**
307
-     * localize_i18n_js_strings
308
-     *
309
-     * @return string
310
-     */
311
-    public static function localize_i18n_js_strings()
312
-    {
313
-        $i18n_js_strings = (array) self::$i18n_js_strings;
314
-        foreach ($i18n_js_strings as $key => $value) {
315
-            if (is_scalar($value)) {
316
-                $i18n_js_strings[ $key ] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
317
-            }
318
-        }
319
-        return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
320
-    }
321
-
322
-
323
-    /**
324
-     * @param mixed string | EED_Module $module
325
-     * @throws OutOfBoundsException
326
-     * @throws InvalidArgumentException
327
-     * @throws InvalidInterfaceException
328
-     * @throws InvalidDataTypeException
329
-     * @throws EE_Error
330
-     * @throws ReflectionException
331
-     */
332
-    public function add_module($module)
333
-    {
334
-        if ($module instanceof EED_Module) {
335
-            $module_class                   = get_class($module);
336
-            $this->modules->{$module_class} = $module;
337
-        } else {
338
-            if (! class_exists('EE_Module_Request_Router', false)) {
339
-                $this->load_core('Module_Request_Router');
340
-            }
341
-            EE_Module_Request_Router::module_factory($module);
342
-        }
343
-    }
344
-
345
-
346
-    /**
347
-     * @param string $module_name
348
-     * @return mixed EED_Module | NULL
349
-     */
350
-    public function get_module($module_name = '')
351
-    {
352
-        return isset($this->modules->{$module_name})
353
-            ? $this->modules->{$module_name}
354
-            : null;
355
-    }
356
-
357
-
358
-    /**
359
-     * loads core classes - must be singletons
360
-     *
361
-     * @param string $class_name - simple class name ie: session
362
-     * @param mixed  $arguments
363
-     * @param bool   $load_only
364
-     * @return mixed
365
-     * @throws InvalidInterfaceException
366
-     * @throws InvalidDataTypeException
367
-     * @throws EE_Error
368
-     * @throws ReflectionException
369
-     * @throws InvalidArgumentException
370
-     */
371
-    public function load_core($class_name, $arguments = array(), $load_only = false)
372
-    {
373
-        $core_paths = apply_filters(
374
-            'FHEE__EE_Registry__load_core__core_paths',
375
-            array(
376
-                EE_CORE,
377
-                EE_ADMIN,
378
-                EE_CPTS,
379
-                EE_CORE . 'data_migration_scripts' . DS,
380
-                EE_CORE . 'capabilities' . DS,
381
-                EE_CORE . 'request_stack' . DS,
382
-                EE_CORE . 'middleware' . DS,
383
-            )
384
-        );
385
-        // retrieve instantiated class
386
-        return $this->_load(
387
-            $core_paths,
388
-            'EE_',
389
-            $class_name,
390
-            'core',
391
-            $arguments,
392
-            false,
393
-            true,
394
-            $load_only
395
-        );
396
-    }
397
-
398
-
399
-    /**
400
-     * loads service classes
401
-     *
402
-     * @param string $class_name - simple class name ie: session
403
-     * @param mixed  $arguments
404
-     * @param bool   $load_only
405
-     * @return mixed
406
-     * @throws InvalidInterfaceException
407
-     * @throws InvalidDataTypeException
408
-     * @throws EE_Error
409
-     * @throws ReflectionException
410
-     * @throws InvalidArgumentException
411
-     */
412
-    public function load_service($class_name, $arguments = array(), $load_only = false)
413
-    {
414
-        $service_paths = apply_filters(
415
-            'FHEE__EE_Registry__load_service__service_paths',
416
-            array(
417
-                EE_CORE . 'services' . DS,
418
-            )
419
-        );
420
-        // retrieve instantiated class
421
-        return $this->_load(
422
-            $service_paths,
423
-            'EE_',
424
-            $class_name,
425
-            'class',
426
-            $arguments,
427
-            false,
428
-            true,
429
-            $load_only
430
-        );
431
-    }
432
-
433
-
434
-    /**
435
-     * loads data_migration_scripts
436
-     *
437
-     * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
438
-     * @param mixed  $arguments
439
-     * @return EE_Data_Migration_Script_Base|mixed
440
-     * @throws InvalidInterfaceException
441
-     * @throws InvalidDataTypeException
442
-     * @throws EE_Error
443
-     * @throws ReflectionException
444
-     * @throws InvalidArgumentException
445
-     */
446
-    public function load_dms($class_name, $arguments = array())
447
-    {
448
-        // retrieve instantiated class
449
-        return $this->_load(
450
-            EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(),
451
-            'EE_DMS_',
452
-            $class_name,
453
-            'dms',
454
-            $arguments,
455
-            false,
456
-            false
457
-        );
458
-    }
459
-
460
-
461
-    /**
462
-     * loads object creating classes - must be singletons
463
-     *
464
-     * @param string $class_name - simple class name ie: attendee
465
-     * @param mixed  $arguments  - an array of arguments to pass to the class
466
-     * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to
467
-     *                           instantiate
468
-     * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then
469
-     *                           set this to FALSE (ie. when instantiating model objects from client in a loop)
470
-     * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate
471
-     *                           (default)
472
-     * @return EE_Base_Class | bool
473
-     * @throws InvalidInterfaceException
474
-     * @throws InvalidDataTypeException
475
-     * @throws EE_Error
476
-     * @throws ReflectionException
477
-     * @throws InvalidArgumentException
478
-     */
479
-    public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
480
-    {
481
-        $paths = apply_filters(
482
-            'FHEE__EE_Registry__load_class__paths', array(
483
-                EE_CORE,
484
-                EE_CLASSES,
485
-                EE_BUSINESS,
486
-            )
487
-        );
488
-        // retrieve instantiated class
489
-        return $this->_load(
490
-            $paths,
491
-            'EE_',
492
-            $class_name,
493
-            'class',
494
-            $arguments,
495
-            $from_db,
496
-            $cache,
497
-            $load_only
498
-        );
499
-    }
500
-
501
-
502
-    /**
503
-     * loads helper classes - must be singletons
504
-     *
505
-     * @param string $class_name - simple class name ie: price
506
-     * @param mixed  $arguments
507
-     * @param bool   $load_only
508
-     * @return EEH_Base | bool
509
-     * @throws InvalidInterfaceException
510
-     * @throws InvalidDataTypeException
511
-     * @throws EE_Error
512
-     * @throws ReflectionException
513
-     * @throws InvalidArgumentException
514
-     */
515
-    public function load_helper($class_name, $arguments = array(), $load_only = true)
516
-    {
517
-        // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
518
-        $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
519
-        // retrieve instantiated class
520
-        return $this->_load(
521
-            $helper_paths,
522
-            'EEH_',
523
-            $class_name,
524
-            'helper',
525
-            $arguments,
526
-            false,
527
-            true,
528
-            $load_only
529
-        );
530
-    }
531
-
532
-
533
-    /**
534
-     * loads core classes - must be singletons
535
-     *
536
-     * @param string $class_name - simple class name ie: session
537
-     * @param mixed  $arguments
538
-     * @param bool   $load_only
539
-     * @param bool   $cache      whether to cache the object or not.
540
-     * @return mixed
541
-     * @throws InvalidInterfaceException
542
-     * @throws InvalidDataTypeException
543
-     * @throws EE_Error
544
-     * @throws ReflectionException
545
-     * @throws InvalidArgumentException
546
-     */
547
-    public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
548
-    {
549
-        $paths = array(
550
-            EE_LIBRARIES,
551
-            EE_LIBRARIES . 'messages' . DS,
552
-            EE_LIBRARIES . 'shortcodes' . DS,
553
-            EE_LIBRARIES . 'qtips' . DS,
554
-            EE_LIBRARIES . 'payment_methods' . DS,
555
-        );
556
-        // retrieve instantiated class
557
-        return $this->_load(
558
-            $paths,
559
-            'EE_',
560
-            $class_name,
561
-            'lib',
562
-            $arguments,
563
-            false,
564
-            $cache,
565
-            $load_only
566
-        );
567
-    }
568
-
569
-
570
-    /**
571
-     * loads model classes - must be singletons
572
-     *
573
-     * @param string $class_name - simple class name ie: price
574
-     * @param mixed  $arguments
575
-     * @param bool   $load_only
576
-     * @return EEM_Base | bool
577
-     * @throws InvalidInterfaceException
578
-     * @throws InvalidDataTypeException
579
-     * @throws EE_Error
580
-     * @throws ReflectionException
581
-     * @throws InvalidArgumentException
582
-     */
583
-    public function load_model($class_name, $arguments = array(), $load_only = false)
584
-    {
585
-        $paths = apply_filters(
586
-            'FHEE__EE_Registry__load_model__paths', array(
587
-                EE_MODELS,
588
-                EE_CORE,
589
-            )
590
-        );
591
-        // retrieve instantiated class
592
-        return $this->_load(
593
-            $paths,
594
-            'EEM_',
595
-            $class_name,
596
-            'model',
597
-            $arguments,
598
-            false,
599
-            true,
600
-            $load_only
601
-        );
602
-    }
603
-
604
-
605
-    /**
606
-     * loads model classes - must be singletons
607
-     *
608
-     * @param string $class_name - simple class name ie: price
609
-     * @param mixed  $arguments
610
-     * @param bool   $load_only
611
-     * @return mixed | bool
612
-     * @throws InvalidInterfaceException
613
-     * @throws InvalidDataTypeException
614
-     * @throws EE_Error
615
-     * @throws ReflectionException
616
-     * @throws InvalidArgumentException
617
-     */
618
-    public function load_model_class($class_name, $arguments = array(), $load_only = true)
619
-    {
620
-        $paths = array(
621
-            EE_MODELS . 'fields' . DS,
622
-            EE_MODELS . 'helpers' . DS,
623
-            EE_MODELS . 'relations' . DS,
624
-            EE_MODELS . 'strategies' . DS,
625
-        );
626
-        // retrieve instantiated class
627
-        return $this->_load(
628
-            $paths,
629
-            'EE_',
630
-            $class_name,
631
-            '',
632
-            $arguments,
633
-            false,
634
-            true,
635
-            $load_only
636
-        );
637
-    }
638
-
639
-
640
-    /**
641
-     * Determines if $model_name is the name of an actual EE model.
642
-     *
643
-     * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
644
-     * @return boolean
645
-     */
646
-    public function is_model_name($model_name)
647
-    {
648
-        return isset($this->models[ $model_name ]);
649
-    }
650
-
651
-
652
-    /**
653
-     * generic class loader
654
-     *
655
-     * @param string $path_to_file - directory path to file location, not including filename
656
-     * @param string $file_name    - file name  ie:  my_file.php, including extension
657
-     * @param string $type         - file type - core? class? helper? model?
658
-     * @param mixed  $arguments
659
-     * @param bool   $load_only
660
-     * @return mixed
661
-     * @throws InvalidInterfaceException
662
-     * @throws InvalidDataTypeException
663
-     * @throws EE_Error
664
-     * @throws ReflectionException
665
-     * @throws InvalidArgumentException
666
-     */
667
-    public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
668
-    {
669
-        // retrieve instantiated class
670
-        return $this->_load(
671
-            $path_to_file,
672
-            '',
673
-            $file_name,
674
-            $type,
675
-            $arguments,
676
-            false,
677
-            true,
678
-            $load_only
679
-        );
680
-    }
681
-
682
-
683
-    /**
684
-     * @param string $path_to_file - directory path to file location, not including filename
685
-     * @param string $class_name   - full class name  ie:  My_Class
686
-     * @param string $type         - file type - core? class? helper? model?
687
-     * @param mixed  $arguments
688
-     * @param bool   $load_only
689
-     * @return bool|EE_Addon|object
690
-     * @throws InvalidInterfaceException
691
-     * @throws InvalidDataTypeException
692
-     * @throws EE_Error
693
-     * @throws ReflectionException
694
-     * @throws InvalidArgumentException
695
-     */
696
-    public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
697
-    {
698
-        // retrieve instantiated class
699
-        return $this->_load(
700
-            $path_to_file,
701
-            'addon',
702
-            $class_name,
703
-            $type,
704
-            $arguments,
705
-            false,
706
-            true,
707
-            $load_only
708
-        );
709
-    }
710
-
711
-
712
-    /**
713
-     * instantiates, caches, and automatically resolves dependencies
714
-     * for classes that use a Fully Qualified Class Name.
715
-     * if the class is not capable of being loaded using PSR-4 autoloading,
716
-     * then you need to use one of the existing load_*() methods
717
-     * which can resolve the classname and filepath from the passed arguments
718
-     *
719
-     * @param bool|string $class_name   Fully Qualified Class Name
720
-     * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
721
-     * @param bool        $cache        whether to cache the instantiated object for reuse
722
-     * @param bool        $from_db      some classes are instantiated from the db
723
-     *                                  and thus call a different method to instantiate
724
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
725
-     * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
726
-     * @return bool|null|mixed          null = failure to load or instantiate class object.
727
-     *                                  object = class loaded and instantiated successfully.
728
-     *                                  bool = fail or success when $load_only is true
729
-     * @throws InvalidInterfaceException
730
-     * @throws InvalidDataTypeException
731
-     * @throws EE_Error
732
-     * @throws ReflectionException
733
-     * @throws InvalidArgumentException
734
-     */
735
-    public function create(
736
-        $class_name = false,
737
-        $arguments = array(),
738
-        $cache = false,
739
-        $from_db = false,
740
-        $load_only = false,
741
-        $addon = false
742
-    ) {
743
-        $class_name   = ltrim($class_name, '\\');
744
-        $class_name   = $this->class_cache->getFqnForAlias($class_name);
745
-        $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
746
-        // if a non-FQCN was passed, then
747
-        // verifyClassExists() might return an object
748
-        // or it could return null if the class just could not be found anywhere
749
-        if ($class_exists instanceof $class_name || $class_exists === null) {
750
-            // either way, return the results
751
-            return $class_exists;
752
-        }
753
-        $class_name = $class_exists;
754
-        // if we're only loading the class and it already exists, then let's just return true immediately
755
-        if ($load_only) {
756
-            return true;
757
-        }
758
-        $addon = $addon ? 'addon' : '';
759
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
760
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
761
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
762
-        if ($this->_cache_on && $cache && ! $load_only) {
763
-            // return object if it's already cached
764
-            $cached_class = $this->_get_cached_class($class_name, $addon, $arguments);
765
-            if ($cached_class !== null) {
766
-                return $cached_class;
767
-            }
768
-        }// obtain the loader method from the dependency map
769
-        $loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object
770
-        if ($loader instanceof Closure) {
771
-            $class_obj = $loader($arguments);
772
-        } else {
773
-            if ($loader && method_exists($this, $loader)) {
774
-                $class_obj = $this->{$loader}($class_name, $arguments);
775
-            } else {
776
-                $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
777
-            }
778
-        }
779
-        if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) {
780
-            // save it for later... kinda like gum  { : $
781
-            $this->_set_cached_class(
782
-                $class_obj,
783
-                $class_name,
784
-                $addon,
785
-                $from_db,
786
-                $arguments
787
-            );
788
-        }
789
-        $this->_cache_on = true;
790
-        return $class_obj;
791
-    }
792
-
793
-
794
-    /**
795
-     * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
796
-     *
797
-     * @param string|object $class_name
798
-     * @param array         $arguments
799
-     * @param int           $attempt
800
-     * @return mixed
801
-     */
802
-    private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1)
803
-    {
804
-        if (is_object($class_name) || class_exists($class_name)) {
805
-            return $class_name;
806
-        }
807
-        switch ($attempt) {
808
-            case 1:
809
-                // if it's a FQCN then maybe the class is registered with a preceding \
810
-                $class_name = strpos($class_name, '\\') !== false
811
-                    ? '\\' . ltrim($class_name, '\\')
812
-                    : $class_name;
813
-                break;
814
-            case 2:
815
-                //
816
-                $loader = $this->_dependency_map->class_loader($class_name);
817
-                if ($loader && method_exists($this, $loader)) {
818
-                    return $this->{$loader}($class_name, $arguments);
819
-                }
820
-                break;
821
-            case 3:
822
-            default;
823
-                return null;
824
-        }
825
-        $attempt++;
826
-        return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt);
827
-    }
828
-
829
-
830
-    /**
831
-     * instantiates, caches, and injects dependencies for classes
832
-     *
833
-     * @param array       $file_paths   an array of paths to folders to look in
834
-     * @param string      $class_prefix EE  or EEM or... ???
835
-     * @param bool|string $class_name   $class name
836
-     * @param string      $type         file type - core? class? helper? model?
837
-     * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
838
-     * @param bool        $from_db      some classes are instantiated from the db
839
-     *                                  and thus call a different method to instantiate
840
-     * @param bool        $cache        whether to cache the instantiated object for reuse
841
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
842
-     * @return bool|null|object null = failure to load or instantiate class object.
843
-     *                                  object = class loaded and instantiated successfully.
844
-     *                                  bool = fail or success when $load_only is true
845
-     * @throws EE_Error
846
-     * @throws ReflectionException
847
-     * @throws InvalidInterfaceException
848
-     * @throws InvalidDataTypeException
849
-     * @throws InvalidArgumentException
850
-     */
851
-    protected function _load(
852
-        $file_paths = array(),
853
-        $class_prefix = 'EE_',
854
-        $class_name = false,
855
-        $type = 'class',
856
-        $arguments = array(),
857
-        $from_db = false,
858
-        $cache = true,
859
-        $load_only = false
860
-    ) {
861
-        $class_name = ltrim($class_name, '\\');
862
-        // strip php file extension
863
-        $class_name = str_replace('.php', '', trim($class_name));
864
-        // does the class have a prefix ?
865
-        if (! empty($class_prefix) && $class_prefix !== 'addon') {
866
-            // make sure $class_prefix is uppercase
867
-            $class_prefix = strtoupper(trim($class_prefix));
868
-            // add class prefix ONCE!!!
869
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
870
-        }
871
-        $class_name   = $this->class_cache->getFqnForAlias($class_name);
872
-        $class_exists = class_exists($class_name, false);
873
-        // if we're only loading the class and it already exists, then let's just return true immediately
874
-        if ($load_only && $class_exists) {
875
-            return true;
876
-        }
877
-        $arguments = is_array($arguments) ? $arguments : array($arguments);
878
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
879
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
880
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
881
-        if ($this->_cache_on && $cache && ! $load_only) {
882
-            // return object if it's already cached
883
-            $cached_class = $this->_get_cached_class($class_name, $class_prefix, $arguments);
884
-            if ($cached_class !== null) {
885
-                return $cached_class;
886
-            }
887
-        }
888
-        // if the class doesn't already exist.. then we need to try and find the file and load it
889
-        if (! $class_exists) {
890
-            // get full path to file
891
-            $path = $this->_resolve_path($class_name, $type, $file_paths);
892
-            // load the file
893
-            $loaded = $this->_require_file($path, $class_name, $type, $file_paths);
894
-            // if we are only loading a file but NOT instantiating an object
895
-            // then return boolean for whether class was loaded or not
896
-            if ($load_only) {
897
-                return $loaded;
898
-            }
899
-            // if an object was expected but loading failed, then return nothing
900
-            if (! $loaded) {
901
-                return null;
902
-            }
903
-        }
904
-        // instantiate the requested object
905
-        $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
906
-        if ($this->_cache_on && $cache) {
907
-            // save it for later... kinda like gum  { : $
908
-            $this->_set_cached_class(
909
-                $class_obj,
910
-                $class_name,
911
-                $class_prefix,
912
-                $from_db,
913
-                $arguments
914
-            );
915
-        }
916
-        $this->_cache_on = true;
917
-        return $class_obj;
918
-    }
919
-
920
-
921
-    /**
922
-     * @param string $class_name
923
-     * @param string $default have to specify something, but not anything that will conflict
924
-     * @return mixed|string
925
-     */
926
-    protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS')
927
-    {
928
-        return isset($this->_class_abbreviations[ $class_name ])
929
-            ? $this->_class_abbreviations[ $class_name ]
930
-            : $default;
931
-    }
932
-
933
-
934
-    /**
935
-     * attempts to find a cached version of the requested class
936
-     * by looking in the following places:
937
-     *        $this->{$class_abbreviation}            ie:    $this->CART
938
-     *        $this->{$class_name}                        ie:    $this->Some_Class
939
-     *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
940
-     *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
941
-     *
942
-     * @param string $class_name
943
-     * @param string $class_prefix
944
-     * @param array  $arguments
945
-     * @return mixed
946
-     */
947
-    protected function _get_cached_class(
948
-        $class_name,
949
-        $class_prefix = '',
950
-        $arguments = array()
951
-    ) {
952
-        if ($class_name === 'EE_Registry') {
953
-            return $this;
954
-        }
955
-        $class_abbreviation = $this->get_class_abbreviation($class_name);
956
-        // check if class has already been loaded, and return it if it has been
957
-        if (isset($this->{$class_abbreviation})) {
958
-            return $this->{$class_abbreviation};
959
-        }
960
-        $class_name = str_replace('\\', '_', $class_name);
961
-        if (isset ($this->{$class_name})) {
962
-            return $this->{$class_name};
963
-        }
964
-        if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
965
-            return $this->addons->{$class_name};
966
-        }
967
-        $object_identifier = $this->object_identifier->getIdentifier($class_name, $arguments);
968
-        if (isset($this->LIB->{$object_identifier})) {
969
-            return $this->LIB->{$object_identifier};
970
-        }
971
-        foreach ($this->LIB as $key => $object) {
972
-            if (
973
-                // request does not contain new arguments and therefore no args identifier
974
-                ! $this->object_identifier->hasArguments($object_identifier)
975
-                // but previously cached class with args was found
976
-                && $this->object_identifier->fqcnMatchesObjectIdentifier($class_name, $key)
977
-            ) {
978
-                return $object;
979
-            }
980
-        }
981
-        return null;
982
-    }
983
-
984
-
985
-    /**
986
-     * removes a cached version of the requested class
987
-     *
988
-     * @param string  $class_name
989
-     * @param boolean $addon
990
-     * @param array   $arguments
991
-     * @return boolean
992
-     */
993
-    public function clear_cached_class(
994
-        $class_name,
995
-        $addon = false,
996
-        $arguments = array()
997
-    ) {
998
-        $class_abbreviation = $this->get_class_abbreviation($class_name);
999
-        // check if class has already been loaded, and return it if it has been
1000
-        if (isset($this->{$class_abbreviation})) {
1001
-            $this->{$class_abbreviation} = null;
1002
-            return true;
1003
-        }
1004
-        $class_name = str_replace('\\', '_', $class_name);
1005
-        if (isset($this->{$class_name})) {
1006
-            $this->{$class_name} = null;
1007
-            return true;
1008
-        }
1009
-        if ($addon && isset($this->addons->{$class_name})) {
1010
-            unset($this->addons->{$class_name});
1011
-            return true;
1012
-        }
1013
-        $class_name = $this->object_identifier->getIdentifier($class_name, $arguments);
1014
-        if (isset($this->LIB->{$class_name})) {
1015
-            unset($this->LIB->{$class_name});
1016
-            return true;
1017
-        }
1018
-        return false;
1019
-    }
1020
-
1021
-
1022
-    /**
1023
-     * _set_cached_class
1024
-     * attempts to cache the instantiated class locally
1025
-     * in one of the following places, in the following order:
1026
-     *        $this->{class_abbreviation}   ie:    $this->CART
1027
-     *        $this->{$class_name}          ie:    $this->Some_Class
1028
-     *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1029
-     *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1030
-     *
1031
-     * @param object $class_obj
1032
-     * @param string $class_name
1033
-     * @param string $class_prefix
1034
-     * @param bool   $from_db
1035
-     * @param array  $arguments
1036
-     * @return void
1037
-     */
1038
-    protected function _set_cached_class(
1039
-        $class_obj,
1040
-        $class_name,
1041
-        $class_prefix = '',
1042
-        $from_db = false,
1043
-        $arguments = array()
1044
-    ) {
1045
-        if ($class_name === 'EE_Registry' || empty($class_obj)) {
1046
-            return;
1047
-        }
1048
-        // return newly instantiated class
1049
-        $class_abbreviation = $this->get_class_abbreviation($class_name, '');
1050
-        if ($class_abbreviation) {
1051
-            $this->{$class_abbreviation} = $class_obj;
1052
-            return;
1053
-        }
1054
-        $class_name = str_replace('\\', '_', $class_name);
1055
-        if (property_exists($this, $class_name)) {
1056
-            $this->{$class_name} = $class_obj;
1057
-            return;
1058
-        }
1059
-        if ($class_prefix === 'addon') {
1060
-            $this->addons->{$class_name} = $class_obj;
1061
-            return;
1062
-        }
1063
-        if (! $from_db) {
1064
-            $class_name               = $this->object_identifier->getIdentifier($class_name, $arguments);
1065
-            $this->LIB->{$class_name} = $class_obj;
1066
-        }
1067
-    }
1068
-
1069
-
1070
-    /**
1071
-     * attempts to find a full valid filepath for the requested class.
1072
-     * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
1073
-     * then returns that path if the target file has been found and is readable
1074
-     *
1075
-     * @param string $class_name
1076
-     * @param string $type
1077
-     * @param array  $file_paths
1078
-     * @return string | bool
1079
-     */
1080
-    protected function _resolve_path($class_name, $type = '', $file_paths = array())
1081
-    {
1082
-        // make sure $file_paths is an array
1083
-        $file_paths = is_array($file_paths)
1084
-            ? $file_paths
1085
-            : array($file_paths);
1086
-        // cycle thru paths
1087
-        foreach ($file_paths as $key => $file_path) {
1088
-            // convert all separators to proper DS, if no filepath, then use EE_CLASSES
1089
-            $file_path = $file_path
1090
-                ? str_replace(array('/', '\\'), DS, $file_path)
1091
-                : EE_CLASSES;
1092
-            // prep file type
1093
-            $type = ! empty($type)
1094
-                ? trim($type, '.') . '.'
1095
-                : '';
1096
-            // build full file path
1097
-            $file_paths[ $key ] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
1098
-            //does the file exist and can be read ?
1099
-            if (is_readable($file_paths[ $key ])) {
1100
-                return $file_paths[ $key ];
1101
-            }
1102
-        }
1103
-        return false;
1104
-    }
1105
-
1106
-
1107
-    /**
1108
-     * basically just performs a require_once()
1109
-     * but with some error handling
1110
-     *
1111
-     * @param  string $path
1112
-     * @param  string $class_name
1113
-     * @param  string $type
1114
-     * @param  array  $file_paths
1115
-     * @return bool
1116
-     * @throws EE_Error
1117
-     * @throws ReflectionException
1118
-     */
1119
-    protected function _require_file($path, $class_name, $type = '', $file_paths = array())
1120
-    {
1121
-        $this->resolve_legacy_class_parent($class_name);
1122
-        // don't give up! you gotta...
1123
-        try {
1124
-            //does the file exist and can it be read ?
1125
-            if (! $path) {
1126
-                // just in case the file has already been autoloaded,
1127
-                // but discrepancies in the naming schema are preventing it from
1128
-                // being loaded via one of the EE_Registry::load_*() methods,
1129
-                // then let's try one last hail mary before throwing an exception
1130
-                // and call class_exists() again, but with autoloading turned ON
1131
-                if (class_exists($class_name)) {
1132
-                    return true;
1133
-                }
1134
-                // so sorry, can't find the file
1135
-                throw new EE_Error (
1136
-                    sprintf(
1137
-                        esc_html__(
1138
-                            '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',
1139
-                            'event_espresso'
1140
-                        ),
1141
-                        trim($type, '.'),
1142
-                        $class_name,
1143
-                        '<br />' . implode(',<br />', $file_paths)
1144
-                    )
1145
-                );
1146
-            }
1147
-            // get the file
1148
-            require_once($path);
1149
-            // if the class isn't already declared somewhere
1150
-            if (class_exists($class_name, false) === false) {
1151
-                // so sorry, not a class
1152
-                throw new EE_Error(
1153
-                    sprintf(
1154
-                        esc_html__(
1155
-                            'The %s file %s does not appear to contain the %s Class.',
1156
-                            'event_espresso'
1157
-                        ),
1158
-                        $type,
1159
-                        $path,
1160
-                        $class_name
1161
-                    )
1162
-                );
1163
-            }
1164
-        } catch (EE_Error $e) {
1165
-            $e->get_error();
1166
-            return false;
1167
-        }
1168
-        return true;
1169
-    }
1170
-
1171
-
1172
-    /**
1173
-     * Some of our legacy classes that extended a parent class would simply use a require() statement
1174
-     * before their class declaration in order to ensure that the parent class was loaded.
1175
-     * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class,
1176
-     * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist.
1177
-     *
1178
-     * @param string $class_name
1179
-     */
1180
-    protected function resolve_legacy_class_parent($class_name = '')
1181
-    {
1182
-        try {
1183
-            $legacy_parent_class_map = array(
1184
-                'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php',
1185
-            );
1186
-            if (isset($legacy_parent_class_map[ $class_name ])) {
1187
-                require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ];
1188
-            }
1189
-        } catch (Exception $exception) {
1190
-        }
1191
-    }
1192
-
1193
-
1194
-    /**
1195
-     * _create_object
1196
-     * Attempts to instantiate the requested class via any of the
1197
-     * commonly used instantiation methods employed throughout EE.
1198
-     * The priority for instantiation is as follows:
1199
-     *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
1200
-     *        - model objects via their 'new_instance_from_db' method
1201
-     *        - model objects via their 'new_instance' method
1202
-     *        - "singleton" classes" via their 'instance' method
1203
-     *    - standard instantiable classes via their __constructor
1204
-     * Prior to instantiation, if the classname exists in the dependency_map,
1205
-     * then the constructor for the requested class will be examined to determine
1206
-     * if any dependencies exist, and if they can be injected.
1207
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1208
-     *
1209
-     * @param string $class_name
1210
-     * @param array  $arguments
1211
-     * @param string $type
1212
-     * @param bool   $from_db
1213
-     * @return null|object|bool
1214
-     * @throws InvalidArgumentException
1215
-     * @throws InvalidInterfaceException
1216
-     * @throws EE_Error
1217
-     * @throws ReflectionException
1218
-     * @throws InvalidDataTypeException
1219
-     */
1220
-    protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
1221
-    {
1222
-        // create reflection
1223
-        $reflector = $this->mirror->getReflectionClass($class_name);
1224
-        // make sure arguments are an array
1225
-        $arguments = is_array($arguments)
1226
-            ? $arguments
1227
-            : array($arguments);
1228
-        // and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
1229
-        // else wrap it in an additional array so that it doesn't get split into multiple parameters
1230
-        $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
1231
-            ? $arguments
1232
-            : array($arguments);
1233
-        // attempt to inject dependencies ?
1234
-        if ($this->_dependency_map->has($class_name)) {
1235
-            $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
1236
-        }
1237
-        // instantiate the class if possible
1238
-        if ($reflector->isAbstract()) {
1239
-            // nothing to instantiate, loading file was enough
1240
-            // does not throw an exception so $instantiation_mode is unused
1241
-            // $instantiation_mode = "1) no constructor abstract class";
1242
-            return true;
1243
-        }
1244
-        if (
1245
-            empty($arguments)
1246
-            && $this->mirror->getConstructorFromReflection($reflector) === null
1247
-            && $reflector->isInstantiable()
1248
-        ) {
1249
-            // no constructor = static methods only... nothing to instantiate, loading file was enough
1250
-            // $instantiation_mode = "2) no constructor but instantiable";
1251
-            return $reflector->newInstance();
1252
-        }
1253
-        if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
1254
-            // $instantiation_mode = "3) new_instance_from_db()";
1255
-            return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
1256
-        }
1257
-        if (method_exists($class_name, 'new_instance')) {
1258
-            // $instantiation_mode = "4) new_instance()";
1259
-            return call_user_func_array(array($class_name, 'new_instance'), $arguments);
1260
-        }
1261
-        if (method_exists($class_name, 'instance')) {
1262
-            // $instantiation_mode = "5) instance()";
1263
-            return call_user_func_array(array($class_name, 'instance'), $arguments);
1264
-        }
1265
-        if ($reflector->isInstantiable()) {
1266
-            // $instantiation_mode = "6) constructor";
1267
-            return $reflector->newInstanceArgs($arguments);
1268
-        }
1269
-        // heh ? something's not right !
1270
-        throw new EE_Error(
1271
-            sprintf(
1272
-                __('The %s file %s could not be instantiated.', 'event_espresso'),
1273
-                $type,
1274
-                $class_name
1275
-            )
1276
-        );
1277
-    }
1278
-
1279
-
1280
-    /**
1281
-     * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1282
-     * @param array $array
1283
-     * @return bool
1284
-     */
1285
-    protected function _array_is_numerically_and_sequentially_indexed(array $array)
1286
-    {
1287
-        return ! empty($array)
1288
-            ? array_keys($array) === range(0, count($array) - 1)
1289
-            : true;
1290
-    }
1291
-
1292
-
1293
-    /**
1294
-     * _resolve_dependencies
1295
-     * examines the constructor for the requested class to determine
1296
-     * if any dependencies exist, and if they can be injected.
1297
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1298
-     * PLZ NOTE: this is achieved by type hinting the constructor params
1299
-     * For example:
1300
-     *        if attempting to load a class "Foo" with the following constructor:
1301
-     *        __construct( Bar $bar_class, Fighter $grohl_class )
1302
-     *        then $bar_class and $grohl_class will be added to the $arguments array,
1303
-     *        but only IF they are NOT already present in the incoming arguments array,
1304
-     *        and the correct classes can be loaded
1305
-     *
1306
-     * @param ReflectionClass $reflector
1307
-     * @param string          $class_name
1308
-     * @param array           $arguments
1309
-     * @return array
1310
-     * @throws InvalidArgumentException
1311
-     * @throws InvalidDataTypeException
1312
-     * @throws InvalidInterfaceException
1313
-     * @throws ReflectionException
1314
-     */
1315
-    protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, array $arguments = array())
1316
-    {
1317
-        // let's examine the constructor
1318
-        $constructor = $this->mirror->getConstructorFromReflection($reflector);
1319
-        // whu? huh? nothing?
1320
-        if (! $constructor) {
1321
-            return $arguments;
1322
-        }
1323
-        // get constructor parameters
1324
-        $params = $this->mirror->getParametersFromReflection($reflector);
1325
-        // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1326
-        $argument_keys = array_keys($arguments);
1327
-        // now loop thru all of the constructors expected parameters
1328
-        foreach ($params as $index => $param) {
1329
-            // is this a dependency for a specific class ?
1330
-            $param_class = $this->mirror->getParameterClassName($param, $class_name, $index);
1331
-            // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1332
-            $param_class = $this->class_cache->isAlias($param_class, $class_name)
1333
-                ? $this->class_cache->getFqnForAlias($param_class, $class_name)
1334
-                : $param_class;
1335
-            if (
1336
-                // param is not even a class
1337
-                $param_class === null
1338
-                // and something already exists in the incoming arguments for this param
1339
-                && array_key_exists($index, $argument_keys)
1340
-                && array_key_exists($argument_keys[ $index ], $arguments)
1341
-            ) {
1342
-                // so let's skip this argument and move on to the next
1343
-                continue;
1344
-            }
1345
-            if (
1346
-                // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1347
-                $param_class !== null
1348
-                && isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ])
1349
-                && $arguments[ $argument_keys[ $index ] ] instanceof $param_class
1350
-            ) {
1351
-                // skip this argument and move on to the next
1352
-                continue;
1353
-            }
1354
-            if (
1355
-                // parameter is type hinted as a class, and should be injected
1356
-                $param_class !== null
1357
-                && $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1358
-            ) {
1359
-                $arguments = $this->_resolve_dependency(
1360
-                    $class_name,
1361
-                    $param_class,
1362
-                    $arguments,
1363
-                    $index
1364
-                );
1365
-            } else {
1366
-                $arguments[ $index ] = $this->mirror->getParameterDefaultValue(
1367
-                    $param,
1368
-                    $class_name,
1369
-                    $index
1370
-                );
1371
-            }
1372
-        }
1373
-        return $arguments;
1374
-    }
1375
-
1376
-
1377
-    /**
1378
-     * @param string $class_name
1379
-     * @param string $param_class
1380
-     * @param array  $arguments
1381
-     * @param mixed  $index
1382
-     * @return array
1383
-     * @throws InvalidArgumentException
1384
-     * @throws InvalidInterfaceException
1385
-     * @throws InvalidDataTypeException
1386
-     */
1387
-    protected function _resolve_dependency($class_name, $param_class, $arguments, $index)
1388
-    {
1389
-        $dependency = null;
1390
-        // should dependency be loaded from cache ?
1391
-        $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency(
1392
-            $class_name,
1393
-            $param_class
1394
-        );
1395
-        $cache_on = $cache_on !== EE_Dependency_Map::load_new_object;
1396
-        // we might have a dependency...
1397
-        // let's MAYBE try and find it in our cache if that's what's been requested
1398
-        $cached_class = $cache_on
1399
-            ? $this->_get_cached_class($param_class)
1400
-            : null;
1401
-        // and grab it if it exists
1402
-        if ($cached_class instanceof $param_class) {
1403
-            $dependency = $cached_class;
1404
-        } elseif ($param_class !== $class_name) {
1405
-            // obtain the loader method from the dependency map
1406
-            $loader = $this->_dependency_map->class_loader($param_class);
1407
-            // is loader a custom closure ?
1408
-            if ($loader instanceof Closure) {
1409
-                $dependency = $loader($arguments);
1410
-            } else {
1411
-                // set the cache on property for the recursive loading call
1412
-                $this->_cache_on = $cache_on;
1413
-                // if not, then let's try and load it via the registry
1414
-                if ($loader && method_exists($this, $loader)) {
1415
-                    $dependency = $this->{$loader}($param_class);
1416
-                } else {
1417
-                    $dependency = LoaderFactory::getLoader()->load(
1418
-                        $param_class,
1419
-                        array(),
1420
-                        $cache_on
1421
-                    );
1422
-                }
1423
-            }
1424
-        }
1425
-        // did we successfully find the correct dependency ?
1426
-        if ($dependency instanceof $param_class) {
1427
-            // then let's inject it into the incoming array of arguments at the correct location
1428
-            $arguments[ $index ] = $dependency;
1429
-        }
1430
-        return $arguments;
1431
-    }
1432
-
1433
-
1434
-    /**
1435
-     * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1436
-     *
1437
-     * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1438
-     *                          in the EE_Dependency_Map::$_class_loaders array,
1439
-     *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1440
-     * @param array  $arguments
1441
-     * @return object
1442
-     */
1443
-    public static function factory($classname, $arguments = array())
1444
-    {
1445
-        $loader = self::instance()->_dependency_map->class_loader($classname);
1446
-        if ($loader instanceof Closure) {
1447
-            return $loader($arguments);
1448
-        }
1449
-        if (method_exists(self::instance(), $loader)) {
1450
-            return self::instance()->{$loader}($classname, $arguments);
1451
-        }
1452
-        return null;
1453
-    }
1454
-
1455
-
1456
-    /**
1457
-     * Gets the addon by its class name
1458
-     *
1459
-     * @param string $class_name
1460
-     * @return EE_Addon
1461
-     */
1462
-    public function getAddon($class_name)
1463
-    {
1464
-        $class_name = str_replace('\\', '_', $class_name);
1465
-        return $this->addons->{$class_name};
1466
-    }
1467
-
1468
-
1469
-    /**
1470
-     * removes the addon from the internal cache
1471
-     *
1472
-     * @param string $class_name
1473
-     * @return void
1474
-     */
1475
-    public function removeAddon($class_name)
1476
-    {
1477
-        $class_name = str_replace('\\', '_', $class_name);
1478
-        unset($this->addons->{$class_name});
1479
-    }
1480
-
1481
-
1482
-    /**
1483
-     * Gets the addon by its name/slug (not classname. For that, just
1484
-     * use the get_addon() method above
1485
-     *
1486
-     * @param string $name
1487
-     * @return EE_Addon
1488
-     */
1489
-    public function get_addon_by_name($name)
1490
-    {
1491
-        foreach ($this->addons as $addon) {
1492
-            if ($addon->name() === $name) {
1493
-                return $addon;
1494
-            }
1495
-        }
1496
-        return null;
1497
-    }
1498
-
1499
-
1500
-    /**
1501
-     * Gets an array of all the registered addons, where the keys are their names.
1502
-     * (ie, what each returns for their name() function)
1503
-     * They're already available on EE_Registry::instance()->addons as properties,
1504
-     * where each property's name is the addon's classname,
1505
-     * So if you just want to get the addon by classname,
1506
-     * OR use the get_addon() method above.
1507
-     * PLEASE  NOTE:
1508
-     * addons with Fully Qualified Class Names
1509
-     * have had the namespace separators converted to underscores,
1510
-     * so a classname like Fully\Qualified\ClassName
1511
-     * would have been converted to Fully_Qualified_ClassName
1512
-     *
1513
-     * @return EE_Addon[] where the KEYS are the addon's name()
1514
-     */
1515
-    public function get_addons_by_name()
1516
-    {
1517
-        $addons = array();
1518
-        foreach ($this->addons as $addon) {
1519
-            $addons[ $addon->name() ] = $addon;
1520
-        }
1521
-        return $addons;
1522
-    }
1523
-
1524
-
1525
-    /**
1526
-     * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1527
-     * a stale copy of it around
1528
-     *
1529
-     * @param string $model_name
1530
-     * @return \EEM_Base
1531
-     * @throws \EE_Error
1532
-     */
1533
-    public function reset_model($model_name)
1534
-    {
1535
-        $model_class_name = strpos($model_name, 'EEM_') !== 0
1536
-            ? "EEM_{$model_name}"
1537
-            : $model_name;
1538
-        if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1539
-            return null;
1540
-        }
1541
-        //get that model reset it and make sure we nuke the old reference to it
1542
-        if ($this->LIB->{$model_class_name} instanceof $model_class_name
1543
-            && is_callable(
1544
-                array($model_class_name, 'reset')
1545
-            )) {
1546
-            $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1547
-        } else {
1548
-            throw new EE_Error(
1549
-                sprintf(
1550
-                    esc_html__('Model %s does not have a method "reset"', 'event_espresso'),
1551
-                    $model_name
1552
-                )
1553
-            );
1554
-        }
1555
-        return $this->LIB->{$model_class_name};
1556
-    }
1557
-
1558
-
1559
-    /**
1560
-     * Resets the registry.
1561
-     * The criteria for what gets reset is based on what can be shared between sites on the same request when
1562
-     * switch_to_blog is used in a multisite install.  Here is a list of things that are NOT reset.
1563
-     * - $_dependency_map
1564
-     * - $_class_abbreviations
1565
-     * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1566
-     * - $REQ:  Still on the same request so no need to change.
1567
-     * - $CAP: There is no site specific state in the EE_Capability class.
1568
-     * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only
1569
-     * one Session can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1570
-     * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1571
-     *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1572
-     *             switch or on the restore.
1573
-     * - $modules
1574
-     * - $shortcodes
1575
-     * - $widgets
1576
-     *
1577
-     * @param boolean $hard             [deprecated]
1578
-     * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1579
-     *                                  or just reset without re-instantiating (handy to set to FALSE if you're not
1580
-     *                                  sure if you CAN currently reinstantiate the singletons at the moment)
1581
-     * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so
1582
-     *                                  client
1583
-     *                                  code instead can just change the model context to a different blog id if
1584
-     *                                  necessary
1585
-     * @return EE_Registry
1586
-     * @throws InvalidInterfaceException
1587
-     * @throws InvalidDataTypeException
1588
-     * @throws EE_Error
1589
-     * @throws ReflectionException
1590
-     * @throws InvalidArgumentException
1591
-     */
1592
-    public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1593
-    {
1594
-        $instance            = self::instance();
1595
-        $instance->_cache_on = true;
1596
-        // reset some "special" classes
1597
-        EEH_Activation::reset();
1598
-        $hard                     = apply_filters('FHEE__EE_Registry__reset__hard', $hard);
1599
-        $instance->CFG            = EE_Config::reset($hard, $reinstantiate);
1600
-        $instance->CART           = null;
1601
-        $instance->MRM            = null;
1602
-        $instance->AssetsRegistry = LoaderFactory::getLoader()->getShared(
1603
-            'EventEspresso\core\services\assets\Registry'
1604
-        );
1605
-        //messages reset
1606
-        EED_Messages::reset();
1607
-        //handle of objects cached on LIB
1608
-        foreach (array('LIB', 'modules') as $cache) {
1609
-            foreach ($instance->{$cache} as $class_name => $class) {
1610
-                if (self::_reset_and_unset_object($class, $reset_models)) {
1611
-                    unset($instance->{$cache}->{$class_name});
1612
-                }
1613
-            }
1614
-        }
1615
-        return $instance;
1616
-    }
1617
-
1618
-
1619
-    /**
1620
-     * if passed object implements ResettableInterface, then call it's reset() method
1621
-     * if passed object implements InterminableInterface, then return false,
1622
-     * to indicate that it should NOT be cleared from the Registry cache
1623
-     *
1624
-     * @param      $object
1625
-     * @param bool $reset_models
1626
-     * @return bool returns true if cached object should be unset
1627
-     */
1628
-    private static function _reset_and_unset_object($object, $reset_models)
1629
-    {
1630
-        if (! is_object($object)) {
1631
-            // don't unset anything that's not an object
1632
-            return false;
1633
-        }
1634
-        if ($object instanceof EED_Module) {
1635
-            $object::reset();
1636
-            // don't unset modules
1637
-            return false;
1638
-        }
1639
-        if ($object instanceof ResettableInterface) {
1640
-            if ($object instanceof EEM_Base) {
1641
-                if ($reset_models) {
1642
-                    $object->reset();
1643
-                    return true;
1644
-                }
1645
-                return false;
1646
-            }
1647
-            $object->reset();
1648
-            return true;
1649
-        }
1650
-        if (! $object instanceof InterminableInterface) {
1651
-            return true;
1652
-        }
1653
-        return false;
1654
-    }
1655
-
1656
-
1657
-    /**
1658
-     * Gets all the custom post type models defined
1659
-     *
1660
-     * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1661
-     */
1662
-    public function cpt_models()
1663
-    {
1664
-        $cpt_models = array();
1665
-        foreach ($this->non_abstract_db_models as $short_name => $classname) {
1666
-            if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1667
-                $cpt_models[ $short_name ] = $classname;
1668
-            }
1669
-        }
1670
-        return $cpt_models;
1671
-    }
1672
-
1673
-
1674
-    /**
1675
-     * @return \EE_Config
1676
-     */
1677
-    public static function CFG()
1678
-    {
1679
-        return self::instance()->CFG;
1680
-    }
1681
-
1682
-
1683
-    /**
1684
-     * @deprecated $VID:$
1685
-     * @param string $class_name
1686
-     * @return ReflectionClass
1687
-     * @throws ReflectionException
1688
-     * @throws InvalidDataTypeException
1689
-     */
1690
-    public function get_ReflectionClass($class_name)
1691
-    {
1692
-        return $this->mirror->getReflectionClass($class_name);
1693
-    }
30
+	/**
31
+	 * @var EE_Registry $_instance
32
+	 */
33
+	private static $_instance;
34
+
35
+	/**
36
+	 * @var EE_Dependency_Map $_dependency_map
37
+	 */
38
+	protected $_dependency_map;
39
+
40
+	/**
41
+	 * @var Mirror
42
+	 */
43
+	private $mirror;
44
+
45
+	/**
46
+	 * @var ClassInterfaceCache $class_cache
47
+	 */
48
+	private $class_cache;
49
+
50
+	/**
51
+	 * @var array $_class_abbreviations
52
+	 */
53
+	protected $_class_abbreviations = array();
54
+
55
+	/**
56
+	 * @var CommandBusInterface $BUS
57
+	 */
58
+	public $BUS;
59
+
60
+	/**
61
+	 * @var EE_Cart $CART
62
+	 */
63
+	public $CART;
64
+
65
+	/**
66
+	 * @var EE_Config $CFG
67
+	 */
68
+	public $CFG;
69
+
70
+	/**
71
+	 * @var EE_Network_Config $NET_CFG
72
+	 */
73
+	public $NET_CFG;
74
+
75
+	/**
76
+	 * StdClass object for storing library classes in
77
+	 *
78
+	 * @var RegistryContainer $LIB
79
+	 */
80
+	public $LIB;
81
+
82
+	/**
83
+	 * @var EE_Request_Handler $REQ
84
+	 */
85
+	public $REQ;
86
+
87
+	/**
88
+	 * @var EE_Session $SSN
89
+	 */
90
+	public $SSN;
91
+
92
+	/**
93
+	 * @since 4.5.0
94
+	 * @var EE_Capabilities $CAP
95
+	 */
96
+	public $CAP;
97
+
98
+	/**
99
+	 * @since 4.9.0
100
+	 * @var EE_Message_Resource_Manager $MRM
101
+	 */
102
+	public $MRM;
103
+
104
+	/**
105
+	 * @var Registry $AssetsRegistry
106
+	 */
107
+	public $AssetsRegistry;
108
+
109
+	/**
110
+	 * StdClass object for holding addons which have registered themselves to work with EE core
111
+	 *
112
+	 * @var EE_Addon[] $addons
113
+	 */
114
+	public $addons;
115
+
116
+	/**
117
+	 * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
118
+	 *
119
+	 * @var EEM_Base[] $models
120
+	 */
121
+	public $models = array();
122
+
123
+	/**
124
+	 * @var EED_Module[] $modules
125
+	 */
126
+	public $modules;
127
+
128
+	/**
129
+	 * @var EES_Shortcode[] $shortcodes
130
+	 */
131
+	public $shortcodes;
132
+
133
+	/**
134
+	 * @var WP_Widget[] $widgets
135
+	 */
136
+	public $widgets;
137
+
138
+	/**
139
+	 * this is an array of all implemented model names (i.e. not the parent abstract models, or models
140
+	 * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
141
+	 * Keys are model "short names" (eg "Event") as used in model relations, and values are
142
+	 * classnames (eg "EEM_Event")
143
+	 *
144
+	 * @var array $non_abstract_db_models
145
+	 */
146
+	public $non_abstract_db_models = array();
147
+
148
+	/**
149
+	 * internationalization for JS strings
150
+	 *    usage:   EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' );
151
+	 *    in js file:  var translatedString = eei18n.string_key;
152
+	 *
153
+	 * @var array $i18n_js_strings
154
+	 */
155
+	public static $i18n_js_strings = array();
156
+
157
+	/**
158
+	 * $main_file - path to espresso.php
159
+	 *
160
+	 * @var array $main_file
161
+	 */
162
+	public $main_file;
163
+
164
+	/**
165
+	 * array of ReflectionClass objects where the key is the class name
166
+	 *
167
+	 * @deprecated $VID:$
168
+	 * @var ReflectionClass[] $_reflectors
169
+	 */
170
+	public $_reflectors;
171
+
172
+	/**
173
+	 * boolean flag to indicate whether or not to load/save dependencies from/to the cache
174
+	 *
175
+	 * @var boolean $_cache_on
176
+	 */
177
+	protected $_cache_on = true;
178
+
179
+	/**
180
+	 * @var ObjectIdentifier
181
+	 */
182
+	private $object_identifier;
183
+
184
+
185
+	/**
186
+	 * @singleton method used to instantiate class object
187
+	 * @param EE_Dependency_Map|null   $dependency_map
188
+	 * @param Mirror|null              $mirror
189
+	 * @param ClassInterfaceCache|null $class_cache
190
+	 * @param ObjectIdentifier|null    $object_identifier
191
+	 * @return EE_Registry instance
192
+	 */
193
+	public static function instance(
194
+		EE_Dependency_Map $dependency_map = null,
195
+		Mirror $mirror = null,
196
+		ClassInterfaceCache $class_cache = null,
197
+		ObjectIdentifier $object_identifier = null
198
+	) {
199
+		// check if class object is instantiated
200
+		if (
201
+			! self::$_instance instanceof EE_Registry
202
+			&& $dependency_map instanceof EE_Dependency_Map
203
+			&& $mirror instanceof Mirror
204
+			&& $class_cache instanceof ClassInterfaceCache
205
+			&& $object_identifier instanceof ObjectIdentifier
206
+		) {
207
+			self::$_instance = new self(
208
+				$dependency_map,
209
+				$mirror,
210
+				$class_cache,
211
+				$object_identifier
212
+			);
213
+		}
214
+		return self::$_instance;
215
+	}
216
+
217
+
218
+	/**
219
+	 * protected constructor to prevent direct creation
220
+	 *
221
+	 * @Constructor
222
+	 * @param  EE_Dependency_Map  $dependency_map
223
+	 * @param Mirror              $mirror
224
+	 * @param ClassInterfaceCache $class_cache
225
+	 * @param ObjectIdentifier    $object_identifier
226
+	 */
227
+	protected function __construct(
228
+		EE_Dependency_Map $dependency_map,
229
+		Mirror $mirror,
230
+		ClassInterfaceCache $class_cache,
231
+		ObjectIdentifier $object_identifier
232
+	) {
233
+		$this->_dependency_map   = $dependency_map;
234
+		$this->mirror            = $mirror;
235
+		$this->class_cache       = $class_cache;
236
+		$this->object_identifier = $object_identifier;
237
+		// $registry_container = new RegistryContainer();
238
+		$this->LIB        = new RegistryContainer();
239
+		$this->addons     = new RegistryContainer();
240
+		$this->modules    = new RegistryContainer();
241
+		$this->shortcodes = new RegistryContainer();
242
+		$this->widgets    = new RegistryContainer();
243
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
244
+	}
245
+
246
+
247
+	/**
248
+	 * initialize
249
+	 *
250
+	 * @throws OutOfBoundsException
251
+	 * @throws InvalidArgumentException
252
+	 * @throws InvalidInterfaceException
253
+	 * @throws InvalidDataTypeException
254
+	 * @throws EE_Error
255
+	 * @throws ReflectionException
256
+	 */
257
+	public function initialize()
258
+	{
259
+		$this->_class_abbreviations = apply_filters(
260
+			'FHEE__EE_Registry____construct___class_abbreviations',
261
+			array(
262
+				'EE_Config'                                       => 'CFG',
263
+				'EE_Session'                                      => 'SSN',
264
+				'EE_Capabilities'                                 => 'CAP',
265
+				'EE_Cart'                                         => 'CART',
266
+				'EE_Network_Config'                               => 'NET_CFG',
267
+				'EE_Request_Handler'                              => 'REQ',
268
+				'EE_Message_Resource_Manager'                     => 'MRM',
269
+				'EventEspresso\core\services\commands\CommandBus' => 'BUS',
270
+				'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
271
+			)
272
+		);
273
+		$this->load_core('Base', array(), true);
274
+		// add our request and response objects to the cache
275
+		$request_loader = $this->_dependency_map->class_loader(
276
+			'EventEspresso\core\services\request\Request'
277
+		);
278
+		$this->_set_cached_class(
279
+			$request_loader(),
280
+			'EventEspresso\core\services\request\Request'
281
+		);
282
+		$response_loader = $this->_dependency_map->class_loader(
283
+			'EventEspresso\core\services\request\Response'
284
+		);
285
+		$this->_set_cached_class(
286
+			$response_loader(),
287
+			'EventEspresso\core\services\request\Response'
288
+		);
289
+		add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
290
+	}
291
+
292
+
293
+	/**
294
+	 * @return void
295
+	 */
296
+	public function init()
297
+	{
298
+		// Get current page protocol
299
+		$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
300
+		// Output admin-ajax.php URL with same protocol as current page
301
+		self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
302
+		self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
303
+	}
304
+
305
+
306
+	/**
307
+	 * localize_i18n_js_strings
308
+	 *
309
+	 * @return string
310
+	 */
311
+	public static function localize_i18n_js_strings()
312
+	{
313
+		$i18n_js_strings = (array) self::$i18n_js_strings;
314
+		foreach ($i18n_js_strings as $key => $value) {
315
+			if (is_scalar($value)) {
316
+				$i18n_js_strings[ $key ] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
317
+			}
318
+		}
319
+		return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
320
+	}
321
+
322
+
323
+	/**
324
+	 * @param mixed string | EED_Module $module
325
+	 * @throws OutOfBoundsException
326
+	 * @throws InvalidArgumentException
327
+	 * @throws InvalidInterfaceException
328
+	 * @throws InvalidDataTypeException
329
+	 * @throws EE_Error
330
+	 * @throws ReflectionException
331
+	 */
332
+	public function add_module($module)
333
+	{
334
+		if ($module instanceof EED_Module) {
335
+			$module_class                   = get_class($module);
336
+			$this->modules->{$module_class} = $module;
337
+		} else {
338
+			if (! class_exists('EE_Module_Request_Router', false)) {
339
+				$this->load_core('Module_Request_Router');
340
+			}
341
+			EE_Module_Request_Router::module_factory($module);
342
+		}
343
+	}
344
+
345
+
346
+	/**
347
+	 * @param string $module_name
348
+	 * @return mixed EED_Module | NULL
349
+	 */
350
+	public function get_module($module_name = '')
351
+	{
352
+		return isset($this->modules->{$module_name})
353
+			? $this->modules->{$module_name}
354
+			: null;
355
+	}
356
+
357
+
358
+	/**
359
+	 * loads core classes - must be singletons
360
+	 *
361
+	 * @param string $class_name - simple class name ie: session
362
+	 * @param mixed  $arguments
363
+	 * @param bool   $load_only
364
+	 * @return mixed
365
+	 * @throws InvalidInterfaceException
366
+	 * @throws InvalidDataTypeException
367
+	 * @throws EE_Error
368
+	 * @throws ReflectionException
369
+	 * @throws InvalidArgumentException
370
+	 */
371
+	public function load_core($class_name, $arguments = array(), $load_only = false)
372
+	{
373
+		$core_paths = apply_filters(
374
+			'FHEE__EE_Registry__load_core__core_paths',
375
+			array(
376
+				EE_CORE,
377
+				EE_ADMIN,
378
+				EE_CPTS,
379
+				EE_CORE . 'data_migration_scripts' . DS,
380
+				EE_CORE . 'capabilities' . DS,
381
+				EE_CORE . 'request_stack' . DS,
382
+				EE_CORE . 'middleware' . DS,
383
+			)
384
+		);
385
+		// retrieve instantiated class
386
+		return $this->_load(
387
+			$core_paths,
388
+			'EE_',
389
+			$class_name,
390
+			'core',
391
+			$arguments,
392
+			false,
393
+			true,
394
+			$load_only
395
+		);
396
+	}
397
+
398
+
399
+	/**
400
+	 * loads service classes
401
+	 *
402
+	 * @param string $class_name - simple class name ie: session
403
+	 * @param mixed  $arguments
404
+	 * @param bool   $load_only
405
+	 * @return mixed
406
+	 * @throws InvalidInterfaceException
407
+	 * @throws InvalidDataTypeException
408
+	 * @throws EE_Error
409
+	 * @throws ReflectionException
410
+	 * @throws InvalidArgumentException
411
+	 */
412
+	public function load_service($class_name, $arguments = array(), $load_only = false)
413
+	{
414
+		$service_paths = apply_filters(
415
+			'FHEE__EE_Registry__load_service__service_paths',
416
+			array(
417
+				EE_CORE . 'services' . DS,
418
+			)
419
+		);
420
+		// retrieve instantiated class
421
+		return $this->_load(
422
+			$service_paths,
423
+			'EE_',
424
+			$class_name,
425
+			'class',
426
+			$arguments,
427
+			false,
428
+			true,
429
+			$load_only
430
+		);
431
+	}
432
+
433
+
434
+	/**
435
+	 * loads data_migration_scripts
436
+	 *
437
+	 * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
438
+	 * @param mixed  $arguments
439
+	 * @return EE_Data_Migration_Script_Base|mixed
440
+	 * @throws InvalidInterfaceException
441
+	 * @throws InvalidDataTypeException
442
+	 * @throws EE_Error
443
+	 * @throws ReflectionException
444
+	 * @throws InvalidArgumentException
445
+	 */
446
+	public function load_dms($class_name, $arguments = array())
447
+	{
448
+		// retrieve instantiated class
449
+		return $this->_load(
450
+			EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(),
451
+			'EE_DMS_',
452
+			$class_name,
453
+			'dms',
454
+			$arguments,
455
+			false,
456
+			false
457
+		);
458
+	}
459
+
460
+
461
+	/**
462
+	 * loads object creating classes - must be singletons
463
+	 *
464
+	 * @param string $class_name - simple class name ie: attendee
465
+	 * @param mixed  $arguments  - an array of arguments to pass to the class
466
+	 * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to
467
+	 *                           instantiate
468
+	 * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then
469
+	 *                           set this to FALSE (ie. when instantiating model objects from client in a loop)
470
+	 * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate
471
+	 *                           (default)
472
+	 * @return EE_Base_Class | bool
473
+	 * @throws InvalidInterfaceException
474
+	 * @throws InvalidDataTypeException
475
+	 * @throws EE_Error
476
+	 * @throws ReflectionException
477
+	 * @throws InvalidArgumentException
478
+	 */
479
+	public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
480
+	{
481
+		$paths = apply_filters(
482
+			'FHEE__EE_Registry__load_class__paths', array(
483
+				EE_CORE,
484
+				EE_CLASSES,
485
+				EE_BUSINESS,
486
+			)
487
+		);
488
+		// retrieve instantiated class
489
+		return $this->_load(
490
+			$paths,
491
+			'EE_',
492
+			$class_name,
493
+			'class',
494
+			$arguments,
495
+			$from_db,
496
+			$cache,
497
+			$load_only
498
+		);
499
+	}
500
+
501
+
502
+	/**
503
+	 * loads helper classes - must be singletons
504
+	 *
505
+	 * @param string $class_name - simple class name ie: price
506
+	 * @param mixed  $arguments
507
+	 * @param bool   $load_only
508
+	 * @return EEH_Base | bool
509
+	 * @throws InvalidInterfaceException
510
+	 * @throws InvalidDataTypeException
511
+	 * @throws EE_Error
512
+	 * @throws ReflectionException
513
+	 * @throws InvalidArgumentException
514
+	 */
515
+	public function load_helper($class_name, $arguments = array(), $load_only = true)
516
+	{
517
+		// todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
518
+		$helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
519
+		// retrieve instantiated class
520
+		return $this->_load(
521
+			$helper_paths,
522
+			'EEH_',
523
+			$class_name,
524
+			'helper',
525
+			$arguments,
526
+			false,
527
+			true,
528
+			$load_only
529
+		);
530
+	}
531
+
532
+
533
+	/**
534
+	 * loads core classes - must be singletons
535
+	 *
536
+	 * @param string $class_name - simple class name ie: session
537
+	 * @param mixed  $arguments
538
+	 * @param bool   $load_only
539
+	 * @param bool   $cache      whether to cache the object or not.
540
+	 * @return mixed
541
+	 * @throws InvalidInterfaceException
542
+	 * @throws InvalidDataTypeException
543
+	 * @throws EE_Error
544
+	 * @throws ReflectionException
545
+	 * @throws InvalidArgumentException
546
+	 */
547
+	public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
548
+	{
549
+		$paths = array(
550
+			EE_LIBRARIES,
551
+			EE_LIBRARIES . 'messages' . DS,
552
+			EE_LIBRARIES . 'shortcodes' . DS,
553
+			EE_LIBRARIES . 'qtips' . DS,
554
+			EE_LIBRARIES . 'payment_methods' . DS,
555
+		);
556
+		// retrieve instantiated class
557
+		return $this->_load(
558
+			$paths,
559
+			'EE_',
560
+			$class_name,
561
+			'lib',
562
+			$arguments,
563
+			false,
564
+			$cache,
565
+			$load_only
566
+		);
567
+	}
568
+
569
+
570
+	/**
571
+	 * loads model classes - must be singletons
572
+	 *
573
+	 * @param string $class_name - simple class name ie: price
574
+	 * @param mixed  $arguments
575
+	 * @param bool   $load_only
576
+	 * @return EEM_Base | bool
577
+	 * @throws InvalidInterfaceException
578
+	 * @throws InvalidDataTypeException
579
+	 * @throws EE_Error
580
+	 * @throws ReflectionException
581
+	 * @throws InvalidArgumentException
582
+	 */
583
+	public function load_model($class_name, $arguments = array(), $load_only = false)
584
+	{
585
+		$paths = apply_filters(
586
+			'FHEE__EE_Registry__load_model__paths', array(
587
+				EE_MODELS,
588
+				EE_CORE,
589
+			)
590
+		);
591
+		// retrieve instantiated class
592
+		return $this->_load(
593
+			$paths,
594
+			'EEM_',
595
+			$class_name,
596
+			'model',
597
+			$arguments,
598
+			false,
599
+			true,
600
+			$load_only
601
+		);
602
+	}
603
+
604
+
605
+	/**
606
+	 * loads model classes - must be singletons
607
+	 *
608
+	 * @param string $class_name - simple class name ie: price
609
+	 * @param mixed  $arguments
610
+	 * @param bool   $load_only
611
+	 * @return mixed | bool
612
+	 * @throws InvalidInterfaceException
613
+	 * @throws InvalidDataTypeException
614
+	 * @throws EE_Error
615
+	 * @throws ReflectionException
616
+	 * @throws InvalidArgumentException
617
+	 */
618
+	public function load_model_class($class_name, $arguments = array(), $load_only = true)
619
+	{
620
+		$paths = array(
621
+			EE_MODELS . 'fields' . DS,
622
+			EE_MODELS . 'helpers' . DS,
623
+			EE_MODELS . 'relations' . DS,
624
+			EE_MODELS . 'strategies' . DS,
625
+		);
626
+		// retrieve instantiated class
627
+		return $this->_load(
628
+			$paths,
629
+			'EE_',
630
+			$class_name,
631
+			'',
632
+			$arguments,
633
+			false,
634
+			true,
635
+			$load_only
636
+		);
637
+	}
638
+
639
+
640
+	/**
641
+	 * Determines if $model_name is the name of an actual EE model.
642
+	 *
643
+	 * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
644
+	 * @return boolean
645
+	 */
646
+	public function is_model_name($model_name)
647
+	{
648
+		return isset($this->models[ $model_name ]);
649
+	}
650
+
651
+
652
+	/**
653
+	 * generic class loader
654
+	 *
655
+	 * @param string $path_to_file - directory path to file location, not including filename
656
+	 * @param string $file_name    - file name  ie:  my_file.php, including extension
657
+	 * @param string $type         - file type - core? class? helper? model?
658
+	 * @param mixed  $arguments
659
+	 * @param bool   $load_only
660
+	 * @return mixed
661
+	 * @throws InvalidInterfaceException
662
+	 * @throws InvalidDataTypeException
663
+	 * @throws EE_Error
664
+	 * @throws ReflectionException
665
+	 * @throws InvalidArgumentException
666
+	 */
667
+	public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
668
+	{
669
+		// retrieve instantiated class
670
+		return $this->_load(
671
+			$path_to_file,
672
+			'',
673
+			$file_name,
674
+			$type,
675
+			$arguments,
676
+			false,
677
+			true,
678
+			$load_only
679
+		);
680
+	}
681
+
682
+
683
+	/**
684
+	 * @param string $path_to_file - directory path to file location, not including filename
685
+	 * @param string $class_name   - full class name  ie:  My_Class
686
+	 * @param string $type         - file type - core? class? helper? model?
687
+	 * @param mixed  $arguments
688
+	 * @param bool   $load_only
689
+	 * @return bool|EE_Addon|object
690
+	 * @throws InvalidInterfaceException
691
+	 * @throws InvalidDataTypeException
692
+	 * @throws EE_Error
693
+	 * @throws ReflectionException
694
+	 * @throws InvalidArgumentException
695
+	 */
696
+	public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
697
+	{
698
+		// retrieve instantiated class
699
+		return $this->_load(
700
+			$path_to_file,
701
+			'addon',
702
+			$class_name,
703
+			$type,
704
+			$arguments,
705
+			false,
706
+			true,
707
+			$load_only
708
+		);
709
+	}
710
+
711
+
712
+	/**
713
+	 * instantiates, caches, and automatically resolves dependencies
714
+	 * for classes that use a Fully Qualified Class Name.
715
+	 * if the class is not capable of being loaded using PSR-4 autoloading,
716
+	 * then you need to use one of the existing load_*() methods
717
+	 * which can resolve the classname and filepath from the passed arguments
718
+	 *
719
+	 * @param bool|string $class_name   Fully Qualified Class Name
720
+	 * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
721
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
722
+	 * @param bool        $from_db      some classes are instantiated from the db
723
+	 *                                  and thus call a different method to instantiate
724
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
725
+	 * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
726
+	 * @return bool|null|mixed          null = failure to load or instantiate class object.
727
+	 *                                  object = class loaded and instantiated successfully.
728
+	 *                                  bool = fail or success when $load_only is true
729
+	 * @throws InvalidInterfaceException
730
+	 * @throws InvalidDataTypeException
731
+	 * @throws EE_Error
732
+	 * @throws ReflectionException
733
+	 * @throws InvalidArgumentException
734
+	 */
735
+	public function create(
736
+		$class_name = false,
737
+		$arguments = array(),
738
+		$cache = false,
739
+		$from_db = false,
740
+		$load_only = false,
741
+		$addon = false
742
+	) {
743
+		$class_name   = ltrim($class_name, '\\');
744
+		$class_name   = $this->class_cache->getFqnForAlias($class_name);
745
+		$class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
746
+		// if a non-FQCN was passed, then
747
+		// verifyClassExists() might return an object
748
+		// or it could return null if the class just could not be found anywhere
749
+		if ($class_exists instanceof $class_name || $class_exists === null) {
750
+			// either way, return the results
751
+			return $class_exists;
752
+		}
753
+		$class_name = $class_exists;
754
+		// if we're only loading the class and it already exists, then let's just return true immediately
755
+		if ($load_only) {
756
+			return true;
757
+		}
758
+		$addon = $addon ? 'addon' : '';
759
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
760
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
761
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
762
+		if ($this->_cache_on && $cache && ! $load_only) {
763
+			// return object if it's already cached
764
+			$cached_class = $this->_get_cached_class($class_name, $addon, $arguments);
765
+			if ($cached_class !== null) {
766
+				return $cached_class;
767
+			}
768
+		}// obtain the loader method from the dependency map
769
+		$loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object
770
+		if ($loader instanceof Closure) {
771
+			$class_obj = $loader($arguments);
772
+		} else {
773
+			if ($loader && method_exists($this, $loader)) {
774
+				$class_obj = $this->{$loader}($class_name, $arguments);
775
+			} else {
776
+				$class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
777
+			}
778
+		}
779
+		if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) {
780
+			// save it for later... kinda like gum  { : $
781
+			$this->_set_cached_class(
782
+				$class_obj,
783
+				$class_name,
784
+				$addon,
785
+				$from_db,
786
+				$arguments
787
+			);
788
+		}
789
+		$this->_cache_on = true;
790
+		return $class_obj;
791
+	}
792
+
793
+
794
+	/**
795
+	 * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
796
+	 *
797
+	 * @param string|object $class_name
798
+	 * @param array         $arguments
799
+	 * @param int           $attempt
800
+	 * @return mixed
801
+	 */
802
+	private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1)
803
+	{
804
+		if (is_object($class_name) || class_exists($class_name)) {
805
+			return $class_name;
806
+		}
807
+		switch ($attempt) {
808
+			case 1:
809
+				// if it's a FQCN then maybe the class is registered with a preceding \
810
+				$class_name = strpos($class_name, '\\') !== false
811
+					? '\\' . ltrim($class_name, '\\')
812
+					: $class_name;
813
+				break;
814
+			case 2:
815
+				//
816
+				$loader = $this->_dependency_map->class_loader($class_name);
817
+				if ($loader && method_exists($this, $loader)) {
818
+					return $this->{$loader}($class_name, $arguments);
819
+				}
820
+				break;
821
+			case 3:
822
+			default;
823
+				return null;
824
+		}
825
+		$attempt++;
826
+		return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt);
827
+	}
828
+
829
+
830
+	/**
831
+	 * instantiates, caches, and injects dependencies for classes
832
+	 *
833
+	 * @param array       $file_paths   an array of paths to folders to look in
834
+	 * @param string      $class_prefix EE  or EEM or... ???
835
+	 * @param bool|string $class_name   $class name
836
+	 * @param string      $type         file type - core? class? helper? model?
837
+	 * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
838
+	 * @param bool        $from_db      some classes are instantiated from the db
839
+	 *                                  and thus call a different method to instantiate
840
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
841
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
842
+	 * @return bool|null|object null = failure to load or instantiate class object.
843
+	 *                                  object = class loaded and instantiated successfully.
844
+	 *                                  bool = fail or success when $load_only is true
845
+	 * @throws EE_Error
846
+	 * @throws ReflectionException
847
+	 * @throws InvalidInterfaceException
848
+	 * @throws InvalidDataTypeException
849
+	 * @throws InvalidArgumentException
850
+	 */
851
+	protected function _load(
852
+		$file_paths = array(),
853
+		$class_prefix = 'EE_',
854
+		$class_name = false,
855
+		$type = 'class',
856
+		$arguments = array(),
857
+		$from_db = false,
858
+		$cache = true,
859
+		$load_only = false
860
+	) {
861
+		$class_name = ltrim($class_name, '\\');
862
+		// strip php file extension
863
+		$class_name = str_replace('.php', '', trim($class_name));
864
+		// does the class have a prefix ?
865
+		if (! empty($class_prefix) && $class_prefix !== 'addon') {
866
+			// make sure $class_prefix is uppercase
867
+			$class_prefix = strtoupper(trim($class_prefix));
868
+			// add class prefix ONCE!!!
869
+			$class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
870
+		}
871
+		$class_name   = $this->class_cache->getFqnForAlias($class_name);
872
+		$class_exists = class_exists($class_name, false);
873
+		// if we're only loading the class and it already exists, then let's just return true immediately
874
+		if ($load_only && $class_exists) {
875
+			return true;
876
+		}
877
+		$arguments = is_array($arguments) ? $arguments : array($arguments);
878
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
879
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
880
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
881
+		if ($this->_cache_on && $cache && ! $load_only) {
882
+			// return object if it's already cached
883
+			$cached_class = $this->_get_cached_class($class_name, $class_prefix, $arguments);
884
+			if ($cached_class !== null) {
885
+				return $cached_class;
886
+			}
887
+		}
888
+		// if the class doesn't already exist.. then we need to try and find the file and load it
889
+		if (! $class_exists) {
890
+			// get full path to file
891
+			$path = $this->_resolve_path($class_name, $type, $file_paths);
892
+			// load the file
893
+			$loaded = $this->_require_file($path, $class_name, $type, $file_paths);
894
+			// if we are only loading a file but NOT instantiating an object
895
+			// then return boolean for whether class was loaded or not
896
+			if ($load_only) {
897
+				return $loaded;
898
+			}
899
+			// if an object was expected but loading failed, then return nothing
900
+			if (! $loaded) {
901
+				return null;
902
+			}
903
+		}
904
+		// instantiate the requested object
905
+		$class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
906
+		if ($this->_cache_on && $cache) {
907
+			// save it for later... kinda like gum  { : $
908
+			$this->_set_cached_class(
909
+				$class_obj,
910
+				$class_name,
911
+				$class_prefix,
912
+				$from_db,
913
+				$arguments
914
+			);
915
+		}
916
+		$this->_cache_on = true;
917
+		return $class_obj;
918
+	}
919
+
920
+
921
+	/**
922
+	 * @param string $class_name
923
+	 * @param string $default have to specify something, but not anything that will conflict
924
+	 * @return mixed|string
925
+	 */
926
+	protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS')
927
+	{
928
+		return isset($this->_class_abbreviations[ $class_name ])
929
+			? $this->_class_abbreviations[ $class_name ]
930
+			: $default;
931
+	}
932
+
933
+
934
+	/**
935
+	 * attempts to find a cached version of the requested class
936
+	 * by looking in the following places:
937
+	 *        $this->{$class_abbreviation}            ie:    $this->CART
938
+	 *        $this->{$class_name}                        ie:    $this->Some_Class
939
+	 *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
940
+	 *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
941
+	 *
942
+	 * @param string $class_name
943
+	 * @param string $class_prefix
944
+	 * @param array  $arguments
945
+	 * @return mixed
946
+	 */
947
+	protected function _get_cached_class(
948
+		$class_name,
949
+		$class_prefix = '',
950
+		$arguments = array()
951
+	) {
952
+		if ($class_name === 'EE_Registry') {
953
+			return $this;
954
+		}
955
+		$class_abbreviation = $this->get_class_abbreviation($class_name);
956
+		// check if class has already been loaded, and return it if it has been
957
+		if (isset($this->{$class_abbreviation})) {
958
+			return $this->{$class_abbreviation};
959
+		}
960
+		$class_name = str_replace('\\', '_', $class_name);
961
+		if (isset ($this->{$class_name})) {
962
+			return $this->{$class_name};
963
+		}
964
+		if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
965
+			return $this->addons->{$class_name};
966
+		}
967
+		$object_identifier = $this->object_identifier->getIdentifier($class_name, $arguments);
968
+		if (isset($this->LIB->{$object_identifier})) {
969
+			return $this->LIB->{$object_identifier};
970
+		}
971
+		foreach ($this->LIB as $key => $object) {
972
+			if (
973
+				// request does not contain new arguments and therefore no args identifier
974
+				! $this->object_identifier->hasArguments($object_identifier)
975
+				// but previously cached class with args was found
976
+				&& $this->object_identifier->fqcnMatchesObjectIdentifier($class_name, $key)
977
+			) {
978
+				return $object;
979
+			}
980
+		}
981
+		return null;
982
+	}
983
+
984
+
985
+	/**
986
+	 * removes a cached version of the requested class
987
+	 *
988
+	 * @param string  $class_name
989
+	 * @param boolean $addon
990
+	 * @param array   $arguments
991
+	 * @return boolean
992
+	 */
993
+	public function clear_cached_class(
994
+		$class_name,
995
+		$addon = false,
996
+		$arguments = array()
997
+	) {
998
+		$class_abbreviation = $this->get_class_abbreviation($class_name);
999
+		// check if class has already been loaded, and return it if it has been
1000
+		if (isset($this->{$class_abbreviation})) {
1001
+			$this->{$class_abbreviation} = null;
1002
+			return true;
1003
+		}
1004
+		$class_name = str_replace('\\', '_', $class_name);
1005
+		if (isset($this->{$class_name})) {
1006
+			$this->{$class_name} = null;
1007
+			return true;
1008
+		}
1009
+		if ($addon && isset($this->addons->{$class_name})) {
1010
+			unset($this->addons->{$class_name});
1011
+			return true;
1012
+		}
1013
+		$class_name = $this->object_identifier->getIdentifier($class_name, $arguments);
1014
+		if (isset($this->LIB->{$class_name})) {
1015
+			unset($this->LIB->{$class_name});
1016
+			return true;
1017
+		}
1018
+		return false;
1019
+	}
1020
+
1021
+
1022
+	/**
1023
+	 * _set_cached_class
1024
+	 * attempts to cache the instantiated class locally
1025
+	 * in one of the following places, in the following order:
1026
+	 *        $this->{class_abbreviation}   ie:    $this->CART
1027
+	 *        $this->{$class_name}          ie:    $this->Some_Class
1028
+	 *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1029
+	 *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1030
+	 *
1031
+	 * @param object $class_obj
1032
+	 * @param string $class_name
1033
+	 * @param string $class_prefix
1034
+	 * @param bool   $from_db
1035
+	 * @param array  $arguments
1036
+	 * @return void
1037
+	 */
1038
+	protected function _set_cached_class(
1039
+		$class_obj,
1040
+		$class_name,
1041
+		$class_prefix = '',
1042
+		$from_db = false,
1043
+		$arguments = array()
1044
+	) {
1045
+		if ($class_name === 'EE_Registry' || empty($class_obj)) {
1046
+			return;
1047
+		}
1048
+		// return newly instantiated class
1049
+		$class_abbreviation = $this->get_class_abbreviation($class_name, '');
1050
+		if ($class_abbreviation) {
1051
+			$this->{$class_abbreviation} = $class_obj;
1052
+			return;
1053
+		}
1054
+		$class_name = str_replace('\\', '_', $class_name);
1055
+		if (property_exists($this, $class_name)) {
1056
+			$this->{$class_name} = $class_obj;
1057
+			return;
1058
+		}
1059
+		if ($class_prefix === 'addon') {
1060
+			$this->addons->{$class_name} = $class_obj;
1061
+			return;
1062
+		}
1063
+		if (! $from_db) {
1064
+			$class_name               = $this->object_identifier->getIdentifier($class_name, $arguments);
1065
+			$this->LIB->{$class_name} = $class_obj;
1066
+		}
1067
+	}
1068
+
1069
+
1070
+	/**
1071
+	 * attempts to find a full valid filepath for the requested class.
1072
+	 * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
1073
+	 * then returns that path if the target file has been found and is readable
1074
+	 *
1075
+	 * @param string $class_name
1076
+	 * @param string $type
1077
+	 * @param array  $file_paths
1078
+	 * @return string | bool
1079
+	 */
1080
+	protected function _resolve_path($class_name, $type = '', $file_paths = array())
1081
+	{
1082
+		// make sure $file_paths is an array
1083
+		$file_paths = is_array($file_paths)
1084
+			? $file_paths
1085
+			: array($file_paths);
1086
+		// cycle thru paths
1087
+		foreach ($file_paths as $key => $file_path) {
1088
+			// convert all separators to proper DS, if no filepath, then use EE_CLASSES
1089
+			$file_path = $file_path
1090
+				? str_replace(array('/', '\\'), DS, $file_path)
1091
+				: EE_CLASSES;
1092
+			// prep file type
1093
+			$type = ! empty($type)
1094
+				? trim($type, '.') . '.'
1095
+				: '';
1096
+			// build full file path
1097
+			$file_paths[ $key ] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
1098
+			//does the file exist and can be read ?
1099
+			if (is_readable($file_paths[ $key ])) {
1100
+				return $file_paths[ $key ];
1101
+			}
1102
+		}
1103
+		return false;
1104
+	}
1105
+
1106
+
1107
+	/**
1108
+	 * basically just performs a require_once()
1109
+	 * but with some error handling
1110
+	 *
1111
+	 * @param  string $path
1112
+	 * @param  string $class_name
1113
+	 * @param  string $type
1114
+	 * @param  array  $file_paths
1115
+	 * @return bool
1116
+	 * @throws EE_Error
1117
+	 * @throws ReflectionException
1118
+	 */
1119
+	protected function _require_file($path, $class_name, $type = '', $file_paths = array())
1120
+	{
1121
+		$this->resolve_legacy_class_parent($class_name);
1122
+		// don't give up! you gotta...
1123
+		try {
1124
+			//does the file exist and can it be read ?
1125
+			if (! $path) {
1126
+				// just in case the file has already been autoloaded,
1127
+				// but discrepancies in the naming schema are preventing it from
1128
+				// being loaded via one of the EE_Registry::load_*() methods,
1129
+				// then let's try one last hail mary before throwing an exception
1130
+				// and call class_exists() again, but with autoloading turned ON
1131
+				if (class_exists($class_name)) {
1132
+					return true;
1133
+				}
1134
+				// so sorry, can't find the file
1135
+				throw new EE_Error (
1136
+					sprintf(
1137
+						esc_html__(
1138
+							'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',
1139
+							'event_espresso'
1140
+						),
1141
+						trim($type, '.'),
1142
+						$class_name,
1143
+						'<br />' . implode(',<br />', $file_paths)
1144
+					)
1145
+				);
1146
+			}
1147
+			// get the file
1148
+			require_once($path);
1149
+			// if the class isn't already declared somewhere
1150
+			if (class_exists($class_name, false) === false) {
1151
+				// so sorry, not a class
1152
+				throw new EE_Error(
1153
+					sprintf(
1154
+						esc_html__(
1155
+							'The %s file %s does not appear to contain the %s Class.',
1156
+							'event_espresso'
1157
+						),
1158
+						$type,
1159
+						$path,
1160
+						$class_name
1161
+					)
1162
+				);
1163
+			}
1164
+		} catch (EE_Error $e) {
1165
+			$e->get_error();
1166
+			return false;
1167
+		}
1168
+		return true;
1169
+	}
1170
+
1171
+
1172
+	/**
1173
+	 * Some of our legacy classes that extended a parent class would simply use a require() statement
1174
+	 * before their class declaration in order to ensure that the parent class was loaded.
1175
+	 * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class,
1176
+	 * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist.
1177
+	 *
1178
+	 * @param string $class_name
1179
+	 */
1180
+	protected function resolve_legacy_class_parent($class_name = '')
1181
+	{
1182
+		try {
1183
+			$legacy_parent_class_map = array(
1184
+				'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php',
1185
+			);
1186
+			if (isset($legacy_parent_class_map[ $class_name ])) {
1187
+				require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ];
1188
+			}
1189
+		} catch (Exception $exception) {
1190
+		}
1191
+	}
1192
+
1193
+
1194
+	/**
1195
+	 * _create_object
1196
+	 * Attempts to instantiate the requested class via any of the
1197
+	 * commonly used instantiation methods employed throughout EE.
1198
+	 * The priority for instantiation is as follows:
1199
+	 *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
1200
+	 *        - model objects via their 'new_instance_from_db' method
1201
+	 *        - model objects via their 'new_instance' method
1202
+	 *        - "singleton" classes" via their 'instance' method
1203
+	 *    - standard instantiable classes via their __constructor
1204
+	 * Prior to instantiation, if the classname exists in the dependency_map,
1205
+	 * then the constructor for the requested class will be examined to determine
1206
+	 * if any dependencies exist, and if they can be injected.
1207
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1208
+	 *
1209
+	 * @param string $class_name
1210
+	 * @param array  $arguments
1211
+	 * @param string $type
1212
+	 * @param bool   $from_db
1213
+	 * @return null|object|bool
1214
+	 * @throws InvalidArgumentException
1215
+	 * @throws InvalidInterfaceException
1216
+	 * @throws EE_Error
1217
+	 * @throws ReflectionException
1218
+	 * @throws InvalidDataTypeException
1219
+	 */
1220
+	protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
1221
+	{
1222
+		// create reflection
1223
+		$reflector = $this->mirror->getReflectionClass($class_name);
1224
+		// make sure arguments are an array
1225
+		$arguments = is_array($arguments)
1226
+			? $arguments
1227
+			: array($arguments);
1228
+		// and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
1229
+		// else wrap it in an additional array so that it doesn't get split into multiple parameters
1230
+		$arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
1231
+			? $arguments
1232
+			: array($arguments);
1233
+		// attempt to inject dependencies ?
1234
+		if ($this->_dependency_map->has($class_name)) {
1235
+			$arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
1236
+		}
1237
+		// instantiate the class if possible
1238
+		if ($reflector->isAbstract()) {
1239
+			// nothing to instantiate, loading file was enough
1240
+			// does not throw an exception so $instantiation_mode is unused
1241
+			// $instantiation_mode = "1) no constructor abstract class";
1242
+			return true;
1243
+		}
1244
+		if (
1245
+			empty($arguments)
1246
+			&& $this->mirror->getConstructorFromReflection($reflector) === null
1247
+			&& $reflector->isInstantiable()
1248
+		) {
1249
+			// no constructor = static methods only... nothing to instantiate, loading file was enough
1250
+			// $instantiation_mode = "2) no constructor but instantiable";
1251
+			return $reflector->newInstance();
1252
+		}
1253
+		if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
1254
+			// $instantiation_mode = "3) new_instance_from_db()";
1255
+			return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
1256
+		}
1257
+		if (method_exists($class_name, 'new_instance')) {
1258
+			// $instantiation_mode = "4) new_instance()";
1259
+			return call_user_func_array(array($class_name, 'new_instance'), $arguments);
1260
+		}
1261
+		if (method_exists($class_name, 'instance')) {
1262
+			// $instantiation_mode = "5) instance()";
1263
+			return call_user_func_array(array($class_name, 'instance'), $arguments);
1264
+		}
1265
+		if ($reflector->isInstantiable()) {
1266
+			// $instantiation_mode = "6) constructor";
1267
+			return $reflector->newInstanceArgs($arguments);
1268
+		}
1269
+		// heh ? something's not right !
1270
+		throw new EE_Error(
1271
+			sprintf(
1272
+				__('The %s file %s could not be instantiated.', 'event_espresso'),
1273
+				$type,
1274
+				$class_name
1275
+			)
1276
+		);
1277
+	}
1278
+
1279
+
1280
+	/**
1281
+	 * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1282
+	 * @param array $array
1283
+	 * @return bool
1284
+	 */
1285
+	protected function _array_is_numerically_and_sequentially_indexed(array $array)
1286
+	{
1287
+		return ! empty($array)
1288
+			? array_keys($array) === range(0, count($array) - 1)
1289
+			: true;
1290
+	}
1291
+
1292
+
1293
+	/**
1294
+	 * _resolve_dependencies
1295
+	 * examines the constructor for the requested class to determine
1296
+	 * if any dependencies exist, and if they can be injected.
1297
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1298
+	 * PLZ NOTE: this is achieved by type hinting the constructor params
1299
+	 * For example:
1300
+	 *        if attempting to load a class "Foo" with the following constructor:
1301
+	 *        __construct( Bar $bar_class, Fighter $grohl_class )
1302
+	 *        then $bar_class and $grohl_class will be added to the $arguments array,
1303
+	 *        but only IF they are NOT already present in the incoming arguments array,
1304
+	 *        and the correct classes can be loaded
1305
+	 *
1306
+	 * @param ReflectionClass $reflector
1307
+	 * @param string          $class_name
1308
+	 * @param array           $arguments
1309
+	 * @return array
1310
+	 * @throws InvalidArgumentException
1311
+	 * @throws InvalidDataTypeException
1312
+	 * @throws InvalidInterfaceException
1313
+	 * @throws ReflectionException
1314
+	 */
1315
+	protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, array $arguments = array())
1316
+	{
1317
+		// let's examine the constructor
1318
+		$constructor = $this->mirror->getConstructorFromReflection($reflector);
1319
+		// whu? huh? nothing?
1320
+		if (! $constructor) {
1321
+			return $arguments;
1322
+		}
1323
+		// get constructor parameters
1324
+		$params = $this->mirror->getParametersFromReflection($reflector);
1325
+		// and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1326
+		$argument_keys = array_keys($arguments);
1327
+		// now loop thru all of the constructors expected parameters
1328
+		foreach ($params as $index => $param) {
1329
+			// is this a dependency for a specific class ?
1330
+			$param_class = $this->mirror->getParameterClassName($param, $class_name, $index);
1331
+			// BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1332
+			$param_class = $this->class_cache->isAlias($param_class, $class_name)
1333
+				? $this->class_cache->getFqnForAlias($param_class, $class_name)
1334
+				: $param_class;
1335
+			if (
1336
+				// param is not even a class
1337
+				$param_class === null
1338
+				// and something already exists in the incoming arguments for this param
1339
+				&& array_key_exists($index, $argument_keys)
1340
+				&& array_key_exists($argument_keys[ $index ], $arguments)
1341
+			) {
1342
+				// so let's skip this argument and move on to the next
1343
+				continue;
1344
+			}
1345
+			if (
1346
+				// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1347
+				$param_class !== null
1348
+				&& isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ])
1349
+				&& $arguments[ $argument_keys[ $index ] ] instanceof $param_class
1350
+			) {
1351
+				// skip this argument and move on to the next
1352
+				continue;
1353
+			}
1354
+			if (
1355
+				// parameter is type hinted as a class, and should be injected
1356
+				$param_class !== null
1357
+				&& $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1358
+			) {
1359
+				$arguments = $this->_resolve_dependency(
1360
+					$class_name,
1361
+					$param_class,
1362
+					$arguments,
1363
+					$index
1364
+				);
1365
+			} else {
1366
+				$arguments[ $index ] = $this->mirror->getParameterDefaultValue(
1367
+					$param,
1368
+					$class_name,
1369
+					$index
1370
+				);
1371
+			}
1372
+		}
1373
+		return $arguments;
1374
+	}
1375
+
1376
+
1377
+	/**
1378
+	 * @param string $class_name
1379
+	 * @param string $param_class
1380
+	 * @param array  $arguments
1381
+	 * @param mixed  $index
1382
+	 * @return array
1383
+	 * @throws InvalidArgumentException
1384
+	 * @throws InvalidInterfaceException
1385
+	 * @throws InvalidDataTypeException
1386
+	 */
1387
+	protected function _resolve_dependency($class_name, $param_class, $arguments, $index)
1388
+	{
1389
+		$dependency = null;
1390
+		// should dependency be loaded from cache ?
1391
+		$cache_on = $this->_dependency_map->loading_strategy_for_class_dependency(
1392
+			$class_name,
1393
+			$param_class
1394
+		);
1395
+		$cache_on = $cache_on !== EE_Dependency_Map::load_new_object;
1396
+		// we might have a dependency...
1397
+		// let's MAYBE try and find it in our cache if that's what's been requested
1398
+		$cached_class = $cache_on
1399
+			? $this->_get_cached_class($param_class)
1400
+			: null;
1401
+		// and grab it if it exists
1402
+		if ($cached_class instanceof $param_class) {
1403
+			$dependency = $cached_class;
1404
+		} elseif ($param_class !== $class_name) {
1405
+			// obtain the loader method from the dependency map
1406
+			$loader = $this->_dependency_map->class_loader($param_class);
1407
+			// is loader a custom closure ?
1408
+			if ($loader instanceof Closure) {
1409
+				$dependency = $loader($arguments);
1410
+			} else {
1411
+				// set the cache on property for the recursive loading call
1412
+				$this->_cache_on = $cache_on;
1413
+				// if not, then let's try and load it via the registry
1414
+				if ($loader && method_exists($this, $loader)) {
1415
+					$dependency = $this->{$loader}($param_class);
1416
+				} else {
1417
+					$dependency = LoaderFactory::getLoader()->load(
1418
+						$param_class,
1419
+						array(),
1420
+						$cache_on
1421
+					);
1422
+				}
1423
+			}
1424
+		}
1425
+		// did we successfully find the correct dependency ?
1426
+		if ($dependency instanceof $param_class) {
1427
+			// then let's inject it into the incoming array of arguments at the correct location
1428
+			$arguments[ $index ] = $dependency;
1429
+		}
1430
+		return $arguments;
1431
+	}
1432
+
1433
+
1434
+	/**
1435
+	 * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1436
+	 *
1437
+	 * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1438
+	 *                          in the EE_Dependency_Map::$_class_loaders array,
1439
+	 *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1440
+	 * @param array  $arguments
1441
+	 * @return object
1442
+	 */
1443
+	public static function factory($classname, $arguments = array())
1444
+	{
1445
+		$loader = self::instance()->_dependency_map->class_loader($classname);
1446
+		if ($loader instanceof Closure) {
1447
+			return $loader($arguments);
1448
+		}
1449
+		if (method_exists(self::instance(), $loader)) {
1450
+			return self::instance()->{$loader}($classname, $arguments);
1451
+		}
1452
+		return null;
1453
+	}
1454
+
1455
+
1456
+	/**
1457
+	 * Gets the addon by its class name
1458
+	 *
1459
+	 * @param string $class_name
1460
+	 * @return EE_Addon
1461
+	 */
1462
+	public function getAddon($class_name)
1463
+	{
1464
+		$class_name = str_replace('\\', '_', $class_name);
1465
+		return $this->addons->{$class_name};
1466
+	}
1467
+
1468
+
1469
+	/**
1470
+	 * removes the addon from the internal cache
1471
+	 *
1472
+	 * @param string $class_name
1473
+	 * @return void
1474
+	 */
1475
+	public function removeAddon($class_name)
1476
+	{
1477
+		$class_name = str_replace('\\', '_', $class_name);
1478
+		unset($this->addons->{$class_name});
1479
+	}
1480
+
1481
+
1482
+	/**
1483
+	 * Gets the addon by its name/slug (not classname. For that, just
1484
+	 * use the get_addon() method above
1485
+	 *
1486
+	 * @param string $name
1487
+	 * @return EE_Addon
1488
+	 */
1489
+	public function get_addon_by_name($name)
1490
+	{
1491
+		foreach ($this->addons as $addon) {
1492
+			if ($addon->name() === $name) {
1493
+				return $addon;
1494
+			}
1495
+		}
1496
+		return null;
1497
+	}
1498
+
1499
+
1500
+	/**
1501
+	 * Gets an array of all the registered addons, where the keys are their names.
1502
+	 * (ie, what each returns for their name() function)
1503
+	 * They're already available on EE_Registry::instance()->addons as properties,
1504
+	 * where each property's name is the addon's classname,
1505
+	 * So if you just want to get the addon by classname,
1506
+	 * OR use the get_addon() method above.
1507
+	 * PLEASE  NOTE:
1508
+	 * addons with Fully Qualified Class Names
1509
+	 * have had the namespace separators converted to underscores,
1510
+	 * so a classname like Fully\Qualified\ClassName
1511
+	 * would have been converted to Fully_Qualified_ClassName
1512
+	 *
1513
+	 * @return EE_Addon[] where the KEYS are the addon's name()
1514
+	 */
1515
+	public function get_addons_by_name()
1516
+	{
1517
+		$addons = array();
1518
+		foreach ($this->addons as $addon) {
1519
+			$addons[ $addon->name() ] = $addon;
1520
+		}
1521
+		return $addons;
1522
+	}
1523
+
1524
+
1525
+	/**
1526
+	 * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1527
+	 * a stale copy of it around
1528
+	 *
1529
+	 * @param string $model_name
1530
+	 * @return \EEM_Base
1531
+	 * @throws \EE_Error
1532
+	 */
1533
+	public function reset_model($model_name)
1534
+	{
1535
+		$model_class_name = strpos($model_name, 'EEM_') !== 0
1536
+			? "EEM_{$model_name}"
1537
+			: $model_name;
1538
+		if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1539
+			return null;
1540
+		}
1541
+		//get that model reset it and make sure we nuke the old reference to it
1542
+		if ($this->LIB->{$model_class_name} instanceof $model_class_name
1543
+			&& is_callable(
1544
+				array($model_class_name, 'reset')
1545
+			)) {
1546
+			$this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1547
+		} else {
1548
+			throw new EE_Error(
1549
+				sprintf(
1550
+					esc_html__('Model %s does not have a method "reset"', 'event_espresso'),
1551
+					$model_name
1552
+				)
1553
+			);
1554
+		}
1555
+		return $this->LIB->{$model_class_name};
1556
+	}
1557
+
1558
+
1559
+	/**
1560
+	 * Resets the registry.
1561
+	 * The criteria for what gets reset is based on what can be shared between sites on the same request when
1562
+	 * switch_to_blog is used in a multisite install.  Here is a list of things that are NOT reset.
1563
+	 * - $_dependency_map
1564
+	 * - $_class_abbreviations
1565
+	 * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1566
+	 * - $REQ:  Still on the same request so no need to change.
1567
+	 * - $CAP: There is no site specific state in the EE_Capability class.
1568
+	 * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only
1569
+	 * one Session can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1570
+	 * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1571
+	 *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1572
+	 *             switch or on the restore.
1573
+	 * - $modules
1574
+	 * - $shortcodes
1575
+	 * - $widgets
1576
+	 *
1577
+	 * @param boolean $hard             [deprecated]
1578
+	 * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1579
+	 *                                  or just reset without re-instantiating (handy to set to FALSE if you're not
1580
+	 *                                  sure if you CAN currently reinstantiate the singletons at the moment)
1581
+	 * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so
1582
+	 *                                  client
1583
+	 *                                  code instead can just change the model context to a different blog id if
1584
+	 *                                  necessary
1585
+	 * @return EE_Registry
1586
+	 * @throws InvalidInterfaceException
1587
+	 * @throws InvalidDataTypeException
1588
+	 * @throws EE_Error
1589
+	 * @throws ReflectionException
1590
+	 * @throws InvalidArgumentException
1591
+	 */
1592
+	public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1593
+	{
1594
+		$instance            = self::instance();
1595
+		$instance->_cache_on = true;
1596
+		// reset some "special" classes
1597
+		EEH_Activation::reset();
1598
+		$hard                     = apply_filters('FHEE__EE_Registry__reset__hard', $hard);
1599
+		$instance->CFG            = EE_Config::reset($hard, $reinstantiate);
1600
+		$instance->CART           = null;
1601
+		$instance->MRM            = null;
1602
+		$instance->AssetsRegistry = LoaderFactory::getLoader()->getShared(
1603
+			'EventEspresso\core\services\assets\Registry'
1604
+		);
1605
+		//messages reset
1606
+		EED_Messages::reset();
1607
+		//handle of objects cached on LIB
1608
+		foreach (array('LIB', 'modules') as $cache) {
1609
+			foreach ($instance->{$cache} as $class_name => $class) {
1610
+				if (self::_reset_and_unset_object($class, $reset_models)) {
1611
+					unset($instance->{$cache}->{$class_name});
1612
+				}
1613
+			}
1614
+		}
1615
+		return $instance;
1616
+	}
1617
+
1618
+
1619
+	/**
1620
+	 * if passed object implements ResettableInterface, then call it's reset() method
1621
+	 * if passed object implements InterminableInterface, then return false,
1622
+	 * to indicate that it should NOT be cleared from the Registry cache
1623
+	 *
1624
+	 * @param      $object
1625
+	 * @param bool $reset_models
1626
+	 * @return bool returns true if cached object should be unset
1627
+	 */
1628
+	private static function _reset_and_unset_object($object, $reset_models)
1629
+	{
1630
+		if (! is_object($object)) {
1631
+			// don't unset anything that's not an object
1632
+			return false;
1633
+		}
1634
+		if ($object instanceof EED_Module) {
1635
+			$object::reset();
1636
+			// don't unset modules
1637
+			return false;
1638
+		}
1639
+		if ($object instanceof ResettableInterface) {
1640
+			if ($object instanceof EEM_Base) {
1641
+				if ($reset_models) {
1642
+					$object->reset();
1643
+					return true;
1644
+				}
1645
+				return false;
1646
+			}
1647
+			$object->reset();
1648
+			return true;
1649
+		}
1650
+		if (! $object instanceof InterminableInterface) {
1651
+			return true;
1652
+		}
1653
+		return false;
1654
+	}
1655
+
1656
+
1657
+	/**
1658
+	 * Gets all the custom post type models defined
1659
+	 *
1660
+	 * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1661
+	 */
1662
+	public function cpt_models()
1663
+	{
1664
+		$cpt_models = array();
1665
+		foreach ($this->non_abstract_db_models as $short_name => $classname) {
1666
+			if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1667
+				$cpt_models[ $short_name ] = $classname;
1668
+			}
1669
+		}
1670
+		return $cpt_models;
1671
+	}
1672
+
1673
+
1674
+	/**
1675
+	 * @return \EE_Config
1676
+	 */
1677
+	public static function CFG()
1678
+	{
1679
+		return self::instance()->CFG;
1680
+	}
1681
+
1682
+
1683
+	/**
1684
+	 * @deprecated $VID:$
1685
+	 * @param string $class_name
1686
+	 * @return ReflectionClass
1687
+	 * @throws ReflectionException
1688
+	 * @throws InvalidDataTypeException
1689
+	 */
1690
+	public function get_ReflectionClass($class_name)
1691
+	{
1692
+		return $this->mirror->getReflectionClass($class_name);
1693
+	}
1694 1694
 }
1695 1695
 // End of file EE_Registry.core.php
1696 1696
 // Location: ./core/EE_Registry.core.php
Please login to merge, or discard this patch.
core/services/assets/Registry.php 2 patches
Indentation   +694 added lines, -694 removed lines patch added patch discarded remove patch
@@ -27,705 +27,705 @@
 block discarded – undo
27 27
 class Registry
28 28
 {
29 29
 
30
-    const ASSET_TYPE_CSS = 'css';
31
-    const ASSET_TYPE_JS = 'js';
32
-    const ASSET_NAMESPACE = 'core';
33
-
34
-    /**
35
-     * @var EE_Template_Config $template_config
36
-     */
37
-    protected $template_config;
38
-
39
-    /**
40
-     * @var EE_Currency_Config $currency_config
41
-     */
42
-    protected $currency_config;
43
-
44
-    /**
45
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
46
-     *
47
-     * @var array
48
-     */
49
-    protected $jsdata = array();
50
-
51
-
52
-    /**
53
-     * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
54
-     * page source.
55
-     * @var array
56
-     */
57
-    protected $script_handles_with_data = array();
58
-
59
-
60
-    /**
61
-     * @var DomainInterface
62
-     */
63
-    protected $domain;
64
-
65
-
66
-    /**
67
-     * @var I18nRegistry
68
-     */
69
-    private $i18n_registry;
70
-
71
-
72
-
73
-    /**
74
-     * Holds the manifest data obtained from registered manifest files.
75
-     * Manifests are maps of asset chunk name to actual built asset file names.
76
-     * Shape of this array is:
77
-     *
78
-     * array(
79
-     *  'some_namespace_slug' => array(
80
-     *      'some_chunk_name' => array(
81
-     *          'js' => 'filename.js'
82
-     *          'css' => 'filename.js'
83
-     *      ),
84
-     *      'url_base' => 'https://baseurl.com/to/assets
85
-     *  )
86
-     * )
87
-     *
88
-     * @var array
89
-     */
90
-    private $manifest_data = array();
91
-
92
-
93
-    /**
94
-     * Registry constructor.
95
-     * Hooking into WP actions for script registry.
96
-     *
97
-     * @param EE_Template_Config $template_config
98
-     * @param EE_Currency_Config $currency_config
99
-     * @param I18nRegistry       $i18n_registry
100
-     * @param DomainInterface    $domain
101
-     * @throws InvalidArgumentException
102
-     * @throws InvalidFilePathException
103
-     */
104
-    public function __construct(
105
-        EE_Template_Config $template_config,
106
-        EE_Currency_Config $currency_config,
107
-        I18nRegistry $i18n_registry,
108
-        DomainInterface $domain
109
-    ) {
110
-        $this->template_config = $template_config;
111
-        $this->currency_config = $currency_config;
112
-        $this->domain = $domain;
113
-        $this->i18n_registry = $i18n_registry;
114
-        $this->registerManifestFile(
115
-            self::ASSET_NAMESPACE,
116
-            $this->domain->distributionAssetsUrl(),
117
-            $this->domain->distributionAssetsPath() . 'build-manifest.json'
118
-        );
119
-        add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
120
-        add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
121
-        add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2);
122
-        add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2);
123
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
124
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
125
-    }
126
-
127
-
128
-    /**
129
-     * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
130
-     * translation handling.
131
-     *
132
-     * @return I18nRegistry
133
-     */
134
-    public function getI18nRegistry()
135
-    {
136
-        return $this->i18n_registry;
137
-    }
138
-
139
-    /**
140
-     * Callback for the WP script actions.
141
-     * Used to register globally accessible core scripts.
142
-     * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency.
143
-     *
144
-     */
145
-    public function scripts()
146
-    {
147
-        global $wp_version;
148
-        wp_register_script(
149
-            'ee-manifest',
150
-            $this->getJsUrl(self::ASSET_NAMESPACE, 'manifest'),
151
-            array(),
152
-            null,
153
-            true
154
-        );
155
-        wp_register_script(
156
-            'eejs-core',
157
-            $this->getJsUrl(self::ASSET_NAMESPACE, 'eejs'),
158
-            array('ee-manifest'),
159
-            null,
160
-            true
161
-        );
162
-        wp_register_script(
163
-            'ee-vendor-react',
164
-            $this->getJsUrl(self::ASSET_NAMESPACE, 'reactVendor'),
165
-            array('eejs-core'),
166
-            null,
167
-            true
168
-        );
169
-        //only run this if WordPress 4.4.0 > is in use.
170
-        if (version_compare($wp_version, '4.4.0', '>')) {
171
-            //js.api
172
-            wp_register_script(
173
-                'eejs-api',
174
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
175
-                array('underscore', 'eejs-core'),
176
-                EVENT_ESPRESSO_VERSION,
177
-                true
178
-            );
179
-            $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
180
-            $this->jsdata['paths'] = array(
181
-                'rest_route' => rest_url('ee/v4.8.36/'),
182
-                'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName()
183
-            );
184
-        }
185
-        if (! is_admin()) {
186
-            $this->loadCoreCss();
187
-        }
188
-        $this->registerTranslationsForHandles(array('eejs-core'));
189
-        $this->loadCoreJs();
190
-        $this->loadJqueryValidate();
191
-        $this->loadAccountingJs();
192
-        $this->loadQtipJs();
193
-        $this->registerAdminAssets();
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     * Call back for the script print in frontend and backend.
200
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
201
-     *
202
-     * @since 4.9.31.rc.015
203
-     */
204
-    public function enqueueData()
205
-    {
206
-        $this->removeAlreadyRegisteredDataForScriptHandles();
207
-        wp_add_inline_script(
208
-            'eejs-core',
209
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
210
-            'before'
211
-        );
212
-        wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
213
-        $this->localizeAccountingJs();
214
-        $this->addRegisteredScriptHandlesWithData('eejs-core');
215
-        $this->addRegisteredScriptHandlesWithData('espresso_core');
216
-    }
217
-
218
-
219
-
220
-    /**
221
-     * Used to add data to eejs.data object.
222
-     * Note:  Overriding existing data is not allowed.
223
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
224
-     * If the data you add is something like this:
225
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
226
-     * It will be exposed in the page source as:
227
-     *  eejs.data.my_plugin_data.foo == gar
228
-     *
229
-     * @param string       $key   Key used to access your data
230
-     * @param string|array $value Value to attach to key
231
-     * @throws InvalidArgumentException
232
-     */
233
-    public function addData($key, $value)
234
-    {
235
-        if ($this->verifyDataNotExisting($key)) {
236
-            $this->jsdata[$key] = $value;
237
-        }
238
-    }
239
-
240
-
241
-
242
-    /**
243
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
244
-     * elements in an array.
245
-     * When you use this method, the value you include will be appended to the end of an array on $key.
246
-     * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
247
-     * object like this, eejs.data.test = [ my_data,
248
-     * ]
249
-     * If there has already been a scalar value attached to the data object given key, then
250
-     * this will throw an exception.
251
-     *
252
-     * @param string       $key   Key to attach data to.
253
-     * @param string|array $value Value being registered.
254
-     * @throws InvalidArgumentException
255
-     */
256
-    public function pushData($key, $value)
257
-    {
258
-        if (isset($this->jsdata[$key])
259
-            && ! is_array($this->jsdata[$key])
260
-        ) {
261
-            throw new invalidArgumentException(
262
-                sprintf(
263
-                    __(
264
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
30
+	const ASSET_TYPE_CSS = 'css';
31
+	const ASSET_TYPE_JS = 'js';
32
+	const ASSET_NAMESPACE = 'core';
33
+
34
+	/**
35
+	 * @var EE_Template_Config $template_config
36
+	 */
37
+	protected $template_config;
38
+
39
+	/**
40
+	 * @var EE_Currency_Config $currency_config
41
+	 */
42
+	protected $currency_config;
43
+
44
+	/**
45
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
46
+	 *
47
+	 * @var array
48
+	 */
49
+	protected $jsdata = array();
50
+
51
+
52
+	/**
53
+	 * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
54
+	 * page source.
55
+	 * @var array
56
+	 */
57
+	protected $script_handles_with_data = array();
58
+
59
+
60
+	/**
61
+	 * @var DomainInterface
62
+	 */
63
+	protected $domain;
64
+
65
+
66
+	/**
67
+	 * @var I18nRegistry
68
+	 */
69
+	private $i18n_registry;
70
+
71
+
72
+
73
+	/**
74
+	 * Holds the manifest data obtained from registered manifest files.
75
+	 * Manifests are maps of asset chunk name to actual built asset file names.
76
+	 * Shape of this array is:
77
+	 *
78
+	 * array(
79
+	 *  'some_namespace_slug' => array(
80
+	 *      'some_chunk_name' => array(
81
+	 *          'js' => 'filename.js'
82
+	 *          'css' => 'filename.js'
83
+	 *      ),
84
+	 *      'url_base' => 'https://baseurl.com/to/assets
85
+	 *  )
86
+	 * )
87
+	 *
88
+	 * @var array
89
+	 */
90
+	private $manifest_data = array();
91
+
92
+
93
+	/**
94
+	 * Registry constructor.
95
+	 * Hooking into WP actions for script registry.
96
+	 *
97
+	 * @param EE_Template_Config $template_config
98
+	 * @param EE_Currency_Config $currency_config
99
+	 * @param I18nRegistry       $i18n_registry
100
+	 * @param DomainInterface    $domain
101
+	 * @throws InvalidArgumentException
102
+	 * @throws InvalidFilePathException
103
+	 */
104
+	public function __construct(
105
+		EE_Template_Config $template_config,
106
+		EE_Currency_Config $currency_config,
107
+		I18nRegistry $i18n_registry,
108
+		DomainInterface $domain
109
+	) {
110
+		$this->template_config = $template_config;
111
+		$this->currency_config = $currency_config;
112
+		$this->domain = $domain;
113
+		$this->i18n_registry = $i18n_registry;
114
+		$this->registerManifestFile(
115
+			self::ASSET_NAMESPACE,
116
+			$this->domain->distributionAssetsUrl(),
117
+			$this->domain->distributionAssetsPath() . 'build-manifest.json'
118
+		);
119
+		add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
120
+		add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
121
+		add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2);
122
+		add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2);
123
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
124
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
125
+	}
126
+
127
+
128
+	/**
129
+	 * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
130
+	 * translation handling.
131
+	 *
132
+	 * @return I18nRegistry
133
+	 */
134
+	public function getI18nRegistry()
135
+	{
136
+		return $this->i18n_registry;
137
+	}
138
+
139
+	/**
140
+	 * Callback for the WP script actions.
141
+	 * Used to register globally accessible core scripts.
142
+	 * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency.
143
+	 *
144
+	 */
145
+	public function scripts()
146
+	{
147
+		global $wp_version;
148
+		wp_register_script(
149
+			'ee-manifest',
150
+			$this->getJsUrl(self::ASSET_NAMESPACE, 'manifest'),
151
+			array(),
152
+			null,
153
+			true
154
+		);
155
+		wp_register_script(
156
+			'eejs-core',
157
+			$this->getJsUrl(self::ASSET_NAMESPACE, 'eejs'),
158
+			array('ee-manifest'),
159
+			null,
160
+			true
161
+		);
162
+		wp_register_script(
163
+			'ee-vendor-react',
164
+			$this->getJsUrl(self::ASSET_NAMESPACE, 'reactVendor'),
165
+			array('eejs-core'),
166
+			null,
167
+			true
168
+		);
169
+		//only run this if WordPress 4.4.0 > is in use.
170
+		if (version_compare($wp_version, '4.4.0', '>')) {
171
+			//js.api
172
+			wp_register_script(
173
+				'eejs-api',
174
+				EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
175
+				array('underscore', 'eejs-core'),
176
+				EVENT_ESPRESSO_VERSION,
177
+				true
178
+			);
179
+			$this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
180
+			$this->jsdata['paths'] = array(
181
+				'rest_route' => rest_url('ee/v4.8.36/'),
182
+				'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName()
183
+			);
184
+		}
185
+		if (! is_admin()) {
186
+			$this->loadCoreCss();
187
+		}
188
+		$this->registerTranslationsForHandles(array('eejs-core'));
189
+		$this->loadCoreJs();
190
+		$this->loadJqueryValidate();
191
+		$this->loadAccountingJs();
192
+		$this->loadQtipJs();
193
+		$this->registerAdminAssets();
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 * Call back for the script print in frontend and backend.
200
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
201
+	 *
202
+	 * @since 4.9.31.rc.015
203
+	 */
204
+	public function enqueueData()
205
+	{
206
+		$this->removeAlreadyRegisteredDataForScriptHandles();
207
+		wp_add_inline_script(
208
+			'eejs-core',
209
+			'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
210
+			'before'
211
+		);
212
+		wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
213
+		$this->localizeAccountingJs();
214
+		$this->addRegisteredScriptHandlesWithData('eejs-core');
215
+		$this->addRegisteredScriptHandlesWithData('espresso_core');
216
+	}
217
+
218
+
219
+
220
+	/**
221
+	 * Used to add data to eejs.data object.
222
+	 * Note:  Overriding existing data is not allowed.
223
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
224
+	 * If the data you add is something like this:
225
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
226
+	 * It will be exposed in the page source as:
227
+	 *  eejs.data.my_plugin_data.foo == gar
228
+	 *
229
+	 * @param string       $key   Key used to access your data
230
+	 * @param string|array $value Value to attach to key
231
+	 * @throws InvalidArgumentException
232
+	 */
233
+	public function addData($key, $value)
234
+	{
235
+		if ($this->verifyDataNotExisting($key)) {
236
+			$this->jsdata[$key] = $value;
237
+		}
238
+	}
239
+
240
+
241
+
242
+	/**
243
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
244
+	 * elements in an array.
245
+	 * When you use this method, the value you include will be appended to the end of an array on $key.
246
+	 * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
247
+	 * object like this, eejs.data.test = [ my_data,
248
+	 * ]
249
+	 * If there has already been a scalar value attached to the data object given key, then
250
+	 * this will throw an exception.
251
+	 *
252
+	 * @param string       $key   Key to attach data to.
253
+	 * @param string|array $value Value being registered.
254
+	 * @throws InvalidArgumentException
255
+	 */
256
+	public function pushData($key, $value)
257
+	{
258
+		if (isset($this->jsdata[$key])
259
+			&& ! is_array($this->jsdata[$key])
260
+		) {
261
+			throw new invalidArgumentException(
262
+				sprintf(
263
+					__(
264
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
265 265
                          push values to this data element when it is an array.',
266
-                        'event_espresso'
267
-                    ),
268
-                    $key,
269
-                    __METHOD__
270
-                )
271
-            );
272
-        }
273
-        $this->jsdata[$key][] = $value;
274
-    }
275
-
276
-
277
-
278
-    /**
279
-     * Used to set content used by javascript for a template.
280
-     * Note: Overrides of existing registered templates are not allowed.
281
-     *
282
-     * @param string $template_reference
283
-     * @param string $template_content
284
-     * @throws InvalidArgumentException
285
-     */
286
-    public function addTemplate($template_reference, $template_content)
287
-    {
288
-        if (! isset($this->jsdata['templates'])) {
289
-            $this->jsdata['templates'] = array();
290
-        }
291
-        //no overrides allowed.
292
-        if (isset($this->jsdata['templates'][$template_reference])) {
293
-            throw new invalidArgumentException(
294
-                sprintf(
295
-                    __(
296
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
297
-                        'event_espresso'
298
-                    ),
299
-                    $template_reference
300
-                )
301
-            );
302
-        }
303
-        $this->jsdata['templates'][$template_reference] = $template_content;
304
-    }
305
-
306
-
307
-
308
-    /**
309
-     * Retrieve the template content already registered for the given reference.
310
-     *
311
-     * @param string $template_reference
312
-     * @return string
313
-     */
314
-    public function getTemplate($template_reference)
315
-    {
316
-        return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference])
317
-            ? $this->jsdata['templates'][$template_reference]
318
-            : '';
319
-    }
320
-
321
-
322
-
323
-    /**
324
-     * Retrieve registered data.
325
-     *
326
-     * @param string $key Name of key to attach data to.
327
-     * @return mixed                If there is no for the given key, then false is returned.
328
-     */
329
-    public function getData($key)
330
-    {
331
-        return isset($this->jsdata[$key])
332
-            ? $this->jsdata[$key]
333
-            : false;
334
-    }
335
-
336
-
337
-    /**
338
-     * Get the actual asset path for asset manifests.
339
-     * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
340
-     * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
341
-     *                           asset file location.
342
-     * @param string $chunk_name
343
-     * @param string $asset_type
344
-     * @return string
345
-     * @since 4.9.59.p
346
-     */
347
-    public function getAssetUrl($namespace, $chunk_name, $asset_type)
348
-    {
349
-        $url = isset(
350
-            $this->manifest_data[$namespace][$chunk_name][$asset_type],
351
-            $this->manifest_data[$namespace]['url_base']
352
-        )
353
-            ? $this->manifest_data[$namespace]['url_base']
354
-              . $this->manifest_data[$namespace][$chunk_name][$asset_type]
355
-            : $chunk_name;
356
-        return apply_filters(
357
-            'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
358
-            $url,
359
-            $namespace,
360
-            $chunk_name,
361
-            $asset_type
362
-        );
363
-    }
364
-
365
-
366
-    /**
367
-     * Return the url to a js file for the given namespace and chunk name.
368
-     *
369
-     * @param string $namespace
370
-     * @param string $chunk_name
371
-     * @return string
372
-     */
373
-    public function getJsUrl($namespace, $chunk_name)
374
-    {
375
-        return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_JS);
376
-    }
377
-
378
-
379
-    /**
380
-     * Return the url to a css file for the given namespace and chunk name.
381
-     *
382
-     * @param string $namespace
383
-     * @param string $chunk_name
384
-     * @return string
385
-     */
386
-    public function getCssUrl($namespace, $chunk_name)
387
-    {
388
-        return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_CSS);
389
-    }
390
-
391
-
392
-    /**
393
-     * Used to register a js/css manifest file with the registered_manifest_files property.
394
-     *
395
-     * @param string $namespace     Provided to associate the manifest file with a specific namespace.
396
-     * @param string $url_base      The url base for the manifest file location.
397
-     * @param string $manifest_file The absolute path to the manifest file.
398
-     * @throws InvalidArgumentException
399
-     * @throws InvalidFilePathException
400
-     * @since 4.9.59.p
401
-     */
402
-    public function registerManifestFile($namespace, $url_base, $manifest_file)
403
-    {
404
-        if (isset($this->manifest_data[$namespace])) {
405
-            throw new InvalidArgumentException(
406
-                sprintf(
407
-                    esc_html__(
408
-                        'The namespace for this manifest file has already been registered, choose a namespace other than %s',
409
-                        'event_espresso'
410
-                    ),
411
-                    $namespace
412
-                )
413
-            );
414
-        }
415
-        if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
416
-            if (is_admin()) {
417
-                EE_Error::add_error(
418
-                    sprintf(
419
-                        esc_html__(
420
-                            'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
421
-                            'event_espresso'
422
-                        ),
423
-                        'Event Espresso',
424
-                        $url_base,
425
-                        'plugins_url',
426
-                        'WP_PLUGIN_URL'
427
-                    ),
428
-                    __FILE__,
429
-                    __FUNCTION__,
430
-                    __LINE__
431
-                );
432
-            }
433
-            return;
434
-        }
435
-        $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file);
436
-        if (! isset($this->manifest_data[$namespace]['url_base'])) {
437
-            $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base);
438
-        }
439
-    }
440
-
441
-
442
-
443
-    /**
444
-     * Decodes json from the provided manifest file.
445
-     *
446
-     * @since 4.9.59.p
447
-     * @param string $manifest_file Path to manifest file.
448
-     * @return array
449
-     * @throws InvalidFilePathException
450
-     */
451
-    private function decodeManifestFile($manifest_file)
452
-    {
453
-        if (! file_exists($manifest_file)) {
454
-            throw new InvalidFilePathException($manifest_file);
455
-        }
456
-        return json_decode(file_get_contents($manifest_file), true);
457
-    }
458
-
459
-
460
-
461
-    /**
462
-     * Verifies whether the given data exists already on the jsdata array.
463
-     * Overriding data is not allowed.
464
-     *
465
-     * @param string $key Index for data.
466
-     * @return bool        If valid then return true.
467
-     * @throws InvalidArgumentException if data already exists.
468
-     */
469
-    protected function verifyDataNotExisting($key)
470
-    {
471
-        if (isset($this->jsdata[$key])) {
472
-            if (is_array($this->jsdata[$key])) {
473
-                throw new InvalidArgumentException(
474
-                    sprintf(
475
-                        __(
476
-                            'The value for %1$s already exists in the Registry::eejs object.
266
+						'event_espresso'
267
+					),
268
+					$key,
269
+					__METHOD__
270
+				)
271
+			);
272
+		}
273
+		$this->jsdata[$key][] = $value;
274
+	}
275
+
276
+
277
+
278
+	/**
279
+	 * Used to set content used by javascript for a template.
280
+	 * Note: Overrides of existing registered templates are not allowed.
281
+	 *
282
+	 * @param string $template_reference
283
+	 * @param string $template_content
284
+	 * @throws InvalidArgumentException
285
+	 */
286
+	public function addTemplate($template_reference, $template_content)
287
+	{
288
+		if (! isset($this->jsdata['templates'])) {
289
+			$this->jsdata['templates'] = array();
290
+		}
291
+		//no overrides allowed.
292
+		if (isset($this->jsdata['templates'][$template_reference])) {
293
+			throw new invalidArgumentException(
294
+				sprintf(
295
+					__(
296
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
297
+						'event_espresso'
298
+					),
299
+					$template_reference
300
+				)
301
+			);
302
+		}
303
+		$this->jsdata['templates'][$template_reference] = $template_content;
304
+	}
305
+
306
+
307
+
308
+	/**
309
+	 * Retrieve the template content already registered for the given reference.
310
+	 *
311
+	 * @param string $template_reference
312
+	 * @return string
313
+	 */
314
+	public function getTemplate($template_reference)
315
+	{
316
+		return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference])
317
+			? $this->jsdata['templates'][$template_reference]
318
+			: '';
319
+	}
320
+
321
+
322
+
323
+	/**
324
+	 * Retrieve registered data.
325
+	 *
326
+	 * @param string $key Name of key to attach data to.
327
+	 * @return mixed                If there is no for the given key, then false is returned.
328
+	 */
329
+	public function getData($key)
330
+	{
331
+		return isset($this->jsdata[$key])
332
+			? $this->jsdata[$key]
333
+			: false;
334
+	}
335
+
336
+
337
+	/**
338
+	 * Get the actual asset path for asset manifests.
339
+	 * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
340
+	 * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
341
+	 *                           asset file location.
342
+	 * @param string $chunk_name
343
+	 * @param string $asset_type
344
+	 * @return string
345
+	 * @since 4.9.59.p
346
+	 */
347
+	public function getAssetUrl($namespace, $chunk_name, $asset_type)
348
+	{
349
+		$url = isset(
350
+			$this->manifest_data[$namespace][$chunk_name][$asset_type],
351
+			$this->manifest_data[$namespace]['url_base']
352
+		)
353
+			? $this->manifest_data[$namespace]['url_base']
354
+			  . $this->manifest_data[$namespace][$chunk_name][$asset_type]
355
+			: $chunk_name;
356
+		return apply_filters(
357
+			'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
358
+			$url,
359
+			$namespace,
360
+			$chunk_name,
361
+			$asset_type
362
+		);
363
+	}
364
+
365
+
366
+	/**
367
+	 * Return the url to a js file for the given namespace and chunk name.
368
+	 *
369
+	 * @param string $namespace
370
+	 * @param string $chunk_name
371
+	 * @return string
372
+	 */
373
+	public function getJsUrl($namespace, $chunk_name)
374
+	{
375
+		return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_JS);
376
+	}
377
+
378
+
379
+	/**
380
+	 * Return the url to a css file for the given namespace and chunk name.
381
+	 *
382
+	 * @param string $namespace
383
+	 * @param string $chunk_name
384
+	 * @return string
385
+	 */
386
+	public function getCssUrl($namespace, $chunk_name)
387
+	{
388
+		return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_CSS);
389
+	}
390
+
391
+
392
+	/**
393
+	 * Used to register a js/css manifest file with the registered_manifest_files property.
394
+	 *
395
+	 * @param string $namespace     Provided to associate the manifest file with a specific namespace.
396
+	 * @param string $url_base      The url base for the manifest file location.
397
+	 * @param string $manifest_file The absolute path to the manifest file.
398
+	 * @throws InvalidArgumentException
399
+	 * @throws InvalidFilePathException
400
+	 * @since 4.9.59.p
401
+	 */
402
+	public function registerManifestFile($namespace, $url_base, $manifest_file)
403
+	{
404
+		if (isset($this->manifest_data[$namespace])) {
405
+			throw new InvalidArgumentException(
406
+				sprintf(
407
+					esc_html__(
408
+						'The namespace for this manifest file has already been registered, choose a namespace other than %s',
409
+						'event_espresso'
410
+					),
411
+					$namespace
412
+				)
413
+			);
414
+		}
415
+		if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
416
+			if (is_admin()) {
417
+				EE_Error::add_error(
418
+					sprintf(
419
+						esc_html__(
420
+							'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
421
+							'event_espresso'
422
+						),
423
+						'Event Espresso',
424
+						$url_base,
425
+						'plugins_url',
426
+						'WP_PLUGIN_URL'
427
+					),
428
+					__FILE__,
429
+					__FUNCTION__,
430
+					__LINE__
431
+				);
432
+			}
433
+			return;
434
+		}
435
+		$this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file);
436
+		if (! isset($this->manifest_data[$namespace]['url_base'])) {
437
+			$this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base);
438
+		}
439
+	}
440
+
441
+
442
+
443
+	/**
444
+	 * Decodes json from the provided manifest file.
445
+	 *
446
+	 * @since 4.9.59.p
447
+	 * @param string $manifest_file Path to manifest file.
448
+	 * @return array
449
+	 * @throws InvalidFilePathException
450
+	 */
451
+	private function decodeManifestFile($manifest_file)
452
+	{
453
+		if (! file_exists($manifest_file)) {
454
+			throw new InvalidFilePathException($manifest_file);
455
+		}
456
+		return json_decode(file_get_contents($manifest_file), true);
457
+	}
458
+
459
+
460
+
461
+	/**
462
+	 * Verifies whether the given data exists already on the jsdata array.
463
+	 * Overriding data is not allowed.
464
+	 *
465
+	 * @param string $key Index for data.
466
+	 * @return bool        If valid then return true.
467
+	 * @throws InvalidArgumentException if data already exists.
468
+	 */
469
+	protected function verifyDataNotExisting($key)
470
+	{
471
+		if (isset($this->jsdata[$key])) {
472
+			if (is_array($this->jsdata[$key])) {
473
+				throw new InvalidArgumentException(
474
+					sprintf(
475
+						__(
476
+							'The value for %1$s already exists in the Registry::eejs object.
477 477
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
478 478
                             %2$s method to push your value to the array.',
479
-                            'event_espresso'
480
-                        ),
481
-                        $key,
482
-                        'pushData()'
483
-                    )
484
-                );
485
-            }
486
-            throw new InvalidArgumentException(
487
-                sprintf(
488
-                    __(
489
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
479
+							'event_espresso'
480
+						),
481
+						$key,
482
+						'pushData()'
483
+					)
484
+				);
485
+			}
486
+			throw new InvalidArgumentException(
487
+				sprintf(
488
+					__(
489
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
490 490
                         allowed.  Consider attaching your value to a different key',
491
-                        'event_espresso'
492
-                    ),
493
-                    $key
494
-                )
495
-            );
496
-        }
497
-        return true;
498
-    }
499
-
500
-
501
-
502
-    /**
503
-     * registers core default stylesheets
504
-     */
505
-    private function loadCoreCss()
506
-    {
507
-        if ($this->template_config->enable_default_style) {
508
-            $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
509
-                ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
510
-                : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
511
-            wp_register_style(
512
-                'espresso_default',
513
-                $default_stylesheet_path,
514
-                array('dashicons'),
515
-                EVENT_ESPRESSO_VERSION
516
-            );
517
-            //Load custom style sheet if available
518
-            if ($this->template_config->custom_style_sheet !== null) {
519
-                wp_register_style(
520
-                    'espresso_custom_css',
521
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
522
-                    array('espresso_default'),
523
-                    EVENT_ESPRESSO_VERSION
524
-                );
525
-            }
526
-        }
527
-    }
528
-
529
-
530
-
531
-    /**
532
-     * registers core default javascript
533
-     */
534
-    private function loadCoreJs()
535
-    {
536
-        // load core js
537
-        wp_register_script(
538
-            'espresso_core',
539
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
540
-            array('jquery'),
541
-            EVENT_ESPRESSO_VERSION,
542
-            true
543
-        );
544
-    }
545
-
546
-
547
-
548
-    /**
549
-     * registers jQuery Validate for form validation
550
-     */
551
-    private function loadJqueryValidate()
552
-    {
553
-        // register jQuery Validate and additional methods
554
-        wp_register_script(
555
-            'jquery-validate',
556
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
557
-            array('jquery'),
558
-            '1.15.0',
559
-            true
560
-        );
561
-        wp_register_script(
562
-            'jquery-validate-extra-methods',
563
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
564
-            array('jquery', 'jquery-validate'),
565
-            '1.15.0',
566
-            true
567
-        );
568
-    }
569
-
570
-
571
-
572
-    /**
573
-     * registers accounting.js for performing client-side calculations
574
-     */
575
-    private function loadAccountingJs()
576
-    {
577
-        //accounting.js library
578
-        // @link http://josscrowcroft.github.io/accounting.js/
579
-        wp_register_script(
580
-            'ee-accounting-core',
581
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
582
-            array('underscore'),
583
-            '0.3.2',
584
-            true
585
-        );
586
-        wp_register_script(
587
-            'ee-accounting',
588
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
589
-            array('ee-accounting-core'),
590
-            EVENT_ESPRESSO_VERSION,
591
-            true
592
-        );
593
-    }
594
-
595
-
596
-
597
-    /**
598
-     * registers accounting.js for performing client-side calculations
599
-     */
600
-    private function localizeAccountingJs()
601
-    {
602
-        wp_localize_script(
603
-            'ee-accounting',
604
-            'EE_ACCOUNTING_CFG',
605
-            array(
606
-                'currency' => array(
607
-                    'symbol'    => $this->currency_config->sign,
608
-                    'format'    => array(
609
-                        'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
610
-                        'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
611
-                        'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
612
-                    ),
613
-                    'decimal'   => $this->currency_config->dec_mrk,
614
-                    'thousand'  => $this->currency_config->thsnds,
615
-                    'precision' => $this->currency_config->dec_plc,
616
-                ),
617
-                'number'   => array(
618
-                    'precision' => $this->currency_config->dec_plc,
619
-                    'thousand'  => $this->currency_config->thsnds,
620
-                    'decimal'   => $this->currency_config->dec_mrk,
621
-                ),
622
-            )
623
-        );
624
-        $this->addRegisteredScriptHandlesWithData('ee-accounting');
625
-    }
626
-
627
-
628
-
629
-    /**
630
-     * registers assets for cleaning your ears
631
-     */
632
-    private function loadQtipJs()
633
-    {
634
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
635
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
636
-        if (apply_filters('FHEE_load_qtip', false)) {
637
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
638
-        }
639
-    }
640
-
641
-
642
-    /**
643
-     * This is used to set registered script handles that have data.
644
-     * @param string $script_handle
645
-     */
646
-    private function addRegisteredScriptHandlesWithData($script_handle)
647
-    {
648
-        $this->script_handles_with_data[$script_handle] = $script_handle;
649
-    }
650
-
651
-
652
-    /**i
491
+						'event_espresso'
492
+					),
493
+					$key
494
+				)
495
+			);
496
+		}
497
+		return true;
498
+	}
499
+
500
+
501
+
502
+	/**
503
+	 * registers core default stylesheets
504
+	 */
505
+	private function loadCoreCss()
506
+	{
507
+		if ($this->template_config->enable_default_style) {
508
+			$default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
509
+				? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
510
+				: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
511
+			wp_register_style(
512
+				'espresso_default',
513
+				$default_stylesheet_path,
514
+				array('dashicons'),
515
+				EVENT_ESPRESSO_VERSION
516
+			);
517
+			//Load custom style sheet if available
518
+			if ($this->template_config->custom_style_sheet !== null) {
519
+				wp_register_style(
520
+					'espresso_custom_css',
521
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
522
+					array('espresso_default'),
523
+					EVENT_ESPRESSO_VERSION
524
+				);
525
+			}
526
+		}
527
+	}
528
+
529
+
530
+
531
+	/**
532
+	 * registers core default javascript
533
+	 */
534
+	private function loadCoreJs()
535
+	{
536
+		// load core js
537
+		wp_register_script(
538
+			'espresso_core',
539
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
540
+			array('jquery'),
541
+			EVENT_ESPRESSO_VERSION,
542
+			true
543
+		);
544
+	}
545
+
546
+
547
+
548
+	/**
549
+	 * registers jQuery Validate for form validation
550
+	 */
551
+	private function loadJqueryValidate()
552
+	{
553
+		// register jQuery Validate and additional methods
554
+		wp_register_script(
555
+			'jquery-validate',
556
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
557
+			array('jquery'),
558
+			'1.15.0',
559
+			true
560
+		);
561
+		wp_register_script(
562
+			'jquery-validate-extra-methods',
563
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
564
+			array('jquery', 'jquery-validate'),
565
+			'1.15.0',
566
+			true
567
+		);
568
+	}
569
+
570
+
571
+
572
+	/**
573
+	 * registers accounting.js for performing client-side calculations
574
+	 */
575
+	private function loadAccountingJs()
576
+	{
577
+		//accounting.js library
578
+		// @link http://josscrowcroft.github.io/accounting.js/
579
+		wp_register_script(
580
+			'ee-accounting-core',
581
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
582
+			array('underscore'),
583
+			'0.3.2',
584
+			true
585
+		);
586
+		wp_register_script(
587
+			'ee-accounting',
588
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
589
+			array('ee-accounting-core'),
590
+			EVENT_ESPRESSO_VERSION,
591
+			true
592
+		);
593
+	}
594
+
595
+
596
+
597
+	/**
598
+	 * registers accounting.js for performing client-side calculations
599
+	 */
600
+	private function localizeAccountingJs()
601
+	{
602
+		wp_localize_script(
603
+			'ee-accounting',
604
+			'EE_ACCOUNTING_CFG',
605
+			array(
606
+				'currency' => array(
607
+					'symbol'    => $this->currency_config->sign,
608
+					'format'    => array(
609
+						'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
610
+						'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
611
+						'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
612
+					),
613
+					'decimal'   => $this->currency_config->dec_mrk,
614
+					'thousand'  => $this->currency_config->thsnds,
615
+					'precision' => $this->currency_config->dec_plc,
616
+				),
617
+				'number'   => array(
618
+					'precision' => $this->currency_config->dec_plc,
619
+					'thousand'  => $this->currency_config->thsnds,
620
+					'decimal'   => $this->currency_config->dec_mrk,
621
+				),
622
+			)
623
+		);
624
+		$this->addRegisteredScriptHandlesWithData('ee-accounting');
625
+	}
626
+
627
+
628
+
629
+	/**
630
+	 * registers assets for cleaning your ears
631
+	 */
632
+	private function loadQtipJs()
633
+	{
634
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
635
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
636
+		if (apply_filters('FHEE_load_qtip', false)) {
637
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
638
+		}
639
+	}
640
+
641
+
642
+	/**
643
+	 * This is used to set registered script handles that have data.
644
+	 * @param string $script_handle
645
+	 */
646
+	private function addRegisteredScriptHandlesWithData($script_handle)
647
+	{
648
+		$this->script_handles_with_data[$script_handle] = $script_handle;
649
+	}
650
+
651
+
652
+	/**i
653 653
      * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
654 654
      * Dependency stored in WP_Scripts if its set.
655 655
      */
656
-    private function removeAlreadyRegisteredDataForScriptHandles()
657
-    {
658
-        if (empty($this->script_handles_with_data)) {
659
-            return;
660
-        }
661
-        foreach ($this->script_handles_with_data as $script_handle) {
662
-            $this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
663
-        }
664
-    }
665
-
666
-
667
-    /**
668
-     * Removes any data dependency registered in WP_Scripts if its set.
669
-     * @param string $script_handle
670
-     */
671
-    private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
672
-    {
673
-        if (isset($this->script_handles_with_data[$script_handle])) {
674
-            global $wp_scripts;
675
-            $unset_handle = false;
676
-            if ($wp_scripts->get_data($script_handle, 'data')) {
677
-                unset($wp_scripts->registered[$script_handle]->extra['data']);
678
-                $unset_handle = true;
679
-            }
680
-            //deal with inline_scripts
681
-            if ($wp_scripts->get_data($script_handle, 'before')) {
682
-                unset($wp_scripts->registered[$script_handle]->extra['before']);
683
-                $unset_handle = true;
684
-            }
685
-            if ($wp_scripts->get_data($script_handle, 'after')) {
686
-                unset($wp_scripts->registered[$script_handle]->extra['after']);
687
-            }
688
-            if ($unset_handle) {
689
-                unset($this->script_handles_with_data[$script_handle]);
690
-            }
691
-        }
692
-    }
693
-
694
-
695
-    /**
696
-     * Registers assets that are used in the WordPress admin.
697
-     */
698
-    private function registerAdminAssets()
699
-    {
700
-        wp_register_script(
701
-            'ee-wp-plugins-page',
702
-            $this->getJsUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'),
703
-            array(
704
-                'jquery',
705
-                'ee-vendor-react'
706
-            ),
707
-            null,
708
-            true
709
-        );
710
-        wp_register_style(
711
-            'ee-wp-plugins-page',
712
-            $this->getCssUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'),
713
-            array(),
714
-            null
715
-        );
716
-        $this->registerTranslationsForHandles(array('ee-wp-plugins-page'));
717
-    }
718
-
719
-
720
-    /**
721
-     * All handles that are registered via the registry that might have translations have their translations registered
722
-     *
723
-     * @param array $handles_to_register
724
-     */
725
-    private function registerTranslationsForHandles(array $handles_to_register)
726
-    {
727
-        foreach($handles_to_register as $handle) {
728
-            $this->i18n_registry->registerScriptI18n($handle);
729
-        }
730
-    }
656
+	private function removeAlreadyRegisteredDataForScriptHandles()
657
+	{
658
+		if (empty($this->script_handles_with_data)) {
659
+			return;
660
+		}
661
+		foreach ($this->script_handles_with_data as $script_handle) {
662
+			$this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
663
+		}
664
+	}
665
+
666
+
667
+	/**
668
+	 * Removes any data dependency registered in WP_Scripts if its set.
669
+	 * @param string $script_handle
670
+	 */
671
+	private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
672
+	{
673
+		if (isset($this->script_handles_with_data[$script_handle])) {
674
+			global $wp_scripts;
675
+			$unset_handle = false;
676
+			if ($wp_scripts->get_data($script_handle, 'data')) {
677
+				unset($wp_scripts->registered[$script_handle]->extra['data']);
678
+				$unset_handle = true;
679
+			}
680
+			//deal with inline_scripts
681
+			if ($wp_scripts->get_data($script_handle, 'before')) {
682
+				unset($wp_scripts->registered[$script_handle]->extra['before']);
683
+				$unset_handle = true;
684
+			}
685
+			if ($wp_scripts->get_data($script_handle, 'after')) {
686
+				unset($wp_scripts->registered[$script_handle]->extra['after']);
687
+			}
688
+			if ($unset_handle) {
689
+				unset($this->script_handles_with_data[$script_handle]);
690
+			}
691
+		}
692
+	}
693
+
694
+
695
+	/**
696
+	 * Registers assets that are used in the WordPress admin.
697
+	 */
698
+	private function registerAdminAssets()
699
+	{
700
+		wp_register_script(
701
+			'ee-wp-plugins-page',
702
+			$this->getJsUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'),
703
+			array(
704
+				'jquery',
705
+				'ee-vendor-react'
706
+			),
707
+			null,
708
+			true
709
+		);
710
+		wp_register_style(
711
+			'ee-wp-plugins-page',
712
+			$this->getCssUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'),
713
+			array(),
714
+			null
715
+		);
716
+		$this->registerTranslationsForHandles(array('ee-wp-plugins-page'));
717
+	}
718
+
719
+
720
+	/**
721
+	 * All handles that are registered via the registry that might have translations have their translations registered
722
+	 *
723
+	 * @param array $handles_to_register
724
+	 */
725
+	private function registerTranslationsForHandles(array $handles_to_register)
726
+	{
727
+		foreach($handles_to_register as $handle) {
728
+			$this->i18n_registry->registerScriptI18n($handle);
729
+		}
730
+	}
731 731
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         $this->registerManifestFile(
115 115
             self::ASSET_NAMESPACE,
116 116
             $this->domain->distributionAssetsUrl(),
117
-            $this->domain->distributionAssetsPath() . 'build-manifest.json'
117
+            $this->domain->distributionAssetsPath().'build-manifest.json'
118 118
         );
119 119
         add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
120 120
         add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
             //js.api
172 172
             wp_register_script(
173 173
                 'eejs-api',
174
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
174
+                EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js',
175 175
                 array('underscore', 'eejs-core'),
176 176
                 EVENT_ESPRESSO_VERSION,
177 177
                 true
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
                 'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName()
183 183
             );
184 184
         }
185
-        if (! is_admin()) {
185
+        if ( ! is_admin()) {
186 186
             $this->loadCoreCss();
187 187
         }
188 188
         $this->registerTranslationsForHandles(array('eejs-core'));
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
         $this->removeAlreadyRegisteredDataForScriptHandles();
207 207
         wp_add_inline_script(
208 208
             'eejs-core',
209
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
209
+            'var eejsdata='.wp_json_encode(array('data' => $this->jsdata)),
210 210
             'before'
211 211
         );
212 212
         wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
      */
286 286
     public function addTemplate($template_reference, $template_content)
287 287
     {
288
-        if (! isset($this->jsdata['templates'])) {
288
+        if ( ! isset($this->jsdata['templates'])) {
289 289
             $this->jsdata['templates'] = array();
290 290
         }
291 291
         //no overrides allowed.
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
             return;
434 434
         }
435 435
         $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file);
436
-        if (! isset($this->manifest_data[$namespace]['url_base'])) {
436
+        if ( ! isset($this->manifest_data[$namespace]['url_base'])) {
437 437
             $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base);
438 438
         }
439 439
     }
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
      */
451 451
     private function decodeManifestFile($manifest_file)
452 452
     {
453
-        if (! file_exists($manifest_file)) {
453
+        if ( ! file_exists($manifest_file)) {
454 454
             throw new InvalidFilePathException($manifest_file);
455 455
         }
456 456
         return json_decode(file_get_contents($manifest_file), true);
@@ -505,9 +505,9 @@  discard block
 block discarded – undo
505 505
     private function loadCoreCss()
506 506
     {
507 507
         if ($this->template_config->enable_default_style) {
508
-            $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
508
+            $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css')
509 509
                 ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
510
-                : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
510
+                : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css';
511 511
             wp_register_style(
512 512
                 'espresso_default',
513 513
                 $default_stylesheet_path,
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
             if ($this->template_config->custom_style_sheet !== null) {
519 519
                 wp_register_style(
520 520
                     'espresso_custom_css',
521
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
521
+                    EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet,
522 522
                     array('espresso_default'),
523 523
                     EVENT_ESPRESSO_VERSION
524 524
                 );
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
         // load core js
537 537
         wp_register_script(
538 538
             'espresso_core',
539
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
539
+            EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
540 540
             array('jquery'),
541 541
             EVENT_ESPRESSO_VERSION,
542 542
             true
@@ -553,14 +553,14 @@  discard block
 block discarded – undo
553 553
         // register jQuery Validate and additional methods
554 554
         wp_register_script(
555 555
             'jquery-validate',
556
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
556
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js',
557 557
             array('jquery'),
558 558
             '1.15.0',
559 559
             true
560 560
         );
561 561
         wp_register_script(
562 562
             'jquery-validate-extra-methods',
563
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
563
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js',
564 564
             array('jquery', 'jquery-validate'),
565 565
             '1.15.0',
566 566
             true
@@ -578,14 +578,14 @@  discard block
 block discarded – undo
578 578
         // @link http://josscrowcroft.github.io/accounting.js/
579 579
         wp_register_script(
580 580
             'ee-accounting-core',
581
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
581
+            EE_THIRD_PARTY_URL.'accounting/accounting.js',
582 582
             array('underscore'),
583 583
             '0.3.2',
584 584
             true
585 585
         );
586 586
         wp_register_script(
587 587
             'ee-accounting',
588
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
588
+            EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js',
589 589
             array('ee-accounting-core'),
590 590
             EVENT_ESPRESSO_VERSION,
591 591
             true
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
      */
725 725
     private function registerTranslationsForHandles(array $handles_to_register)
726 726
     {
727
-        foreach($handles_to_register as $handle) {
727
+        foreach ($handles_to_register as $handle) {
728 728
             $this->i18n_registry->registerScriptI18n($handle);
729 729
         }
730 730
     }
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 2 patches
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use EventEspresso\core\services\request\RequestInterface;
9 9
 use EventEspresso\core\services\request\ResponseInterface;
10 10
 
11
-if (! defined('EVENT_ESPRESSO_VERSION')) {
11
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
12 12
     exit('No direct script access allowed');
13 13
 }
14 14
 
@@ -213,8 +213,8 @@  discard block
 block discarded – undo
213 213
     ) {
214 214
         $class = trim($class, '\\');
215 215
         $registered = false;
216
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
217
-            self::$_instance->_dependency_map[ $class ] = array();
216
+        if (empty(self::$_instance->_dependency_map[$class])) {
217
+            self::$_instance->_dependency_map[$class] = array();
218 218
         }
219 219
         // we need to make sure that any aliases used when registering a dependency
220 220
         // get resolved to the correct class name
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
             $alias = self::$_instance->getFqnForAlias($dependency);
223 223
             if (
224 224
                 $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
225
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
225
+                || ! isset(self::$_instance->_dependency_map[$class][$alias])
226 226
             ) {
227 227
                 unset($dependencies[$dependency]);
228 228
                 $dependencies[$alias] = $load_source;
@@ -235,13 +235,13 @@  discard block
 block discarded – undo
235 235
         // ie: with A = B + C, entries in B take precedence over duplicate entries in C
236 236
         // Union is way faster than array_merge() but should be used with caution...
237 237
         // especially with numerically indexed arrays
238
-        $dependencies += self::$_instance->_dependency_map[ $class ];
238
+        $dependencies += self::$_instance->_dependency_map[$class];
239 239
         // now we need to ensure that the resulting dependencies
240 240
         // array only has the entries that are required for the class
241 241
         // so first count how many dependencies were originally registered for the class
242
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
242
+        $dependency_count = count(self::$_instance->_dependency_map[$class]);
243 243
         // if that count is non-zero (meaning dependencies were already registered)
244
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
244
+        self::$_instance->_dependency_map[$class] = $dependency_count
245 245
             // then truncate the  final array to match that count
246 246
             ? array_slice($dependencies, 0, $dependency_count)
247 247
             // otherwise just take the incoming array because nothing previously existed
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
      */
260 260
     public static function register_class_loader($class_name, $loader = 'load_core')
261 261
     {
262
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
262
+        if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
263 263
             throw new DomainException(
264 264
                 esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
265 265
             );
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
             );
284 284
         }
285 285
         $class_name = self::$_instance->getFqnForAlias($class_name);
286
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
286
+        if ( ! isset(self::$_instance->_class_loaders[$class_name])) {
287 287
             self::$_instance->_class_loaders[$class_name] = $loader;
288 288
             return true;
289 289
         }
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
     public function class_loader($class_name)
369 369
     {
370 370
         // all legacy models use load_model()
371
-        if(strpos($class_name, 'EEM_') === 0){
371
+        if (strpos($class_name, 'EEM_') === 0) {
372 372
             return 'load_model';
373 373
         }
374 374
         $class_name = $this->getFqnForAlias($class_name);
@@ -766,13 +766,13 @@  discard block
 block discarded – undo
766 766
             'EE_Front_Controller'      => 'load_core',
767 767
             'EE_Module_Request_Router' => 'load_core',
768 768
             'EE_Registry'              => 'load_core',
769
-            'EE_Request'               => function () use (&$legacy_request) {
769
+            'EE_Request'               => function() use (&$legacy_request) {
770 770
                 return $legacy_request;
771 771
             },
772
-            'EventEspresso\core\services\request\Request' => function () use (&$request) {
772
+            'EventEspresso\core\services\request\Request' => function() use (&$request) {
773 773
                 return $request;
774 774
             },
775
-            'EventEspresso\core\services\request\Response' => function () use (&$response) {
775
+            'EventEspresso\core\services\request\Response' => function() use (&$response) {
776 776
                 return $response;
777 777
             },
778 778
             'EE_Base'             => 'load_core',
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
             'EE_Messages_Data_Handler_Collection'  => 'load_lib',
796 796
             'EE_Message_Template_Group_Collection' => 'load_lib',
797 797
             'EE_Payment_Method_Manager'            => 'load_lib',
798
-            'EE_Messages_Generator'                => function () {
798
+            'EE_Messages_Generator'                => function() {
799 799
                 return EE_Registry::instance()->load_lib(
800 800
                     'Messages_Generator',
801 801
                     array(),
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
                     false
804 804
                 );
805 805
             },
806
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
806
+            'EE_Messages_Template_Defaults'        => function($arguments = array()) {
807 807
                 return EE_Registry::instance()->load_lib(
808 808
                     'Messages_Template_Defaults',
809 809
                     $arguments,
@@ -812,34 +812,34 @@  discard block
 block discarded – undo
812 812
                 );
813 813
             },
814 814
             //load_helper
815
-            'EEH_Parse_Shortcodes'                 => function () {
815
+            'EEH_Parse_Shortcodes'                 => function() {
816 816
                 if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
817 817
                     return new EEH_Parse_Shortcodes();
818 818
                 }
819 819
                 return null;
820 820
             },
821
-            'EE_Template_Config'                   => function () {
821
+            'EE_Template_Config'                   => function() {
822 822
                 return EE_Config::instance()->template_settings;
823 823
             },
824
-            'EE_Currency_Config'                   => function () {
824
+            'EE_Currency_Config'                   => function() {
825 825
                 return EE_Config::instance()->currency;
826 826
             },
827
-            'EE_Registration_Config'                   => function () {
827
+            'EE_Registration_Config'                   => function() {
828 828
                 return EE_Config::instance()->registration;
829 829
             },
830
-            'EE_Core_Config'                   => function () {
830
+            'EE_Core_Config'                   => function() {
831 831
                 return EE_Config::instance()->core;
832 832
             },
833
-            'EventEspresso\core\services\loaders\Loader' => function () {
833
+            'EventEspresso\core\services\loaders\Loader' => function() {
834 834
                 return LoaderFactory::getLoader();
835 835
             },
836 836
             'EE_Network_Config' => function() {
837 837
                 return EE_Network_Config::instance();
838 838
             },
839
-            'EE_Config' => function () {
839
+            'EE_Config' => function() {
840 840
                 return EE_Config::instance();
841 841
             },
842
-            'EventEspresso\core\domain\Domain' => function () {
842
+            'EventEspresso\core\domain\Domain' => function() {
843 843
                 return DomainFactory::getEventEspressoCoreDomain();
844 844
             },
845 845
         );
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
             'EventEspresso\core\domain\DomainInterface'                           => 'EventEspresso\core\domain\Domain',
896 896
         );
897 897
         foreach ($aliases as $alias => $fqn) {
898
-            if(is_array($fqn)) {
898
+            if (is_array($fqn)) {
899 899
                 foreach ($fqn as $class => $for_class) {
900 900
                     $this->class_cache->addAlias($class, $alias, $for_class);
901 901
                 }
@@ -903,7 +903,7 @@  discard block
 block discarded – undo
903 903
             }
904 904
             $this->class_cache->addAlias($fqn, $alias);
905 905
         }
906
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
906
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
907 907
             $this->class_cache->addAlias(
908 908
                 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
909 909
                 'EventEspresso\core\services\notices\NoticeConverterInterface'
Please login to merge, or discard this patch.
Indentation   +968 added lines, -968 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 use EventEspresso\core\services\request\ResponseInterface;
10 10
 
11 11
 if (! defined('EVENT_ESPRESSO_VERSION')) {
12
-    exit('No direct script access allowed');
12
+	exit('No direct script access allowed');
13 13
 }
14 14
 
15 15
 
@@ -26,973 +26,973 @@  discard block
 block discarded – undo
26 26
 class EE_Dependency_Map
27 27
 {
28 28
 
29
-    /**
30
-     * This means that the requested class dependency is not present in the dependency map
31
-     */
32
-    const not_registered = 0;
33
-
34
-    /**
35
-     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
36
-     */
37
-    const load_new_object = 1;
38
-
39
-    /**
40
-     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
41
-     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
42
-     */
43
-    const load_from_cache = 2;
44
-
45
-    /**
46
-     * When registering a dependency,
47
-     * this indicates to keep any existing dependencies that already exist,
48
-     * and simply discard any new dependencies declared in the incoming data
49
-     */
50
-    const KEEP_EXISTING_DEPENDENCIES = 0;
51
-
52
-    /**
53
-     * When registering a dependency,
54
-     * this indicates to overwrite any existing dependencies that already exist using the incoming data
55
-     */
56
-    const OVERWRITE_DEPENDENCIES = 1;
57
-
58
-
59
-
60
-    /**
61
-     * @type EE_Dependency_Map $_instance
62
-     */
63
-    protected static $_instance;
64
-
65
-    /**
66
-     * @var ClassInterfaceCache $class_cache
67
-     */
68
-    private $class_cache;
69
-
70
-    /**
71
-     * @type RequestInterface $request
72
-     */
73
-    protected $request;
74
-
75
-    /**
76
-     * @type LegacyRequestInterface $legacy_request
77
-     */
78
-    protected $legacy_request;
79
-
80
-    /**
81
-     * @type ResponseInterface $response
82
-     */
83
-    protected $response;
84
-
85
-    /**
86
-     * @type LoaderInterface $loader
87
-     */
88
-    protected $loader;
89
-
90
-    /**
91
-     * @type array $_dependency_map
92
-     */
93
-    protected $_dependency_map = array();
94
-
95
-    /**
96
-     * @type array $_class_loaders
97
-     */
98
-    protected $_class_loaders = array();
99
-
100
-
101
-    /**
102
-     * EE_Dependency_Map constructor.
103
-     *
104
-     * @param ClassInterfaceCache $class_cache
105
-     */
106
-    protected function __construct(ClassInterfaceCache $class_cache)
107
-    {
108
-        $this->class_cache = $class_cache;
109
-        do_action('EE_Dependency_Map____construct', $this);
110
-    }
111
-
112
-
113
-    /**
114
-     * @return void
115
-     */
116
-    public function initialize()
117
-    {
118
-        $this->_register_core_dependencies();
119
-        $this->_register_core_class_loaders();
120
-        $this->_register_core_aliases();
121
-    }
122
-
123
-
124
-    /**
125
-     * @singleton method used to instantiate class object
126
-     * @param ClassInterfaceCache|null $class_cache
127
-     * @return EE_Dependency_Map
128
-     */
129
-    public static function instance(ClassInterfaceCache $class_cache = null) {
130
-        // check if class object is instantiated, and instantiated properly
131
-        if (
132
-            ! self::$_instance instanceof EE_Dependency_Map
133
-            && $class_cache instanceof ClassInterfaceCache
134
-        ) {
135
-            self::$_instance = new EE_Dependency_Map($class_cache);
136
-        }
137
-        return self::$_instance;
138
-    }
139
-
140
-
141
-    /**
142
-     * @param RequestInterface $request
143
-     */
144
-    public function setRequest(RequestInterface $request)
145
-    {
146
-        $this->request = $request;
147
-    }
148
-
149
-
150
-    /**
151
-     * @param LegacyRequestInterface $legacy_request
152
-     */
153
-    public function setLegacyRequest(LegacyRequestInterface $legacy_request)
154
-    {
155
-        $this->legacy_request = $legacy_request;
156
-    }
157
-
158
-
159
-    /**
160
-     * @param ResponseInterface $response
161
-     */
162
-    public function setResponse(ResponseInterface $response)
163
-    {
164
-        $this->response = $response;
165
-    }
166
-
167
-
168
-
169
-    /**
170
-     * @param LoaderInterface $loader
171
-     */
172
-    public function setLoader(LoaderInterface $loader)
173
-    {
174
-        $this->loader = $loader;
175
-    }
176
-
177
-
178
-
179
-    /**
180
-     * @param string $class
181
-     * @param array  $dependencies
182
-     * @param int    $overwrite
183
-     * @return bool
184
-     */
185
-    public static function register_dependencies(
186
-        $class,
187
-        array $dependencies,
188
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
189
-    ) {
190
-        return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
191
-    }
192
-
193
-
194
-
195
-    /**
196
-     * Assigns an array of class names and corresponding load sources (new or cached)
197
-     * to the class specified by the first parameter.
198
-     * IMPORTANT !!!
199
-     * The order of elements in the incoming $dependencies array MUST match
200
-     * the order of the constructor parameters for the class in question.
201
-     * This is especially important when overriding any existing dependencies that are registered.
202
-     * the third parameter controls whether any duplicate dependencies are overwritten or not.
203
-     *
204
-     * @param string $class
205
-     * @param array  $dependencies
206
-     * @param int    $overwrite
207
-     * @return bool
208
-     */
209
-    public function registerDependencies(
210
-        $class,
211
-        array $dependencies,
212
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
213
-    ) {
214
-        $class = trim($class, '\\');
215
-        $registered = false;
216
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
217
-            self::$_instance->_dependency_map[ $class ] = array();
218
-        }
219
-        // we need to make sure that any aliases used when registering a dependency
220
-        // get resolved to the correct class name
221
-        foreach ($dependencies as $dependency => $load_source) {
222
-            $alias = self::$_instance->getFqnForAlias($dependency);
223
-            if (
224
-                $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
225
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
226
-            ) {
227
-                unset($dependencies[$dependency]);
228
-                $dependencies[$alias] = $load_source;
229
-                $registered = true;
230
-            }
231
-        }
232
-        // now add our two lists of dependencies together.
233
-        // using Union (+=) favours the arrays in precedence from left to right,
234
-        // so $dependencies is NOT overwritten because it is listed first
235
-        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
236
-        // Union is way faster than array_merge() but should be used with caution...
237
-        // especially with numerically indexed arrays
238
-        $dependencies += self::$_instance->_dependency_map[ $class ];
239
-        // now we need to ensure that the resulting dependencies
240
-        // array only has the entries that are required for the class
241
-        // so first count how many dependencies were originally registered for the class
242
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
243
-        // if that count is non-zero (meaning dependencies were already registered)
244
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
245
-            // then truncate the  final array to match that count
246
-            ? array_slice($dependencies, 0, $dependency_count)
247
-            // otherwise just take the incoming array because nothing previously existed
248
-            : $dependencies;
249
-        return $registered;
250
-    }
251
-
252
-
253
-
254
-    /**
255
-     * @param string $class_name
256
-     * @param string $loader
257
-     * @return bool
258
-     * @throws DomainException
259
-     */
260
-    public static function register_class_loader($class_name, $loader = 'load_core')
261
-    {
262
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
263
-            throw new DomainException(
264
-                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
265
-            );
266
-        }
267
-        // check that loader is callable or method starts with "load_" and exists in EE_Registry
268
-        if (
269
-            ! is_callable($loader)
270
-            && (
271
-                strpos($loader, 'load_') !== 0
272
-                || ! method_exists('EE_Registry', $loader)
273
-            )
274
-        ) {
275
-            throw new DomainException(
276
-                sprintf(
277
-                    esc_html__(
278
-                        '"%1$s" is not a valid loader method on EE_Registry.',
279
-                        'event_espresso'
280
-                    ),
281
-                    $loader
282
-                )
283
-            );
284
-        }
285
-        $class_name = self::$_instance->getFqnForAlias($class_name);
286
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
287
-            self::$_instance->_class_loaders[$class_name] = $loader;
288
-            return true;
289
-        }
290
-        return false;
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     * @return array
297
-     */
298
-    public function dependency_map()
299
-    {
300
-        return $this->_dependency_map;
301
-    }
302
-
303
-
304
-
305
-    /**
306
-     * returns TRUE if dependency map contains a listing for the provided class name
307
-     *
308
-     * @param string $class_name
309
-     * @return boolean
310
-     */
311
-    public function has($class_name = '')
312
-    {
313
-        // all legacy models have the same dependencies
314
-        if (strpos($class_name, 'EEM_') === 0) {
315
-            $class_name = 'LEGACY_MODELS';
316
-        }
317
-        return isset($this->_dependency_map[$class_name]) ? true : false;
318
-    }
319
-
320
-
321
-
322
-    /**
323
-     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
324
-     *
325
-     * @param string $class_name
326
-     * @param string $dependency
327
-     * @return bool
328
-     */
329
-    public function has_dependency_for_class($class_name = '', $dependency = '')
330
-    {
331
-        // all legacy models have the same dependencies
332
-        if (strpos($class_name, 'EEM_') === 0) {
333
-            $class_name = 'LEGACY_MODELS';
334
-        }
335
-        $dependency = $this->getFqnForAlias($dependency, $class_name);
336
-        return isset($this->_dependency_map[$class_name][$dependency])
337
-            ? true
338
-            : false;
339
-    }
340
-
341
-
342
-
343
-    /**
344
-     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
345
-     *
346
-     * @param string $class_name
347
-     * @param string $dependency
348
-     * @return int
349
-     */
350
-    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
351
-    {
352
-        // all legacy models have the same dependencies
353
-        if (strpos($class_name, 'EEM_') === 0) {
354
-            $class_name = 'LEGACY_MODELS';
355
-        }
356
-        $dependency = $this->getFqnForAlias($dependency);
357
-        return $this->has_dependency_for_class($class_name, $dependency)
358
-            ? $this->_dependency_map[$class_name][$dependency]
359
-            : EE_Dependency_Map::not_registered;
360
-    }
361
-
362
-
363
-
364
-    /**
365
-     * @param string $class_name
366
-     * @return string | Closure
367
-     */
368
-    public function class_loader($class_name)
369
-    {
370
-        // all legacy models use load_model()
371
-        if(strpos($class_name, 'EEM_') === 0){
372
-            return 'load_model';
373
-        }
374
-        $class_name = $this->getFqnForAlias($class_name);
375
-        return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
376
-    }
377
-
378
-
379
-
380
-    /**
381
-     * @return array
382
-     */
383
-    public function class_loaders()
384
-    {
385
-        return $this->_class_loaders;
386
-    }
387
-
388
-
389
-
390
-    /**
391
-     * adds an alias for a classname
392
-     *
393
-     * @param string $fqcn      the class name that should be used (concrete class to replace interface)
394
-     * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
395
-     * @param string $for_class the class that has the dependency (is type hinting for the interface)
396
-     */
397
-    public function add_alias($fqcn, $alias, $for_class = '')
398
-    {
399
-        $this->class_cache->addAlias($fqcn, $alias, $for_class);
400
-    }
401
-
402
-
403
-
404
-    /**
405
-     * Returns TRUE if the provided fully qualified name IS an alias
406
-     * WHY?
407
-     * Because if a class is type hinting for a concretion,
408
-     * then why would we need to find another class to supply it?
409
-     * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
410
-     * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
411
-     * Don't go looking for some substitute.
412
-     * Whereas if a class is type hinting for an interface...
413
-     * then we need to find an actual class to use.
414
-     * So the interface IS the alias for some other FQN,
415
-     * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
416
-     * represents some other class.
417
-     *
418
-     * @param string $fqn
419
-     * @param string $for_class
420
-     * @return bool
421
-     */
422
-    public function isAlias($fqn = '', $for_class = '')
423
-    {
424
-        return $this->class_cache->isAlias($fqn, $for_class);
425
-    }
426
-
427
-
428
-
429
-    /**
430
-     * Returns a FQN for provided alias if one exists, otherwise returns the original $alias
431
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
432
-     *  for example:
433
-     *      if the following two entries were added to the _aliases array:
434
-     *          array(
435
-     *              'interface_alias'           => 'some\namespace\interface'
436
-     *              'some\namespace\interface'  => 'some\namespace\classname'
437
-     *          )
438
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
439
-     *      to load an instance of 'some\namespace\classname'
440
-     *
441
-     * @param string $alias
442
-     * @param string $for_class
443
-     * @return string
444
-     */
445
-    public function getFqnForAlias($alias = '', $for_class = '')
446
-    {
447
-        return (string) $this->class_cache->getFqnForAlias($alias, $for_class);
448
-    }
449
-
450
-
451
-
452
-    /**
453
-     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
454
-     * if one exists, or whether a new object should be generated every time the requested class is loaded.
455
-     * This is done by using the following class constants:
456
-     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
457
-     *        EE_Dependency_Map::load_new_object - generates a new object every time
458
-     */
459
-    protected function _register_core_dependencies()
460
-    {
461
-        $this->_dependency_map = array(
462
-            'EE_Request_Handler'                                                                                          => array(
463
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
464
-            ),
465
-            'EE_System'                                                                                                   => array(
466
-                'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
467
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
468
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
469
-                'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
470
-            ),
471
-            'EE_Session'                                                                                                  => array(
472
-                'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
473
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
474
-                'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
475
-                'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
476
-            ),
477
-            'EE_Cart'                                                                                                     => array(
478
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
479
-            ),
480
-            'EE_Front_Controller'                                                                                         => array(
481
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
482
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
483
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
484
-            ),
485
-            'EE_Messenger_Collection_Loader'                                                                              => array(
486
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
487
-            ),
488
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
489
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
490
-            ),
491
-            'EE_Message_Resource_Manager'                                                                                 => array(
492
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
493
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
494
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
495
-            ),
496
-            'EE_Message_Factory'                                                                                          => array(
497
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
498
-            ),
499
-            'EE_messages'                                                                                                 => array(
500
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
501
-            ),
502
-            'EE_Messages_Generator'                                                                                       => array(
503
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
504
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
505
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
506
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
507
-            ),
508
-            'EE_Messages_Processor'                                                                                       => array(
509
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
510
-            ),
511
-            'EE_Messages_Queue'                                                                                           => array(
512
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
513
-            ),
514
-            'EE_Messages_Template_Defaults'                                                                               => array(
515
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
516
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
517
-            ),
518
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
519
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
520
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
521
-            ),
522
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
523
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
524
-            ),
525
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
526
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
527
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
528
-            ),
529
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
530
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
531
-            ),
532
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
533
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
534
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
535
-            ),
536
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
537
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
538
-            ),
539
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
540
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
541
-            ),
542
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
543
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
544
-            ),
545
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
546
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
547
-            ),
548
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
549
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
550
-            ),
551
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
552
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
553
-            ),
554
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
555
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
556
-            ),
557
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
558
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
559
-            ),
560
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
561
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
562
-            ),
563
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
564
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
565
-            ),
566
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
567
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
568
-            ),
569
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
570
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
571
-            ),
572
-            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
573
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
574
-            ),
575
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
576
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
577
-            ),
578
-            'EE_Data_Migration_Class_Base'                                                                                => array(
579
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
580
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
581
-            ),
582
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
583
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
584
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
585
-            ),
586
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
587
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
588
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
589
-            ),
590
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
591
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
592
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
593
-            ),
594
-            'EE_DMS_Core_4_4_0'                                                                                           => array(
595
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
596
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
597
-            ),
598
-            'EE_DMS_Core_4_5_0'                                                                                           => array(
599
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
600
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
601
-            ),
602
-            'EE_DMS_Core_4_6_0'                                                                                           => array(
603
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
604
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
605
-            ),
606
-            'EE_DMS_Core_4_7_0'                                                                                           => array(
607
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
608
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
609
-            ),
610
-            'EE_DMS_Core_4_8_0'                                                                                           => array(
611
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
612
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
613
-            ),
614
-            'EE_DMS_Core_4_9_0'                                                                                           => array(
615
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
616
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
617
-            ),
618
-            'EventEspresso\core\services\assets\I18nRegistry' => array(
619
-                array(),
620
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
621
-            ),
622
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
623
-                'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
624
-                'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
625
-                'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache,
626
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
627
-            ),
628
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
629
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
630
-            ),
631
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
632
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
633
-            ),
634
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
635
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
636
-            ),
637
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
638
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
639
-            ),
640
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
641
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
642
-            ),
643
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
644
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
645
-            ),
646
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
647
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
648
-            ),
649
-            'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
650
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
651
-            ),
652
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'                  => array(
653
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
654
-            ),
655
-            'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
656
-                'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
657
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
658
-            ),
659
-            'EventEspresso\core\domain\values\EmailAddress'                              => array(
660
-                null,
661
-                'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
662
-            ),
663
-            'EventEspresso\core\services\orm\ModelFieldFactory' => array(
664
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
665
-            ),
666
-            'LEGACY_MODELS'                                                   => array(
667
-                null,
668
-                'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
669
-            ),
670
-            'EE_Module_Request_Router'                                               => array(
671
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
672
-            ),
673
-            'EE_Registration_Processor'                                              => array(
674
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
675
-            ),
676
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array(
677
-                null,
678
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
679
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
680
-            ),
681
-            'EventEspresso\core\services\editor\EditorBlockRegistrationManager'      => array(
682
-                'EventEspresso\core\domain\entities\editor\EditorBlockCollection' => EE_Dependency_Map::load_from_cache,
683
-                'EE_Request'                                                      => EE_Dependency_Map::load_from_cache,
684
-                'EventEspresso\core\domain\Domain'                                => EE_Dependency_Map::load_from_cache,
685
-                'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache
686
-            ),
687
-            'EE_Admin_Transactions_List_Table' => array(
688
-                null,
689
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
690
-            ),
691
-            'EventEspresso\core\services\licensing\LicenseService' => array(
692
-                'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache,
693
-                'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache
694
-            ),
695
-            'EventEspresso\core\domain\services\pue\Stats' => array(
696
-                'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
697
-                'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache,
698
-                'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache
699
-            ),
700
-            'EventEspresso\core\domain\services\pue\Config' => array(
701
-                'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
702
-                'EE_Config' => EE_Dependency_Map::load_from_cache
703
-            ),
704
-            'EventEspresso\core\domain\services\pue\StatsGatherer' => array(
705
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
706
-                'EEM_Event' => EE_Dependency_Map::load_from_cache,
707
-                'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
708
-                'EEM_Ticket' => EE_Dependency_Map::load_from_cache,
709
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache,
710
-                'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
711
-                'EE_Config' => EE_Dependency_Map::load_from_cache
712
-            ),
713
-            'EventEspresso\core\domain\services\admin\ExitModal' => array(
714
-                'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache
715
-            ),
716
-            'EventEspresso\core\domain\services\admin\PluginUpsells' => array(
717
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
718
-            ),
719
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array(
720
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
721
-                'EE_Session'             => EE_Dependency_Map::load_from_cache,
722
-            ),
723
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array(
724
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
725
-            ),
726
-            'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array(
727
-                'EE_Core_Config' => EE_Dependency_Map::load_from_cache,
728
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
729
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
730
-                'EEM_Ticket' => EE_Dependency_Map::load_from_cache,
731
-                'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache,
732
-            ),
733
-            'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array(
734
-                'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
735
-            ),
736
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array(
737
-                'EE_Core_Config' => EE_Dependency_Map::load_from_cache,
738
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
739
-            ),
740
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'   => array(
741
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
742
-            ),
743
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'   => array(
744
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
745
-            ),
746
-            'EE_CPT_Strategy'   => array(
747
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
748
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
749
-            ),
750
-            'EventEspresso\core\services\loaders\ObjectIdentifier' => array(
751
-                'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache,
752
-            ),
753
-        );
754
-    }
755
-
756
-
757
-    /**
758
-     * Registers how core classes are loaded.
759
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
760
-     *        'EE_Request_Handler' => 'load_core'
761
-     *        'EE_Messages_Queue'  => 'load_lib'
762
-     *        'EEH_Debug_Tools'    => 'load_helper'
763
-     * or, if greater control is required, by providing a custom closure. For example:
764
-     *        'Some_Class' => function () {
765
-     *            return new Some_Class();
766
-     *        },
767
-     * This is required for instantiating dependencies
768
-     * where an interface has been type hinted in a class constructor. For example:
769
-     *        'Required_Interface' => function () {
770
-     *            return new A_Class_That_Implements_Required_Interface();
771
-     *        },
772
-     *
773
-     */
774
-    protected function _register_core_class_loaders()
775
-    {
776
-        //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
777
-        //be used in a closure.
778
-        $request = &$this->request;
779
-        $response = &$this->response;
780
-        $legacy_request = &$this->legacy_request;
781
-        // $loader = &$this->loader;
782
-        $this->_class_loaders = array(
783
-            //load_core
784
-            'EE_Capabilities'          => 'load_core',
785
-            'EE_Encryption'            => 'load_core',
786
-            'EE_Front_Controller'      => 'load_core',
787
-            'EE_Module_Request_Router' => 'load_core',
788
-            'EE_Registry'              => 'load_core',
789
-            'EE_Request'               => function () use (&$legacy_request) {
790
-                return $legacy_request;
791
-            },
792
-            'EventEspresso\core\services\request\Request' => function () use (&$request) {
793
-                return $request;
794
-            },
795
-            'EventEspresso\core\services\request\Response' => function () use (&$response) {
796
-                return $response;
797
-            },
798
-            'EE_Base'             => 'load_core',
799
-            'EE_Request_Handler'       => 'load_core',
800
-            'EE_Session'               => 'load_core',
801
-            'EE_Cron_Tasks'            => 'load_core',
802
-            'EE_System'                => 'load_core',
803
-            'EE_Maintenance_Mode'      => 'load_core',
804
-            'EE_Register_CPTs'         => 'load_core',
805
-            'EE_Admin'                 => 'load_core',
806
-            'EE_CPT_Strategy'          => 'load_core',
807
-            //load_lib
808
-            'EE_Message_Resource_Manager'          => 'load_lib',
809
-            'EE_Message_Type_Collection'           => 'load_lib',
810
-            'EE_Message_Type_Collection_Loader'    => 'load_lib',
811
-            'EE_Messenger_Collection'              => 'load_lib',
812
-            'EE_Messenger_Collection_Loader'       => 'load_lib',
813
-            'EE_Messages_Processor'                => 'load_lib',
814
-            'EE_Message_Repository'                => 'load_lib',
815
-            'EE_Messages_Queue'                    => 'load_lib',
816
-            'EE_Messages_Data_Handler_Collection'  => 'load_lib',
817
-            'EE_Message_Template_Group_Collection' => 'load_lib',
818
-            'EE_Payment_Method_Manager'            => 'load_lib',
819
-            'EE_Messages_Generator'                => function () {
820
-                return EE_Registry::instance()->load_lib(
821
-                    'Messages_Generator',
822
-                    array(),
823
-                    false,
824
-                    false
825
-                );
826
-            },
827
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
828
-                return EE_Registry::instance()->load_lib(
829
-                    'Messages_Template_Defaults',
830
-                    $arguments,
831
-                    false,
832
-                    false
833
-                );
834
-            },
835
-            //load_helper
836
-            'EEH_Parse_Shortcodes'                 => function () {
837
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
838
-                    return new EEH_Parse_Shortcodes();
839
-                }
840
-                return null;
841
-            },
842
-            'EE_Template_Config'                   => function () {
843
-                return EE_Config::instance()->template_settings;
844
-            },
845
-            'EE_Currency_Config'                   => function () {
846
-                return EE_Config::instance()->currency;
847
-            },
848
-            'EE_Registration_Config'                   => function () {
849
-                return EE_Config::instance()->registration;
850
-            },
851
-            'EE_Core_Config'                   => function () {
852
-                return EE_Config::instance()->core;
853
-            },
854
-            'EventEspresso\core\services\loaders\Loader' => function () {
855
-                return LoaderFactory::getLoader();
856
-            },
857
-            'EE_Network_Config' => function() {
858
-                return EE_Network_Config::instance();
859
-            },
860
-            'EE_Config' => function () {
861
-                return EE_Config::instance();
862
-            },
863
-            'EventEspresso\core\domain\Domain' => function () {
864
-                return DomainFactory::getEventEspressoCoreDomain();
865
-            },
866
-        );
867
-    }
868
-
869
-
870
-
871
-
872
-    /**
873
-     * can be used for supplying alternate names for classes,
874
-     * or for connecting interface names to instantiable classes
875
-     */
876
-    protected function _register_core_aliases()
877
-    {
878
-        $aliases = array(
879
-            'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
880
-            'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
881
-            'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
882
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
883
-            'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
884
-            'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
885
-            'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
886
-            'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
887
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
888
-            'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
889
-            'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
890
-            'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
891
-            'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
892
-            'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
893
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
894
-            'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
895
-            'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
896
-            'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
897
-            'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
898
-            'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
899
-            'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
900
-            'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
901
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
902
-            'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
903
-            'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
904
-            'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
905
-            'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
906
-            'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
907
-            'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
908
-            'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
909
-            'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
910
-            'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
911
-            'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
912
-            'NoticesContainerInterface'                                           => 'EventEspresso\core\services\notices\NoticesContainerInterface',
913
-            'EventEspresso\core\services\notices\NoticesContainerInterface'       => 'EventEspresso\core\services\notices\NoticesContainer',
914
-            'EventEspresso\core\services\request\RequestInterface'                => 'EventEspresso\core\services\request\Request',
915
-            'EventEspresso\core\services\request\ResponseInterface'               => 'EventEspresso\core\services\request\Response',
916
-            'EventEspresso\core\domain\DomainInterface'                           => 'EventEspresso\core\domain\Domain',
917
-        );
918
-        foreach ($aliases as $alias => $fqn) {
919
-            if(is_array($fqn)) {
920
-                foreach ($fqn as $class => $for_class) {
921
-                    $this->class_cache->addAlias($class, $alias, $for_class);
922
-                }
923
-                continue;
924
-            }
925
-            $this->class_cache->addAlias($fqn, $alias);
926
-        }
927
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
928
-            $this->class_cache->addAlias(
929
-                'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
930
-                'EventEspresso\core\services\notices\NoticeConverterInterface'
931
-            );
932
-        }
933
-    }
934
-
935
-
936
-
937
-    /**
938
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
939
-     * request Primarily used by unit tests.
940
-     */
941
-    public function reset()
942
-    {
943
-        $this->_register_core_class_loaders();
944
-        $this->_register_core_dependencies();
945
-    }
946
-
947
-
948
-    /**
949
-     * PLZ NOTE: a better name for this method would be is_alias()
950
-     * because it returns TRUE if the provided fully qualified name IS an alias
951
-     * WHY?
952
-     * Because if a class is type hinting for a concretion,
953
-     * then why would we need to find another class to supply it?
954
-     * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
955
-     * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
956
-     * Don't go looking for some substitute.
957
-     * Whereas if a class is type hinting for an interface...
958
-     * then we need to find an actual class to use.
959
-     * So the interface IS the alias for some other FQN,
960
-     * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
961
-     * represents some other class.
962
-     *
963
-     * @deprecated $VID:$
964
-     * @param string $fqn
965
-     * @param string $for_class
966
-     * @return bool
967
-     */
968
-    public function has_alias($fqn = '', $for_class = '')
969
-    {
970
-        return $this->isAlias($fqn, $for_class);
971
-    }
972
-
973
-
974
-    /**
975
-     * PLZ NOTE: a better name for this method would be get_fqn_for_alias()
976
-     * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias
977
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
978
-     *  for example:
979
-     *      if the following two entries were added to the _aliases array:
980
-     *          array(
981
-     *              'interface_alias'           => 'some\namespace\interface'
982
-     *              'some\namespace\interface'  => 'some\namespace\classname'
983
-     *          )
984
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
985
-     *      to load an instance of 'some\namespace\classname'
986
-     *
987
-     * @deprecated $VID:$
988
-     * @param string $alias
989
-     * @param string $for_class
990
-     * @return string
991
-     */
992
-    public function get_alias($alias = '', $for_class = '')
993
-    {
994
-        return $this->getFqnForAlias($alias, $for_class);
995
-    }
29
+	/**
30
+	 * This means that the requested class dependency is not present in the dependency map
31
+	 */
32
+	const not_registered = 0;
33
+
34
+	/**
35
+	 * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
36
+	 */
37
+	const load_new_object = 1;
38
+
39
+	/**
40
+	 * This instructs class loaders to return a previously instantiated and cached object for the requested class.
41
+	 * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
42
+	 */
43
+	const load_from_cache = 2;
44
+
45
+	/**
46
+	 * When registering a dependency,
47
+	 * this indicates to keep any existing dependencies that already exist,
48
+	 * and simply discard any new dependencies declared in the incoming data
49
+	 */
50
+	const KEEP_EXISTING_DEPENDENCIES = 0;
51
+
52
+	/**
53
+	 * When registering a dependency,
54
+	 * this indicates to overwrite any existing dependencies that already exist using the incoming data
55
+	 */
56
+	const OVERWRITE_DEPENDENCIES = 1;
57
+
58
+
59
+
60
+	/**
61
+	 * @type EE_Dependency_Map $_instance
62
+	 */
63
+	protected static $_instance;
64
+
65
+	/**
66
+	 * @var ClassInterfaceCache $class_cache
67
+	 */
68
+	private $class_cache;
69
+
70
+	/**
71
+	 * @type RequestInterface $request
72
+	 */
73
+	protected $request;
74
+
75
+	/**
76
+	 * @type LegacyRequestInterface $legacy_request
77
+	 */
78
+	protected $legacy_request;
79
+
80
+	/**
81
+	 * @type ResponseInterface $response
82
+	 */
83
+	protected $response;
84
+
85
+	/**
86
+	 * @type LoaderInterface $loader
87
+	 */
88
+	protected $loader;
89
+
90
+	/**
91
+	 * @type array $_dependency_map
92
+	 */
93
+	protected $_dependency_map = array();
94
+
95
+	/**
96
+	 * @type array $_class_loaders
97
+	 */
98
+	protected $_class_loaders = array();
99
+
100
+
101
+	/**
102
+	 * EE_Dependency_Map constructor.
103
+	 *
104
+	 * @param ClassInterfaceCache $class_cache
105
+	 */
106
+	protected function __construct(ClassInterfaceCache $class_cache)
107
+	{
108
+		$this->class_cache = $class_cache;
109
+		do_action('EE_Dependency_Map____construct', $this);
110
+	}
111
+
112
+
113
+	/**
114
+	 * @return void
115
+	 */
116
+	public function initialize()
117
+	{
118
+		$this->_register_core_dependencies();
119
+		$this->_register_core_class_loaders();
120
+		$this->_register_core_aliases();
121
+	}
122
+
123
+
124
+	/**
125
+	 * @singleton method used to instantiate class object
126
+	 * @param ClassInterfaceCache|null $class_cache
127
+	 * @return EE_Dependency_Map
128
+	 */
129
+	public static function instance(ClassInterfaceCache $class_cache = null) {
130
+		// check if class object is instantiated, and instantiated properly
131
+		if (
132
+			! self::$_instance instanceof EE_Dependency_Map
133
+			&& $class_cache instanceof ClassInterfaceCache
134
+		) {
135
+			self::$_instance = new EE_Dependency_Map($class_cache);
136
+		}
137
+		return self::$_instance;
138
+	}
139
+
140
+
141
+	/**
142
+	 * @param RequestInterface $request
143
+	 */
144
+	public function setRequest(RequestInterface $request)
145
+	{
146
+		$this->request = $request;
147
+	}
148
+
149
+
150
+	/**
151
+	 * @param LegacyRequestInterface $legacy_request
152
+	 */
153
+	public function setLegacyRequest(LegacyRequestInterface $legacy_request)
154
+	{
155
+		$this->legacy_request = $legacy_request;
156
+	}
157
+
158
+
159
+	/**
160
+	 * @param ResponseInterface $response
161
+	 */
162
+	public function setResponse(ResponseInterface $response)
163
+	{
164
+		$this->response = $response;
165
+	}
166
+
167
+
168
+
169
+	/**
170
+	 * @param LoaderInterface $loader
171
+	 */
172
+	public function setLoader(LoaderInterface $loader)
173
+	{
174
+		$this->loader = $loader;
175
+	}
176
+
177
+
178
+
179
+	/**
180
+	 * @param string $class
181
+	 * @param array  $dependencies
182
+	 * @param int    $overwrite
183
+	 * @return bool
184
+	 */
185
+	public static function register_dependencies(
186
+		$class,
187
+		array $dependencies,
188
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
189
+	) {
190
+		return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
191
+	}
192
+
193
+
194
+
195
+	/**
196
+	 * Assigns an array of class names and corresponding load sources (new or cached)
197
+	 * to the class specified by the first parameter.
198
+	 * IMPORTANT !!!
199
+	 * The order of elements in the incoming $dependencies array MUST match
200
+	 * the order of the constructor parameters for the class in question.
201
+	 * This is especially important when overriding any existing dependencies that are registered.
202
+	 * the third parameter controls whether any duplicate dependencies are overwritten or not.
203
+	 *
204
+	 * @param string $class
205
+	 * @param array  $dependencies
206
+	 * @param int    $overwrite
207
+	 * @return bool
208
+	 */
209
+	public function registerDependencies(
210
+		$class,
211
+		array $dependencies,
212
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
213
+	) {
214
+		$class = trim($class, '\\');
215
+		$registered = false;
216
+		if (empty(self::$_instance->_dependency_map[ $class ])) {
217
+			self::$_instance->_dependency_map[ $class ] = array();
218
+		}
219
+		// we need to make sure that any aliases used when registering a dependency
220
+		// get resolved to the correct class name
221
+		foreach ($dependencies as $dependency => $load_source) {
222
+			$alias = self::$_instance->getFqnForAlias($dependency);
223
+			if (
224
+				$overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
225
+				|| ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
226
+			) {
227
+				unset($dependencies[$dependency]);
228
+				$dependencies[$alias] = $load_source;
229
+				$registered = true;
230
+			}
231
+		}
232
+		// now add our two lists of dependencies together.
233
+		// using Union (+=) favours the arrays in precedence from left to right,
234
+		// so $dependencies is NOT overwritten because it is listed first
235
+		// ie: with A = B + C, entries in B take precedence over duplicate entries in C
236
+		// Union is way faster than array_merge() but should be used with caution...
237
+		// especially with numerically indexed arrays
238
+		$dependencies += self::$_instance->_dependency_map[ $class ];
239
+		// now we need to ensure that the resulting dependencies
240
+		// array only has the entries that are required for the class
241
+		// so first count how many dependencies were originally registered for the class
242
+		$dependency_count = count(self::$_instance->_dependency_map[ $class ]);
243
+		// if that count is non-zero (meaning dependencies were already registered)
244
+		self::$_instance->_dependency_map[ $class ] = $dependency_count
245
+			// then truncate the  final array to match that count
246
+			? array_slice($dependencies, 0, $dependency_count)
247
+			// otherwise just take the incoming array because nothing previously existed
248
+			: $dependencies;
249
+		return $registered;
250
+	}
251
+
252
+
253
+
254
+	/**
255
+	 * @param string $class_name
256
+	 * @param string $loader
257
+	 * @return bool
258
+	 * @throws DomainException
259
+	 */
260
+	public static function register_class_loader($class_name, $loader = 'load_core')
261
+	{
262
+		if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
263
+			throw new DomainException(
264
+				esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
265
+			);
266
+		}
267
+		// check that loader is callable or method starts with "load_" and exists in EE_Registry
268
+		if (
269
+			! is_callable($loader)
270
+			&& (
271
+				strpos($loader, 'load_') !== 0
272
+				|| ! method_exists('EE_Registry', $loader)
273
+			)
274
+		) {
275
+			throw new DomainException(
276
+				sprintf(
277
+					esc_html__(
278
+						'"%1$s" is not a valid loader method on EE_Registry.',
279
+						'event_espresso'
280
+					),
281
+					$loader
282
+				)
283
+			);
284
+		}
285
+		$class_name = self::$_instance->getFqnForAlias($class_name);
286
+		if (! isset(self::$_instance->_class_loaders[$class_name])) {
287
+			self::$_instance->_class_loaders[$class_name] = $loader;
288
+			return true;
289
+		}
290
+		return false;
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 * @return array
297
+	 */
298
+	public function dependency_map()
299
+	{
300
+		return $this->_dependency_map;
301
+	}
302
+
303
+
304
+
305
+	/**
306
+	 * returns TRUE if dependency map contains a listing for the provided class name
307
+	 *
308
+	 * @param string $class_name
309
+	 * @return boolean
310
+	 */
311
+	public function has($class_name = '')
312
+	{
313
+		// all legacy models have the same dependencies
314
+		if (strpos($class_name, 'EEM_') === 0) {
315
+			$class_name = 'LEGACY_MODELS';
316
+		}
317
+		return isset($this->_dependency_map[$class_name]) ? true : false;
318
+	}
319
+
320
+
321
+
322
+	/**
323
+	 * returns TRUE if dependency map contains a listing for the provided class name AND dependency
324
+	 *
325
+	 * @param string $class_name
326
+	 * @param string $dependency
327
+	 * @return bool
328
+	 */
329
+	public function has_dependency_for_class($class_name = '', $dependency = '')
330
+	{
331
+		// all legacy models have the same dependencies
332
+		if (strpos($class_name, 'EEM_') === 0) {
333
+			$class_name = 'LEGACY_MODELS';
334
+		}
335
+		$dependency = $this->getFqnForAlias($dependency, $class_name);
336
+		return isset($this->_dependency_map[$class_name][$dependency])
337
+			? true
338
+			: false;
339
+	}
340
+
341
+
342
+
343
+	/**
344
+	 * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
345
+	 *
346
+	 * @param string $class_name
347
+	 * @param string $dependency
348
+	 * @return int
349
+	 */
350
+	public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
351
+	{
352
+		// all legacy models have the same dependencies
353
+		if (strpos($class_name, 'EEM_') === 0) {
354
+			$class_name = 'LEGACY_MODELS';
355
+		}
356
+		$dependency = $this->getFqnForAlias($dependency);
357
+		return $this->has_dependency_for_class($class_name, $dependency)
358
+			? $this->_dependency_map[$class_name][$dependency]
359
+			: EE_Dependency_Map::not_registered;
360
+	}
361
+
362
+
363
+
364
+	/**
365
+	 * @param string $class_name
366
+	 * @return string | Closure
367
+	 */
368
+	public function class_loader($class_name)
369
+	{
370
+		// all legacy models use load_model()
371
+		if(strpos($class_name, 'EEM_') === 0){
372
+			return 'load_model';
373
+		}
374
+		$class_name = $this->getFqnForAlias($class_name);
375
+		return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
376
+	}
377
+
378
+
379
+
380
+	/**
381
+	 * @return array
382
+	 */
383
+	public function class_loaders()
384
+	{
385
+		return $this->_class_loaders;
386
+	}
387
+
388
+
389
+
390
+	/**
391
+	 * adds an alias for a classname
392
+	 *
393
+	 * @param string $fqcn      the class name that should be used (concrete class to replace interface)
394
+	 * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
395
+	 * @param string $for_class the class that has the dependency (is type hinting for the interface)
396
+	 */
397
+	public function add_alias($fqcn, $alias, $for_class = '')
398
+	{
399
+		$this->class_cache->addAlias($fqcn, $alias, $for_class);
400
+	}
401
+
402
+
403
+
404
+	/**
405
+	 * Returns TRUE if the provided fully qualified name IS an alias
406
+	 * WHY?
407
+	 * Because if a class is type hinting for a concretion,
408
+	 * then why would we need to find another class to supply it?
409
+	 * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
410
+	 * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
411
+	 * Don't go looking for some substitute.
412
+	 * Whereas if a class is type hinting for an interface...
413
+	 * then we need to find an actual class to use.
414
+	 * So the interface IS the alias for some other FQN,
415
+	 * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
416
+	 * represents some other class.
417
+	 *
418
+	 * @param string $fqn
419
+	 * @param string $for_class
420
+	 * @return bool
421
+	 */
422
+	public function isAlias($fqn = '', $for_class = '')
423
+	{
424
+		return $this->class_cache->isAlias($fqn, $for_class);
425
+	}
426
+
427
+
428
+
429
+	/**
430
+	 * Returns a FQN for provided alias if one exists, otherwise returns the original $alias
431
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
432
+	 *  for example:
433
+	 *      if the following two entries were added to the _aliases array:
434
+	 *          array(
435
+	 *              'interface_alias'           => 'some\namespace\interface'
436
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
437
+	 *          )
438
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
439
+	 *      to load an instance of 'some\namespace\classname'
440
+	 *
441
+	 * @param string $alias
442
+	 * @param string $for_class
443
+	 * @return string
444
+	 */
445
+	public function getFqnForAlias($alias = '', $for_class = '')
446
+	{
447
+		return (string) $this->class_cache->getFqnForAlias($alias, $for_class);
448
+	}
449
+
450
+
451
+
452
+	/**
453
+	 * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
454
+	 * if one exists, or whether a new object should be generated every time the requested class is loaded.
455
+	 * This is done by using the following class constants:
456
+	 *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
457
+	 *        EE_Dependency_Map::load_new_object - generates a new object every time
458
+	 */
459
+	protected function _register_core_dependencies()
460
+	{
461
+		$this->_dependency_map = array(
462
+			'EE_Request_Handler'                                                                                          => array(
463
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
464
+			),
465
+			'EE_System'                                                                                                   => array(
466
+				'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
467
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
468
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
469
+				'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
470
+			),
471
+			'EE_Session'                                                                                                  => array(
472
+				'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
473
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
474
+				'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
475
+				'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
476
+			),
477
+			'EE_Cart'                                                                                                     => array(
478
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
479
+			),
480
+			'EE_Front_Controller'                                                                                         => array(
481
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
482
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
483
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
484
+			),
485
+			'EE_Messenger_Collection_Loader'                                                                              => array(
486
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
487
+			),
488
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
489
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
490
+			),
491
+			'EE_Message_Resource_Manager'                                                                                 => array(
492
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
493
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
494
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
495
+			),
496
+			'EE_Message_Factory'                                                                                          => array(
497
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
498
+			),
499
+			'EE_messages'                                                                                                 => array(
500
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
501
+			),
502
+			'EE_Messages_Generator'                                                                                       => array(
503
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
504
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
505
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
506
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
507
+			),
508
+			'EE_Messages_Processor'                                                                                       => array(
509
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
510
+			),
511
+			'EE_Messages_Queue'                                                                                           => array(
512
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
513
+			),
514
+			'EE_Messages_Template_Defaults'                                                                               => array(
515
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
516
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
517
+			),
518
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
519
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
520
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
521
+			),
522
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
523
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
524
+			),
525
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
526
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
527
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
528
+			),
529
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
530
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
531
+			),
532
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
533
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
534
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
535
+			),
536
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
537
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
538
+			),
539
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
540
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
541
+			),
542
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
543
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
544
+			),
545
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
546
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
547
+			),
548
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
549
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
550
+			),
551
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
552
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
553
+			),
554
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
555
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
556
+			),
557
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
558
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
559
+			),
560
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
561
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
562
+			),
563
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
564
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
565
+			),
566
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
567
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
568
+			),
569
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
570
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
571
+			),
572
+			'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
573
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
574
+			),
575
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
576
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
577
+			),
578
+			'EE_Data_Migration_Class_Base'                                                                                => array(
579
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
580
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
581
+			),
582
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
583
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
584
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
585
+			),
586
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
587
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
588
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
589
+			),
590
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
591
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
592
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
593
+			),
594
+			'EE_DMS_Core_4_4_0'                                                                                           => array(
595
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
596
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
597
+			),
598
+			'EE_DMS_Core_4_5_0'                                                                                           => array(
599
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
600
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
601
+			),
602
+			'EE_DMS_Core_4_6_0'                                                                                           => array(
603
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
604
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
605
+			),
606
+			'EE_DMS_Core_4_7_0'                                                                                           => array(
607
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
608
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
609
+			),
610
+			'EE_DMS_Core_4_8_0'                                                                                           => array(
611
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
612
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
613
+			),
614
+			'EE_DMS_Core_4_9_0'                                                                                           => array(
615
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
616
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
617
+			),
618
+			'EventEspresso\core\services\assets\I18nRegistry' => array(
619
+				array(),
620
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
621
+			),
622
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
623
+				'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
624
+				'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
625
+				'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache,
626
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
627
+			),
628
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
629
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
630
+			),
631
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
632
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
633
+			),
634
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
635
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
636
+			),
637
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
638
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
639
+			),
640
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
641
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
642
+			),
643
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
644
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
645
+			),
646
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
647
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
648
+			),
649
+			'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
650
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
651
+			),
652
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'                  => array(
653
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
654
+			),
655
+			'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
656
+				'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
657
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
658
+			),
659
+			'EventEspresso\core\domain\values\EmailAddress'                              => array(
660
+				null,
661
+				'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
662
+			),
663
+			'EventEspresso\core\services\orm\ModelFieldFactory' => array(
664
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
665
+			),
666
+			'LEGACY_MODELS'                                                   => array(
667
+				null,
668
+				'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
669
+			),
670
+			'EE_Module_Request_Router'                                               => array(
671
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
672
+			),
673
+			'EE_Registration_Processor'                                              => array(
674
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
675
+			),
676
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array(
677
+				null,
678
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
679
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
680
+			),
681
+			'EventEspresso\core\services\editor\EditorBlockRegistrationManager'      => array(
682
+				'EventEspresso\core\domain\entities\editor\EditorBlockCollection' => EE_Dependency_Map::load_from_cache,
683
+				'EE_Request'                                                      => EE_Dependency_Map::load_from_cache,
684
+				'EventEspresso\core\domain\Domain'                                => EE_Dependency_Map::load_from_cache,
685
+				'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache
686
+			),
687
+			'EE_Admin_Transactions_List_Table' => array(
688
+				null,
689
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
690
+			),
691
+			'EventEspresso\core\services\licensing\LicenseService' => array(
692
+				'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache,
693
+				'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache
694
+			),
695
+			'EventEspresso\core\domain\services\pue\Stats' => array(
696
+				'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
697
+				'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache,
698
+				'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache
699
+			),
700
+			'EventEspresso\core\domain\services\pue\Config' => array(
701
+				'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
702
+				'EE_Config' => EE_Dependency_Map::load_from_cache
703
+			),
704
+			'EventEspresso\core\domain\services\pue\StatsGatherer' => array(
705
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
706
+				'EEM_Event' => EE_Dependency_Map::load_from_cache,
707
+				'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
708
+				'EEM_Ticket' => EE_Dependency_Map::load_from_cache,
709
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache,
710
+				'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
711
+				'EE_Config' => EE_Dependency_Map::load_from_cache
712
+			),
713
+			'EventEspresso\core\domain\services\admin\ExitModal' => array(
714
+				'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache
715
+			),
716
+			'EventEspresso\core\domain\services\admin\PluginUpsells' => array(
717
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
718
+			),
719
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array(
720
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
721
+				'EE_Session'             => EE_Dependency_Map::load_from_cache,
722
+			),
723
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array(
724
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
725
+			),
726
+			'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array(
727
+				'EE_Core_Config' => EE_Dependency_Map::load_from_cache,
728
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
729
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
730
+				'EEM_Ticket' => EE_Dependency_Map::load_from_cache,
731
+				'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache,
732
+			),
733
+			'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array(
734
+				'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
735
+			),
736
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array(
737
+				'EE_Core_Config' => EE_Dependency_Map::load_from_cache,
738
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
739
+			),
740
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'   => array(
741
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
742
+			),
743
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'   => array(
744
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
745
+			),
746
+			'EE_CPT_Strategy'   => array(
747
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
748
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
749
+			),
750
+			'EventEspresso\core\services\loaders\ObjectIdentifier' => array(
751
+				'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache,
752
+			),
753
+		);
754
+	}
755
+
756
+
757
+	/**
758
+	 * Registers how core classes are loaded.
759
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
760
+	 *        'EE_Request_Handler' => 'load_core'
761
+	 *        'EE_Messages_Queue'  => 'load_lib'
762
+	 *        'EEH_Debug_Tools'    => 'load_helper'
763
+	 * or, if greater control is required, by providing a custom closure. For example:
764
+	 *        'Some_Class' => function () {
765
+	 *            return new Some_Class();
766
+	 *        },
767
+	 * This is required for instantiating dependencies
768
+	 * where an interface has been type hinted in a class constructor. For example:
769
+	 *        'Required_Interface' => function () {
770
+	 *            return new A_Class_That_Implements_Required_Interface();
771
+	 *        },
772
+	 *
773
+	 */
774
+	protected function _register_core_class_loaders()
775
+	{
776
+		//for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
777
+		//be used in a closure.
778
+		$request = &$this->request;
779
+		$response = &$this->response;
780
+		$legacy_request = &$this->legacy_request;
781
+		// $loader = &$this->loader;
782
+		$this->_class_loaders = array(
783
+			//load_core
784
+			'EE_Capabilities'          => 'load_core',
785
+			'EE_Encryption'            => 'load_core',
786
+			'EE_Front_Controller'      => 'load_core',
787
+			'EE_Module_Request_Router' => 'load_core',
788
+			'EE_Registry'              => 'load_core',
789
+			'EE_Request'               => function () use (&$legacy_request) {
790
+				return $legacy_request;
791
+			},
792
+			'EventEspresso\core\services\request\Request' => function () use (&$request) {
793
+				return $request;
794
+			},
795
+			'EventEspresso\core\services\request\Response' => function () use (&$response) {
796
+				return $response;
797
+			},
798
+			'EE_Base'             => 'load_core',
799
+			'EE_Request_Handler'       => 'load_core',
800
+			'EE_Session'               => 'load_core',
801
+			'EE_Cron_Tasks'            => 'load_core',
802
+			'EE_System'                => 'load_core',
803
+			'EE_Maintenance_Mode'      => 'load_core',
804
+			'EE_Register_CPTs'         => 'load_core',
805
+			'EE_Admin'                 => 'load_core',
806
+			'EE_CPT_Strategy'          => 'load_core',
807
+			//load_lib
808
+			'EE_Message_Resource_Manager'          => 'load_lib',
809
+			'EE_Message_Type_Collection'           => 'load_lib',
810
+			'EE_Message_Type_Collection_Loader'    => 'load_lib',
811
+			'EE_Messenger_Collection'              => 'load_lib',
812
+			'EE_Messenger_Collection_Loader'       => 'load_lib',
813
+			'EE_Messages_Processor'                => 'load_lib',
814
+			'EE_Message_Repository'                => 'load_lib',
815
+			'EE_Messages_Queue'                    => 'load_lib',
816
+			'EE_Messages_Data_Handler_Collection'  => 'load_lib',
817
+			'EE_Message_Template_Group_Collection' => 'load_lib',
818
+			'EE_Payment_Method_Manager'            => 'load_lib',
819
+			'EE_Messages_Generator'                => function () {
820
+				return EE_Registry::instance()->load_lib(
821
+					'Messages_Generator',
822
+					array(),
823
+					false,
824
+					false
825
+				);
826
+			},
827
+			'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
828
+				return EE_Registry::instance()->load_lib(
829
+					'Messages_Template_Defaults',
830
+					$arguments,
831
+					false,
832
+					false
833
+				);
834
+			},
835
+			//load_helper
836
+			'EEH_Parse_Shortcodes'                 => function () {
837
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
838
+					return new EEH_Parse_Shortcodes();
839
+				}
840
+				return null;
841
+			},
842
+			'EE_Template_Config'                   => function () {
843
+				return EE_Config::instance()->template_settings;
844
+			},
845
+			'EE_Currency_Config'                   => function () {
846
+				return EE_Config::instance()->currency;
847
+			},
848
+			'EE_Registration_Config'                   => function () {
849
+				return EE_Config::instance()->registration;
850
+			},
851
+			'EE_Core_Config'                   => function () {
852
+				return EE_Config::instance()->core;
853
+			},
854
+			'EventEspresso\core\services\loaders\Loader' => function () {
855
+				return LoaderFactory::getLoader();
856
+			},
857
+			'EE_Network_Config' => function() {
858
+				return EE_Network_Config::instance();
859
+			},
860
+			'EE_Config' => function () {
861
+				return EE_Config::instance();
862
+			},
863
+			'EventEspresso\core\domain\Domain' => function () {
864
+				return DomainFactory::getEventEspressoCoreDomain();
865
+			},
866
+		);
867
+	}
868
+
869
+
870
+
871
+
872
+	/**
873
+	 * can be used for supplying alternate names for classes,
874
+	 * or for connecting interface names to instantiable classes
875
+	 */
876
+	protected function _register_core_aliases()
877
+	{
878
+		$aliases = array(
879
+			'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
880
+			'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
881
+			'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
882
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
883
+			'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
884
+			'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
885
+			'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
886
+			'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
887
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
888
+			'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
889
+			'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
890
+			'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
891
+			'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
892
+			'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
893
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
894
+			'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
895
+			'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
896
+			'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
897
+			'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
898
+			'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
899
+			'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
900
+			'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
901
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
902
+			'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
903
+			'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
904
+			'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
905
+			'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
906
+			'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
907
+			'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
908
+			'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
909
+			'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
910
+			'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
911
+			'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
912
+			'NoticesContainerInterface'                                           => 'EventEspresso\core\services\notices\NoticesContainerInterface',
913
+			'EventEspresso\core\services\notices\NoticesContainerInterface'       => 'EventEspresso\core\services\notices\NoticesContainer',
914
+			'EventEspresso\core\services\request\RequestInterface'                => 'EventEspresso\core\services\request\Request',
915
+			'EventEspresso\core\services\request\ResponseInterface'               => 'EventEspresso\core\services\request\Response',
916
+			'EventEspresso\core\domain\DomainInterface'                           => 'EventEspresso\core\domain\Domain',
917
+		);
918
+		foreach ($aliases as $alias => $fqn) {
919
+			if(is_array($fqn)) {
920
+				foreach ($fqn as $class => $for_class) {
921
+					$this->class_cache->addAlias($class, $alias, $for_class);
922
+				}
923
+				continue;
924
+			}
925
+			$this->class_cache->addAlias($fqn, $alias);
926
+		}
927
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
928
+			$this->class_cache->addAlias(
929
+				'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
930
+				'EventEspresso\core\services\notices\NoticeConverterInterface'
931
+			);
932
+		}
933
+	}
934
+
935
+
936
+
937
+	/**
938
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
939
+	 * request Primarily used by unit tests.
940
+	 */
941
+	public function reset()
942
+	{
943
+		$this->_register_core_class_loaders();
944
+		$this->_register_core_dependencies();
945
+	}
946
+
947
+
948
+	/**
949
+	 * PLZ NOTE: a better name for this method would be is_alias()
950
+	 * because it returns TRUE if the provided fully qualified name IS an alias
951
+	 * WHY?
952
+	 * Because if a class is type hinting for a concretion,
953
+	 * then why would we need to find another class to supply it?
954
+	 * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
955
+	 * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
956
+	 * Don't go looking for some substitute.
957
+	 * Whereas if a class is type hinting for an interface...
958
+	 * then we need to find an actual class to use.
959
+	 * So the interface IS the alias for some other FQN,
960
+	 * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
961
+	 * represents some other class.
962
+	 *
963
+	 * @deprecated $VID:$
964
+	 * @param string $fqn
965
+	 * @param string $for_class
966
+	 * @return bool
967
+	 */
968
+	public function has_alias($fqn = '', $for_class = '')
969
+	{
970
+		return $this->isAlias($fqn, $for_class);
971
+	}
972
+
973
+
974
+	/**
975
+	 * PLZ NOTE: a better name for this method would be get_fqn_for_alias()
976
+	 * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias
977
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
978
+	 *  for example:
979
+	 *      if the following two entries were added to the _aliases array:
980
+	 *          array(
981
+	 *              'interface_alias'           => 'some\namespace\interface'
982
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
983
+	 *          )
984
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
985
+	 *      to load an instance of 'some\namespace\classname'
986
+	 *
987
+	 * @deprecated $VID:$
988
+	 * @param string $alias
989
+	 * @param string $for_class
990
+	 * @return string
991
+	 */
992
+	public function get_alias($alias = '', $for_class = '')
993
+	{
994
+		return $this->getFqnForAlias($alias, $for_class);
995
+	}
996 996
 }
997 997
 // End of file EE_Dependency_Map.core.php
998 998
 // Location: /EE_Dependency_Map.core.php
Please login to merge, or discard this patch.
modules/core_rest_api/EED_Core_Rest_Api.module.php 2 patches
Indentation   +1272 added lines, -1272 removed lines patch added patch discarded remove patch
@@ -26,1279 +26,1279 @@
 block discarded – undo
26 26
 class EED_Core_Rest_Api extends \EED_Module
27 27
 {
28 28
 
29
-    const ee_api_namespace           = Domain::API_NAMESPACE;
29
+	const ee_api_namespace           = Domain::API_NAMESPACE;
30 30
 
31
-    const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/';
32
-
33
-    const saved_routes_option_names  = 'ee_core_routes';
34
-
35
-    /**
36
-     * string used in _links response bodies to make them globally unique.
37
-     *
38
-     * @see http://v2.wp-api.org/extending/linking/
39
-     */
40
-    const ee_api_link_namespace = 'https://api.eventespresso.com/';
41
-
42
-    /**
43
-     * @var CalculatedModelFields
44
-     */
45
-    protected static $_field_calculator;
46
-
47
-
48
-
49
-    /**
50
-     * @return EED_Core_Rest_Api|EED_Module
51
-     */
52
-    public static function instance()
53
-    {
54
-        self::$_field_calculator = new CalculatedModelFields();
55
-        return parent::get_instance(__CLASS__);
56
-    }
57
-
58
-
59
-
60
-    /**
61
-     *    set_hooks - for hooking into EE Core, other modules, etc
62
-     *
63
-     * @access    public
64
-     * @return    void
65
-     */
66
-    public static function set_hooks()
67
-    {
68
-        self::set_hooks_both();
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
75
-     *
76
-     * @access    public
77
-     * @return    void
78
-     */
79
-    public static function set_hooks_admin()
80
-    {
81
-        self::set_hooks_both();
82
-    }
83
-
84
-
85
-
86
-    public static function set_hooks_both()
87
-    {
88
-        add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10);
89
-        add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5);
90
-        add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2);
91
-        add_filter('rest_index',
92
-            array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex'));
93
-        EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change();
94
-    }
95
-
96
-
97
-
98
-    /**
99
-     * sets up hooks which only need to be included as part of REST API requests;
100
-     * other requests like to the frontend or admin etc don't need them
101
-     *
102
-     * @throws \EE_Error
103
-     */
104
-    public static function set_hooks_rest_api()
105
-    {
106
-        //set hooks which account for changes made to the API
107
-        EED_Core_Rest_Api::_set_hooks_for_changes();
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * public wrapper of _set_hooks_for_changes.
114
-     * Loads all the hooks which make requests to old versions of the API
115
-     * appear the same as they always did
116
-     *
117
-     * @throws EE_Error
118
-     */
119
-    public static function set_hooks_for_changes()
120
-    {
121
-        self::_set_hooks_for_changes();
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * Loads all the hooks which make requests to old versions of the API
128
-     * appear the same as they always did
129
-     *
130
-     * @throws EE_Error
131
-     */
132
-    protected static function _set_hooks_for_changes()
133
-    {
134
-        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
135
-        foreach ($folder_contents as $classname_in_namespace => $filepath) {
136
-            //ignore the base parent class
137
-            //and legacy named classes
138
-            if ($classname_in_namespace === 'ChangesInBase'
139
-                || strpos($classname_in_namespace, 'Changes_In_') === 0
140
-            ) {
141
-                continue;
142
-            }
143
-            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
144
-            if (class_exists($full_classname)) {
145
-                $instance_of_class = new $full_classname;
146
-                if ($instance_of_class instanceof ChangesInBase) {
147
-                    $instance_of_class->setHooks();
148
-                }
149
-            }
150
-        }
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * Filters the WP routes to add our EE-related ones. This takes a bit of time
157
-     * so we actually prefer to only do it when an EE plugin is activated or upgraded
158
-     *
159
-     * @throws \EE_Error
160
-     */
161
-    public static function register_routes()
162
-    {
163
-        foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) {
164
-            foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) {
165
-                /**
166
-                 * @var array $data_for_multiple_endpoints numerically indexed array
167
-                 *                                         but can also contain route options like {
168
-                 * @type array    $schema                      {
169
-                 * @type callable $schema_callback
170
-                 * @type array    $callback_args               arguments that will be passed to the callback, after the
171
-                 * WP_REST_Request of course
172
-                 * }
173
-                 * }
174
-                 */
175
-                //when registering routes, register all the endpoints' data at the same time
176
-                $multiple_endpoint_args = array();
177
-                foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) {
178
-                    /**
179
-                     * @var array     $data_for_single_endpoint {
180
-                     * @type callable $callback
181
-                     * @type string methods
182
-                     * @type array args
183
-                     * @type array _links
184
-                     * @type array    $callback_args            arguments that will be passed to the callback, after the
185
-                     * WP_REST_Request of course
186
-                     * }
187
-                     */
188
-                    //skip route options
189
-                    if (! is_numeric($endpoint_key)) {
190
-                        continue;
191
-                    }
192
-                    if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) {
193
-                        throw new EE_Error(
194
-                            esc_html__(
195
-                                // @codingStandardsIgnoreStart
196
-                                'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).',
197
-                                // @codingStandardsIgnoreEnd
198
-                                'event_espresso')
199
-                        );
200
-                    }
201
-                    $callback = $data_for_single_endpoint['callback'];
202
-                    $single_endpoint_args = array(
203
-                        'methods' => $data_for_single_endpoint['methods'],
204
-                        'args'    => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args']
205
-                            : array(),
206
-                    );
207
-                    if (isset($data_for_single_endpoint['_links'])) {
208
-                        $single_endpoint_args['_links'] = $data_for_single_endpoint['_links'];
209
-                    }
210
-                    if (isset($data_for_single_endpoint['callback_args'])) {
211
-                        $callback_args = $data_for_single_endpoint['callback_args'];
212
-                        $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use (
213
-                            $callback,
214
-                            $callback_args
215
-                        ) {
216
-                            array_unshift($callback_args, $request);
217
-                            return call_user_func_array(
218
-                                $callback,
219
-                                $callback_args
220
-                            );
221
-                        };
222
-                    } else {
223
-                        $single_endpoint_args['callback'] = $data_for_single_endpoint['callback'];
224
-                    }
225
-                    $multiple_endpoint_args[] = $single_endpoint_args;
226
-                }
227
-                if (isset($data_for_multiple_endpoints['schema'])) {
228
-                    $schema_route_data = $data_for_multiple_endpoints['schema'];
229
-                    $schema_callback = $schema_route_data['schema_callback'];
230
-                    $callback_args = $schema_route_data['callback_args'];
231
-                    $multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) {
232
-                        return call_user_func_array(
233
-                            $schema_callback,
234
-                            $callback_args
235
-                        );
236
-                    };
237
-                }
238
-                register_rest_route(
239
-                    $namespace,
240
-                    $relative_route,
241
-                    $multiple_endpoint_args
242
-                );
243
-            }
244
-        }
245
-    }
246
-
247
-
248
-
249
-    /**
250
-     * Checks if there was a version change or something that merits invalidating the cached
251
-     * route data. If so, invalidates the cached route data so that it gets refreshed
252
-     * next time the WP API is used
253
-     */
254
-    public static function invalidate_cached_route_data_on_version_change()
255
-    {
256
-        if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) {
257
-            EED_Core_Rest_Api::invalidate_cached_route_data();
258
-        }
259
-        foreach (EE_Registry::instance()->addons as $addon) {
260
-            if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) {
261
-                EED_Core_Rest_Api::invalidate_cached_route_data();
262
-            }
263
-        }
264
-    }
265
-
266
-
267
-
268
-    /**
269
-     * Removes the cached route data so it will get refreshed next time the WP API is used
270
-     */
271
-    public static function invalidate_cached_route_data()
272
-    {
273
-        //delete the saved EE REST API routes
274
-        foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
275
-            delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
276
-        }
277
-    }
278
-
279
-
280
-
281
-    /**
282
-     * Gets the EE route data
283
-     *
284
-     * @return array top-level key is the namespace, next-level key is the route and its value is array{
285
-     * @throws \EE_Error
286
-     * @type string|array $callback
287
-     * @type string       $methods
288
-     * @type boolean      $hidden_endpoint
289
-     * }
290
-     */
291
-    public static function get_ee_route_data()
292
-    {
293
-        $ee_routes = array();
294
-        foreach (self::versions_served() as $version => $hidden_endpoints) {
295
-            $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version(
296
-                $version,
297
-                $hidden_endpoints
298
-            );
299
-        }
300
-        return $ee_routes;
301
-    }
302
-
303
-
304
-
305
-    /**
306
-     * Gets the EE route data from the wp options if it exists already,
307
-     * otherwise re-generates it and saves it to the option
308
-     *
309
-     * @param string  $version
310
-     * @param boolean $hidden_endpoints
311
-     * @return array
312
-     * @throws \EE_Error
313
-     */
314
-    protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
315
-    {
316
-        $ee_routes = get_option(self::saved_routes_option_names . $version, null);
317
-        if (! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
318
-            $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
319
-        }
320
-        return $ee_routes;
321
-    }
322
-
323
-
324
-
325
-    /**
326
-     * Saves the EE REST API route data to a wp option and returns it
327
-     *
328
-     * @param string  $version
329
-     * @param boolean $hidden_endpoints
330
-     * @return mixed|null
331
-     * @throws \EE_Error
332
-     */
333
-    protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false)
334
-    {
335
-        $instance = self::instance();
336
-        $routes = apply_filters(
337
-            'EED_Core_Rest_Api__save_ee_route_data_for_version__routes',
338
-            array_replace_recursive(
339
-                $instance->_get_config_route_data_for_version($version, $hidden_endpoints),
340
-                $instance->_get_meta_route_data_for_version($version, $hidden_endpoints),
341
-                $instance->_get_model_route_data_for_version($version, $hidden_endpoints),
342
-                $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
343
-            )
344
-        );
345
-        $option_name = self::saved_routes_option_names . $version;
346
-        if (get_option($option_name)) {
347
-            update_option($option_name, $routes, true);
348
-        } else {
349
-            add_option($option_name, $routes, null, 'no');
350
-        }
351
-        return $routes;
352
-    }
353
-
354
-
355
-
356
-    /**
357
-     * Calculates all the EE routes and saves it to a WordPress option so we don't
358
-     * need to calculate it on every request
359
-     *
360
-     * @deprecated since version 4.9.1
361
-     * @return void
362
-     */
363
-    public static function save_ee_routes()
364
-    {
365
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
366
-            $instance = self::instance();
367
-            $routes = apply_filters(
368
-                'EED_Core_Rest_Api__save_ee_routes__routes',
369
-                array_replace_recursive(
370
-                    $instance->_register_config_routes(),
371
-                    $instance->_register_meta_routes(),
372
-                    $instance->_register_model_routes(),
373
-                    $instance->_register_rpc_routes()
374
-                )
375
-            );
376
-            update_option(self::saved_routes_option_names, $routes, true);
377
-        }
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     * Gets all the route information relating to EE models
384
-     *
385
-     * @return array @see get_ee_route_data
386
-     * @deprecated since version 4.9.1
387
-     */
388
-    protected function _register_model_routes()
389
-    {
390
-        $model_routes = array();
391
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
392
-            $model_routes[EED_Core_Rest_Api::ee_api_namespace
393
-                          . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
394
-        }
395
-        return $model_routes;
396
-    }
397
-
398
-
399
-
400
-    /**
401
-     * Decides whether or not to add write endpoints for this model.
402
-     *
403
-     * Currently, this defaults to exclude all global tables and models
404
-     * which would allow inserting WP core data (we don't want to duplicate
405
-     * what WP API does, as it's unnecessary, extra work, and potentially extra bugs)
406
-     * @param EEM_Base $model
407
-     * @return bool
408
-     */
409
-    public static function should_have_write_endpoints(EEM_Base $model)
410
-    {
411
-        if ($model->is_wp_core_model()){
412
-            return false;
413
-        }
414
-        foreach($model->get_tables() as $table){
415
-            if( $table->is_global()){
416
-                return false;
417
-            }
418
-        }
419
-        return true;
420
-    }
421
-
422
-
423
-
424
-    /**
425
-     * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`)
426
-     * in this versioned namespace of EE4
427
-     * @param $version
428
-     * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event')
429
-     */
430
-    public static function model_names_with_plural_routes($version){
431
-        $model_version_info = new ModelVersionInfo($version);
432
-        $models_to_register = $model_version_info->modelsForRequestedVersion();
433
-        //let's not bother having endpoints for extra metas
434
-        unset(
435
-            $models_to_register['Extra_Meta'],
436
-            $models_to_register['Extra_Join'],
437
-            $models_to_register['Post_Meta']
438
-        );
439
-        return apply_filters(
440
-            'FHEE__EED_Core_REST_API___register_model_routes',
441
-            $models_to_register
442
-        );
443
-    }
444
-
445
-
446
-
447
-    /**
448
-     * Gets the route data for EE models in the specified version
449
-     *
450
-     * @param string  $version
451
-     * @param boolean $hidden_endpoint
452
-     * @return array
453
-     * @throws EE_Error
454
-     */
455
-    protected function _get_model_route_data_for_version($version, $hidden_endpoint = false)
456
-    {
457
-        $model_routes = array();
458
-        $model_version_info = new ModelVersionInfo($version);
459
-        foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) {
460
-            $model = \EE_Registry::instance()->load_model($model_name);
461
-            //if this isn't a valid model then let's skip iterate to the next item in the loop.
462
-            if (! $model instanceof EEM_Base) {
463
-                continue;
464
-            }
465
-            //yes we could just register one route for ALL models, but then they wouldn't show up in the index
466
-            $plural_model_route = EED_Core_Rest_Api::get_collection_route($model);
467
-            $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)');
468
-            $model_routes[$plural_model_route] = array(
469
-                array(
470
-                    'callback'        => array(
471
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
472
-                        'handleRequestGetAll',
473
-                    ),
474
-                    'callback_args'   => array($version, $model_name),
475
-                    'methods'         => WP_REST_Server::READABLE,
476
-                    'hidden_endpoint' => $hidden_endpoint,
477
-                    'args'            => $this->_get_read_query_params($model, $version),
478
-                    '_links'          => array(
479
-                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
480
-                    ),
481
-                ),
482
-                'schema' => array(
483
-                    'schema_callback' => array(
484
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
485
-                        'handleSchemaRequest',
486
-                    ),
487
-                    'callback_args'   => array($version, $model_name),
488
-                ),
489
-            );
490
-            $model_routes[$singular_model_route] = array(
491
-                array(
492
-                    'callback'        => array(
493
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
494
-                        'handleRequestGetOne',
495
-                    ),
496
-                    'callback_args'   => array($version, $model_name),
497
-                    'methods'         => WP_REST_Server::READABLE,
498
-                    'hidden_endpoint' => $hidden_endpoint,
499
-                    'args'            => $this->_get_response_selection_query_params($model, $version),
500
-                ),
501
-            );
502
-            if( apply_filters(
503
-                'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints',
504
-                EED_Core_Rest_Api::should_have_write_endpoints($model),
505
-                $model
506
-            )){
507
-                $model_routes[$plural_model_route][] = array(
508
-                    'callback'        => array(
509
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Write',
510
-                        'handleRequestInsert',
511
-                    ),
512
-                    'callback_args'   => array($version, $model_name),
513
-                    'methods'         => WP_REST_Server::CREATABLE,
514
-                    'hidden_endpoint' => $hidden_endpoint,
515
-                    'args'            => $this->_get_write_params($model_name, $model_version_info, true),
516
-                );
517
-                $model_routes[$singular_model_route] = array_merge(
518
-                    $model_routes[$singular_model_route],
519
-                    array(
520
-                        array(
521
-                            'callback'        => array(
522
-                                'EventEspresso\core\libraries\rest_api\controllers\model\Write',
523
-                                'handleRequestUpdate',
524
-                            ),
525
-                            'callback_args'   => array($version, $model_name),
526
-                            'methods'         => WP_REST_Server::EDITABLE,
527
-                            'hidden_endpoint' => $hidden_endpoint,
528
-                            'args'            => $this->_get_write_params($model_name, $model_version_info),
529
-                        ),
530
-                        array(
531
-                            'callback'        => array(
532
-                                'EventEspresso\core\libraries\rest_api\controllers\model\Write',
533
-                                'handleRequestDelete',
534
-                            ),
535
-                            'callback_args'   => array($version, $model_name),
536
-                            'methods'         => WP_REST_Server::DELETABLE,
537
-                            'hidden_endpoint' => $hidden_endpoint,
538
-                            'args'            => $this->_get_delete_query_params($model, $version),
539
-                        )
540
-                    )
541
-                );
542
-            }
543
-            foreach ($model->relation_settings() as $relation_name => $relation_obj) {
544
-
545
-                $related_route = EED_Core_Rest_Api::get_relation_route_via(
546
-                    $model,
547
-                    '(?P<id>[^\/]+)',
548
-                    $relation_obj
549
-                );
550
-                $endpoints = array(
551
-                    array(
552
-                        'callback'        => array(
553
-                            'EventEspresso\core\libraries\rest_api\controllers\model\Read',
554
-                            'handleRequestGetRelated',
555
-                        ),
556
-                        'callback_args'   => array($version, $model_name, $relation_name),
557
-                        'methods'         => WP_REST_Server::READABLE,
558
-                        'hidden_endpoint' => $hidden_endpoint,
559
-                        'args'            => $this->_get_read_query_params($relation_obj->get_other_model(), $version),
560
-                    ),
561
-                );
562
-                $model_routes[$related_route] = $endpoints;
563
-            }
564
-        }
565
-        return $model_routes;
566
-    }
567
-
568
-
569
-
570
-    /**
571
-     * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace,
572
-     * excluding the preceding slash.
573
-     * Eg you pass get_plural_route_to('Event') = 'events'
574
-     *
575
-     * @param EEM_Base $model
576
-     * @return string
577
-     */
578
-    public static function get_collection_route(EEM_Base $model)
579
-    {
580
-        return EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
581
-    }
582
-
583
-
584
-
585
-    /**
586
-     * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
587
-     * excluding the preceding slash.
588
-     * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
589
-     *
590
-     * @param EEM_Base $model eg Event or Venue
591
-     * @param string $id
592
-     * @return string
593
-     */
594
-    public static function get_entity_route($model, $id)
595
-    {
596
-        return EED_Core_Rest_Api::get_collection_route($model). '/' . $id;
597
-    }
598
-
599
-
600
-    /**
601
-     * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
602
-     * excluding the preceding slash.
603
-     * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
604
-     *
605
-     * @param EEM_Base                 $model eg Event or Venue
606
-     * @param string                 $id
607
-     * @param EE_Model_Relation_Base $relation_obj
608
-     * @return string
609
-     */
610
-    public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj)
611
-    {
612
-        $related_model_name_endpoint_part = ModelRead::getRelatedEntityName(
613
-            $relation_obj->get_other_model()->get_this_model_name(),
614
-            $relation_obj
615
-        );
616
-        return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part;
617
-    }
618
-
619
-
620
-
621
-    /**
622
-     * Adds onto the $relative_route the EE4 REST API versioned namespace.
623
-     * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events'
624
-     * @param string $relative_route
625
-     * @param string $version
626
-     * @return string
627
-     */
628
-    public static function get_versioned_route_to($relative_route, $version = '4.8.36'){
629
-        return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route;
630
-    }
631
-
632
-
633
-
634
-    /**
635
-     * Adds all the RPC-style routes (remote procedure call-like routes, ie
636
-     * routes that don't conform to the traditional REST CRUD-style).
637
-     *
638
-     * @deprecated since 4.9.1
639
-     */
640
-    protected function _register_rpc_routes()
641
-    {
642
-        $routes = array();
643
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
644
-            $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version(
645
-                $version,
646
-                $hidden_endpoint
647
-            );
648
-        }
649
-        return $routes;
650
-    }
651
-
652
-
653
-
654
-    /**
655
-     * @param string  $version
656
-     * @param boolean $hidden_endpoint
657
-     * @return array
658
-     */
659
-    protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false)
660
-    {
661
-        $this_versions_routes = array();
662
-        //checkin endpoint
663
-        $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array(
664
-            array(
665
-                'callback'        => array(
666
-                    'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin',
667
-                    'handleRequestToggleCheckin',
668
-                ),
669
-                'methods'         => WP_REST_Server::CREATABLE,
670
-                'hidden_endpoint' => $hidden_endpoint,
671
-                'args'            => array(
672
-                    'force' => array(
673
-                        'required'    => false,
674
-                        'default'     => false,
675
-                        'description' => __(
676
-                            // @codingStandardsIgnoreStart
677
-                            'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses',
678
-                            // @codingStandardsIgnoreEnd
679
-                            'event_espresso'
680
-                        ),
681
-                    ),
682
-                ),
683
-                'callback_args'   => array($version),
684
-            ),
685
-        );
686
-        return apply_filters(
687
-            'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
688
-            $this_versions_routes,
689
-            $version,
690
-            $hidden_endpoint
691
-        );
692
-    }
693
-
694
-
695
-
696
-    /**
697
-     * Gets the query params that can be used when request one or many
698
-     *
699
-     * @param EEM_Base $model
700
-     * @param string   $version
701
-     * @return array
702
-     */
703
-    protected function _get_response_selection_query_params(\EEM_Base $model, $version)
704
-    {
705
-        return apply_filters(
706
-            'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
707
-            array(
708
-                'include'   => array(
709
-                    'required' => false,
710
-                    'default'  => '*',
711
-                    'type'     => 'string',
712
-                ),
713
-                'calculate' => array(
714
-                    'required'          => false,
715
-                    'default'           => '',
716
-                    'enum'              => self::$_field_calculator->retrieveCalculatedFieldsForModel($model),
717
-                    'type'              => 'string',
718
-                    //because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization
719
-                    //freaks out. We'll just validate this argument while handling the request
720
-                    'validate_callback' => null,
721
-                    'sanitize_callback' => null,
722
-                ),
723
-            ),
724
-            $model,
725
-            $version
726
-        );
727
-    }
728
-
729
-
730
-
731
-    /**
732
-     * Gets the parameters acceptable for delete requests
733
-     *
734
-     * @param \EEM_Base $model
735
-     * @param string    $version
736
-     * @return array
737
-     */
738
-    protected function _get_delete_query_params(\EEM_Base $model, $version)
739
-    {
740
-        $params_for_delete = array(
741
-            'allow_blocking' => array(
742
-                'required' => false,
743
-                'default'  => true,
744
-                'type'     => 'boolean',
745
-            ),
746
-        );
747
-        $params_for_delete['force'] = array(
748
-            'required' => false,
749
-            'default'  => false,
750
-            'type'     => 'boolean',
751
-        );
752
-        return apply_filters(
753
-            'FHEE__EED_Core_Rest_Api___get_delete_query_params',
754
-            $params_for_delete,
755
-            $model,
756
-            $version
757
-        );
758
-    }
759
-
760
-
761
-
762
-    /**
763
-     * Gets info about reading query params that are acceptable
764
-     *
765
-     * @param \EEM_Base $model eg 'Event' or 'Venue'
766
-     * @param  string   $version
767
-     * @return array    describing the args acceptable when querying this model
768
-     * @throws EE_Error
769
-     */
770
-    protected function _get_read_query_params(\EEM_Base $model, $version)
771
-    {
772
-        $default_orderby = array();
773
-        foreach ($model->get_combined_primary_key_fields() as $key_field) {
774
-            $default_orderby[$key_field->get_name()] = 'ASC';
775
-        }
776
-        return array_merge(
777
-            $this->_get_response_selection_query_params($model, $version),
778
-            array(
779
-                'where'    => array(
780
-                    'required' => false,
781
-                    'default'  => array(),
782
-                    'type'     => 'object',
783
-                    //because we accept an almost infinite list of possible where conditions, WP
784
-                    // core validation and sanitization freaks out. We'll just validate this argument
785
-                    // while handling the request
786
-                    'validate_callback' => null,
787
-                    'sanitize_callback' => null,
788
-                ),
789
-                'limit'    => array(
790
-                    'required' => false,
791
-                    'default'  => EED_Core_Rest_Api::get_default_query_limit(),
792
-                    'type'     => array(
793
-                        'array',
794
-                        'string',
795
-                        'integer',
796
-                    ),
797
-                    //because we accept a variety of types, WP core validation and sanitization
798
-                    //freaks out. We'll just validate this argument while handling the request
799
-                    'validate_callback' => null,
800
-                    'sanitize_callback' => null,
801
-                ),
802
-                'order_by' => array(
803
-                    'required' => false,
804
-                    'default'  => $default_orderby,
805
-                    'type'     => array(
806
-                        'object',
807
-                        'string',
808
-                    ),//because we accept a variety of types, WP core validation and sanitization
809
-                    //freaks out. We'll just validate this argument while handling the request
810
-                    'validate_callback' => null,
811
-                    'sanitize_callback' => null,
812
-                ),
813
-                'group_by' => array(
814
-                    'required' => false,
815
-                    'default'  => null,
816
-                    'type'     => array(
817
-                        'object',
818
-                        'string',
819
-                    ),
820
-                    //because we accept  an almost infinite list of possible groupings,
821
-                    // WP core validation and sanitization
822
-                    //freaks out. We'll just validate this argument while handling the request
823
-                    'validate_callback' => null,
824
-                    'sanitize_callback' => null,
825
-                ),
826
-                'having'   => array(
827
-                    'required' => false,
828
-                    'default'  => null,
829
-                    'type'     => 'object',
830
-                    //because we accept an almost infinite list of possible where conditions, WP
831
-                    // core validation and sanitization freaks out. We'll just validate this argument
832
-                    // while handling the request
833
-                    'validate_callback' => null,
834
-                    'sanitize_callback' => null,
835
-                ),
836
-                'caps'     => array(
837
-                    'required' => false,
838
-                    'default'  => EEM_Base::caps_read,
839
-                    'type'     => 'string',
840
-                    'enum'     => array(
841
-                        EEM_Base::caps_read,
842
-                        EEM_Base::caps_read_admin,
843
-                        EEM_Base::caps_edit,
844
-                        EEM_Base::caps_delete
845
-                    )
846
-                ),
847
-            )
848
-        );
849
-    }
850
-
851
-
852
-
853
-    /**
854
-     * Gets parameter information for a model regarding writing data
855
-     *
856
-     * @param string           $model_name
857
-     * @param ModelVersionInfo $model_version_info
858
-     * @param boolean          $create                                       whether this is for request to create (in which case we need
859
-     *                                                                       all required params) or just to update (in which case we don't need those on every request)
860
-     * @return array
861
-     */
862
-    protected function _get_write_params(
863
-        $model_name,
864
-        ModelVersionInfo $model_version_info,
865
-        $create = false
866
-    ) {
867
-        $model = EE_Registry::instance()->load_model($model_name);
868
-        $fields = $model_version_info->fieldsOnModelInThisVersion($model);
869
-        $args_info = array();
870
-        foreach ($fields as $field_name => $field_obj) {
871
-            if ($field_obj->is_auto_increment()) {
872
-                //totally ignore auto increment IDs
873
-                continue;
874
-            }
875
-            $arg_info = $field_obj->getSchema();
876
-            $required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null;
877
-            $arg_info['required'] = $required;
878
-            //remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right?
879
-            unset($arg_info['readonly']);
880
-            $schema_properties = $field_obj->getSchemaProperties();
881
-            if (
882
-                isset($schema_properties['raw'])
883
-                && $field_obj->getSchemaType() === 'object'
884
-            ) {
885
-                //if there's a "raw" form of this argument, use those properties instead
886
-                $arg_info = array_replace(
887
-                    $arg_info,
888
-                    $schema_properties['raw']
889
-                );
890
-            }
891
-            $arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson(
892
-                $field_obj,
893
-                $field_obj->get_default_value(),
894
-                $model_version_info->requestedVersion()
895
-            );
896
-            //we do our own validation and sanitization within the controller
897
-            if(function_exists('rest_validate_value_from_schema')){
898
-                $sanitize_callback = array(
899
-                    'EED_Core_Rest_Api',
900
-                    'default_sanitize_callback',
901
-                );
902
-            } else {
903
-                $sanitize_callback = null;
904
-            }
905
-            $arg_info['sanitize_callback'] = $sanitize_callback;
906
-            $args_info[$field_name] = $arg_info;
907
-            if ($field_obj instanceof EE_Datetime_Field) {
908
-                $gmt_arg_info = $arg_info;
909
-                $gmt_arg_info['description'] = sprintf(
910
-                    esc_html__(
911
-                        '%1$s - the value for this field in UTC. Ignored if %2$s is provided.',
912
-                        'event_espresso'
913
-                    ),
914
-                    $field_obj->get_nicename(),
915
-                    $field_name
916
-                );
917
-                $args_info[$field_name . '_gmt'] = $gmt_arg_info;
918
-            }
919
-        }
920
-        return $args_info;
921
-    }
922
-
923
-
924
-
925
-    /**
926
-     * Replacement for WP API's 'rest_parse_request_arg'.
927
-     * If the value is blank but not required, don't bother validating it.
928
-     * Also, it uses our email validation instead of WP API's default.
929
-     *
930
-     * @param                 $value
931
-     * @param WP_REST_Request $request
932
-     * @param                 $param
933
-     * @return bool|true|WP_Error
934
-     * @throws InvalidArgumentException
935
-     * @throws InvalidInterfaceException
936
-     * @throws InvalidDataTypeException
937
-     */
938
-    public static function default_sanitize_callback( $value, WP_REST_Request $request, $param)
939
-    {
940
-        $attributes = $request->get_attributes();
941
-        if (! isset($attributes['args'][$param])
942
-            || ! is_array($attributes['args'][$param])) {
943
-            $validation_result = true;
944
-        } else {
945
-            $args = $attributes['args'][$param];
946
-            if ((
947
-                    $value === ''
948
-                    || $value === null
949
-                )
950
-                && (! isset($args['required'])
951
-                    || $args['required'] === false
952
-                )
953
-            ) {
954
-                //not required and not provided? that's cool
955
-                $validation_result = true;
956
-            } elseif (isset($args['format'])
957
-                && $args['format'] === 'email'
958
-            ) {
959
-                $validation_result = true;
960
-                if (! self::_validate_email($value)) {
961
-                    $validation_result = new WP_Error(
962
-                        'rest_invalid_param',
963
-                        esc_html__(
964
-                            'The email address is not valid or does not exist.',
965
-                            'event_espresso'
966
-                        )
967
-                    );
968
-                }
969
-            } else {
970
-                $validation_result = rest_validate_value_from_schema($value, $args, $param);
971
-            }
972
-        }
973
-        if (is_wp_error($validation_result)) {
974
-            return $validation_result;
975
-        }
976
-        return rest_sanitize_request_arg($value, $request, $param);
977
-    }
978
-
979
-
980
-
981
-    /**
982
-     * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email()
983
-     *
984
-     * @param $email
985
-     * @return bool
986
-     * @throws InvalidArgumentException
987
-     * @throws InvalidInterfaceException
988
-     * @throws InvalidDataTypeException
989
-     */
990
-    protected static function _validate_email($email){
991
-        try {
992
-            EmailAddressFactory::create($email);
993
-            return true;
994
-        } catch (EmailValidationException $e) {
995
-            return false;
996
-        }
997
-    }
998
-
999
-
1000
-
1001
-    /**
1002
-     * Gets routes for the config
1003
-     *
1004
-     * @return array @see _register_model_routes
1005
-     * @deprecated since version 4.9.1
1006
-     */
1007
-    protected function _register_config_routes()
1008
-    {
1009
-        $config_routes = array();
1010
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
1011
-            $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version(
1012
-                $version,
1013
-                $hidden_endpoint
1014
-            );
1015
-        }
1016
-        return $config_routes;
1017
-    }
1018
-
1019
-
1020
-
1021
-    /**
1022
-     * Gets routes for the config for the specified version
1023
-     *
1024
-     * @param string  $version
1025
-     * @param boolean $hidden_endpoint
1026
-     * @return array
1027
-     */
1028
-    protected function _get_config_route_data_for_version($version, $hidden_endpoint)
1029
-    {
1030
-        return array(
1031
-            'config'    => array(
1032
-                array(
1033
-                    'callback'        => array(
1034
-                        'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1035
-                        'handleRequest',
1036
-                    ),
1037
-                    'methods'         => WP_REST_Server::READABLE,
1038
-                    'hidden_endpoint' => $hidden_endpoint,
1039
-                    'callback_args'   => array($version),
1040
-                ),
1041
-            ),
1042
-            'site_info' => array(
1043
-                array(
1044
-                    'callback'        => array(
1045
-                        'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1046
-                        'handleRequestSiteInfo',
1047
-                    ),
1048
-                    'methods'         => WP_REST_Server::READABLE,
1049
-                    'hidden_endpoint' => $hidden_endpoint,
1050
-                    'callback_args'   => array($version),
1051
-                ),
1052
-            ),
1053
-        );
1054
-    }
1055
-
1056
-
1057
-
1058
-    /**
1059
-     * Gets the meta info routes
1060
-     *
1061
-     * @return array @see _register_model_routes
1062
-     * @deprecated since version 4.9.1
1063
-     */
1064
-    protected function _register_meta_routes()
1065
-    {
1066
-        $meta_routes = array();
1067
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
1068
-            $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version(
1069
-                $version,
1070
-                $hidden_endpoint
1071
-            );
1072
-        }
1073
-        return $meta_routes;
1074
-    }
1075
-
1076
-
1077
-
1078
-    /**
1079
-     * @param string  $version
1080
-     * @param boolean $hidden_endpoint
1081
-     * @return array
1082
-     */
1083
-    protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false)
1084
-    {
1085
-        return array(
1086
-            'resources' => array(
1087
-                array(
1088
-                    'callback'        => array(
1089
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Meta',
1090
-                        'handleRequestModelsMeta',
1091
-                    ),
1092
-                    'methods'         => WP_REST_Server::READABLE,
1093
-                    'hidden_endpoint' => $hidden_endpoint,
1094
-                    'callback_args'   => array($version),
1095
-                ),
1096
-            ),
1097
-        );
1098
-    }
1099
-
1100
-
1101
-
1102
-    /**
1103
-     * Tries to hide old 4.6 endpoints from the
1104
-     *
1105
-     * @param array $route_data
1106
-     * @return array
1107
-     * @throws \EE_Error
1108
-     */
1109
-    public static function hide_old_endpoints($route_data)
1110
-    {
1111
-        //allow API clients to override which endpoints get hidden, in case
1112
-        //they want to discover particular endpoints
1113
-        //also, we don't have access to the request so we have to just grab it from the superglobal
1114
-        $force_show_ee_namespace = ltrim(
1115
-            EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''),
1116
-            '/'
1117
-        );
1118
-        foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
1119
-            foreach ($relative_urls as $resource_name => $endpoints) {
1120
-                foreach ($endpoints as $key => $endpoint) {
1121
-                    //skip schema and other route options
1122
-                    if (! is_numeric($key)) {
1123
-                        continue;
1124
-                    }
1125
-                    //by default, hide "hidden_endpoint"s, unless the request indicates
1126
-                    //to $force_show_ee_namespace, in which case only show that one
1127
-                    //namespace's endpoints (and hide all others)
1128
-                    if (
1129
-                        ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
1130
-                        || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '')
1131
-                    ) {
1132
-                        $full_route = '/' . ltrim($namespace, '/');
1133
-                        $full_route .= '/' . ltrim($resource_name, '/');
1134
-                        unset($route_data[$full_route]);
1135
-                    }
1136
-                }
1137
-            }
1138
-        }
1139
-        return $route_data;
1140
-    }
1141
-
1142
-
1143
-
1144
-    /**
1145
-     * Returns an array describing which versions of core support serving requests for.
1146
-     * Keys are core versions' major and minor version, and values are the
1147
-     * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like
1148
-     * data by just removing a few models and fields from the responses. However, 4.15 might remove
1149
-     * the answers table entirely, in which case it would be very difficult for
1150
-     * it to serve 4.6-style responses.
1151
-     * Versions of core that are missing from this array are unknowns.
1152
-     * previous ver
1153
-     *
1154
-     * @return array
1155
-     */
1156
-    public static function version_compatibilities()
1157
-    {
1158
-        return apply_filters(
1159
-            'FHEE__EED_Core_REST_API__version_compatibilities',
1160
-            array(
1161
-                '4.8.29' => '4.8.29',
1162
-                '4.8.33' => '4.8.29',
1163
-                '4.8.34' => '4.8.29',
1164
-                '4.8.36' => '4.8.29',
1165
-            )
1166
-        );
1167
-    }
1168
-
1169
-
1170
-
1171
-    /**
1172
-     * Gets the latest API version served. Eg if there
1173
-     * are two versions served of the API, 4.8.29 and 4.8.32, and
1174
-     * we are on core version 4.8.34, it will return the string "4.8.32"
1175
-     *
1176
-     * @return string
1177
-     */
1178
-    public static function latest_rest_api_version()
1179
-    {
1180
-        $versions_served = \EED_Core_Rest_Api::versions_served();
1181
-        $versions_served_keys = array_keys($versions_served);
1182
-        return end($versions_served_keys);
1183
-    }
1184
-
1185
-
1186
-
1187
-    /**
1188
-     * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of
1189
-     * EE the API can serve requests for. Eg, if we are on 4.15 of core, and
1190
-     * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ).
1191
-     * We also indicate whether or not this version should be put in the index or not
1192
-     *
1193
-     * @return array keys are API version numbers (just major and minor numbers), and values
1194
-     * are whether or not they should be hidden
1195
-     */
1196
-    public static function versions_served()
1197
-    {
1198
-        $versions_served = array();
1199
-        $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities();
1200
-        $lowest_compatible_version = end($possibly_served_versions);
1201
-        reset($possibly_served_versions);
1202
-        $versions_served_historically = array_keys($possibly_served_versions);
1203
-        $latest_version = end($versions_served_historically);
1204
-        reset($versions_served_historically);
1205
-        //for each version of core we have ever served:
1206
-        foreach ($versions_served_historically as $key_versioned_endpoint) {
1207
-            //if it's not above the current core version, and it's compatible with the current version of core
1208
-            if ($key_versioned_endpoint === $latest_version) {
1209
-                //don't hide the latest version in the index
1210
-                $versions_served[$key_versioned_endpoint] = false;
1211
-            } elseif (
1212
-                $key_versioned_endpoint >= $lowest_compatible_version
1213
-                && $key_versioned_endpoint < EED_Core_Rest_Api::core_version()
1214
-            ) {
1215
-                //include, but hide, previous versions which are still supported
1216
-                $versions_served[$key_versioned_endpoint] = true;
1217
-            } elseif (apply_filters(
1218
-                'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
1219
-                false,
1220
-                $possibly_served_versions
1221
-            )) {
1222
-                //if a version is no longer supported, don't include it in index or list of versions served
1223
-                $versions_served[$key_versioned_endpoint] = true;
1224
-            }
1225
-        }
1226
-        return $versions_served;
1227
-    }
1228
-
1229
-
1230
-
1231
-    /**
1232
-     * Gets the major and minor version of EE core's version string
1233
-     *
1234
-     * @return string
1235
-     */
1236
-    public static function core_version()
1237
-    {
1238
-        return apply_filters(
1239
-            'FHEE__EED_Core_REST_API__core_version',
1240
-            implode(
1241
-                '.',
1242
-                array_slice(
1243
-                    explode(
1244
-                        '.',
1245
-                        espresso_version()
1246
-                    ),
1247
-                0,
1248
-                3
1249
-                )
1250
-            )
1251
-        );
1252
-    }
1253
-
1254
-
1255
-
1256
-    /**
1257
-     * Gets the default limit that should be used when querying for resources
1258
-     *
1259
-     * @return int
1260
-     */
1261
-    public static function get_default_query_limit()
1262
-    {
1263
-        //we actually don't use a const because we want folks to always use
1264
-        //this method, not the const directly
1265
-        return apply_filters(
1266
-            'FHEE__EED_Core_Rest_Api__get_default_query_limit',
1267
-            50
1268
-        );
1269
-    }
1270
-
1271
-
1272
-    /**
1273
-     *
1274
-     * @param string $version api version string (i.e. '4.8.36')
1275
-     * @return array
1276
-     */
1277
-    public static function getCollectionRoutesIndexedByModelName($version = '')
1278
-    {
1279
-        $version = empty($version) ? self::latest_rest_api_version() : $version;
1280
-        $model_names = self::model_names_with_plural_routes($version);
1281
-        $collection_routes = array();
1282
-        foreach ($model_names as $model_name => $model_class_name) {
1283
-            $collection_routes[strtolower($model_name)] = '/' . self::ee_api_namespace . $version . '/'
1284
-                                                          . EEH_Inflector::pluralize_and_lower($model_name);
1285
-
1286
-        }
1287
-        return $collection_routes;
1288
-    }
1289
-
1290
-
1291
-
1292
-    /**
1293
-     *    run - initial module setup
1294
-     *
1295
-     * @access    public
1296
-     * @param  WP $WP
1297
-     * @return    void
1298
-     */
1299
-    public function run($WP)
1300
-    {
1301
-    }
31
+	const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/';
32
+
33
+	const saved_routes_option_names  = 'ee_core_routes';
34
+
35
+	/**
36
+	 * string used in _links response bodies to make them globally unique.
37
+	 *
38
+	 * @see http://v2.wp-api.org/extending/linking/
39
+	 */
40
+	const ee_api_link_namespace = 'https://api.eventespresso.com/';
41
+
42
+	/**
43
+	 * @var CalculatedModelFields
44
+	 */
45
+	protected static $_field_calculator;
46
+
47
+
48
+
49
+	/**
50
+	 * @return EED_Core_Rest_Api|EED_Module
51
+	 */
52
+	public static function instance()
53
+	{
54
+		self::$_field_calculator = new CalculatedModelFields();
55
+		return parent::get_instance(__CLASS__);
56
+	}
57
+
58
+
59
+
60
+	/**
61
+	 *    set_hooks - for hooking into EE Core, other modules, etc
62
+	 *
63
+	 * @access    public
64
+	 * @return    void
65
+	 */
66
+	public static function set_hooks()
67
+	{
68
+		self::set_hooks_both();
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
75
+	 *
76
+	 * @access    public
77
+	 * @return    void
78
+	 */
79
+	public static function set_hooks_admin()
80
+	{
81
+		self::set_hooks_both();
82
+	}
83
+
84
+
85
+
86
+	public static function set_hooks_both()
87
+	{
88
+		add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10);
89
+		add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5);
90
+		add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2);
91
+		add_filter('rest_index',
92
+			array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex'));
93
+		EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change();
94
+	}
95
+
96
+
97
+
98
+	/**
99
+	 * sets up hooks which only need to be included as part of REST API requests;
100
+	 * other requests like to the frontend or admin etc don't need them
101
+	 *
102
+	 * @throws \EE_Error
103
+	 */
104
+	public static function set_hooks_rest_api()
105
+	{
106
+		//set hooks which account for changes made to the API
107
+		EED_Core_Rest_Api::_set_hooks_for_changes();
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * public wrapper of _set_hooks_for_changes.
114
+	 * Loads all the hooks which make requests to old versions of the API
115
+	 * appear the same as they always did
116
+	 *
117
+	 * @throws EE_Error
118
+	 */
119
+	public static function set_hooks_for_changes()
120
+	{
121
+		self::_set_hooks_for_changes();
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * Loads all the hooks which make requests to old versions of the API
128
+	 * appear the same as they always did
129
+	 *
130
+	 * @throws EE_Error
131
+	 */
132
+	protected static function _set_hooks_for_changes()
133
+	{
134
+		$folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
135
+		foreach ($folder_contents as $classname_in_namespace => $filepath) {
136
+			//ignore the base parent class
137
+			//and legacy named classes
138
+			if ($classname_in_namespace === 'ChangesInBase'
139
+				|| strpos($classname_in_namespace, 'Changes_In_') === 0
140
+			) {
141
+				continue;
142
+			}
143
+			$full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
144
+			if (class_exists($full_classname)) {
145
+				$instance_of_class = new $full_classname;
146
+				if ($instance_of_class instanceof ChangesInBase) {
147
+					$instance_of_class->setHooks();
148
+				}
149
+			}
150
+		}
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * Filters the WP routes to add our EE-related ones. This takes a bit of time
157
+	 * so we actually prefer to only do it when an EE plugin is activated or upgraded
158
+	 *
159
+	 * @throws \EE_Error
160
+	 */
161
+	public static function register_routes()
162
+	{
163
+		foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) {
164
+			foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) {
165
+				/**
166
+				 * @var array $data_for_multiple_endpoints numerically indexed array
167
+				 *                                         but can also contain route options like {
168
+				 * @type array    $schema                      {
169
+				 * @type callable $schema_callback
170
+				 * @type array    $callback_args               arguments that will be passed to the callback, after the
171
+				 * WP_REST_Request of course
172
+				 * }
173
+				 * }
174
+				 */
175
+				//when registering routes, register all the endpoints' data at the same time
176
+				$multiple_endpoint_args = array();
177
+				foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) {
178
+					/**
179
+					 * @var array     $data_for_single_endpoint {
180
+					 * @type callable $callback
181
+					 * @type string methods
182
+					 * @type array args
183
+					 * @type array _links
184
+					 * @type array    $callback_args            arguments that will be passed to the callback, after the
185
+					 * WP_REST_Request of course
186
+					 * }
187
+					 */
188
+					//skip route options
189
+					if (! is_numeric($endpoint_key)) {
190
+						continue;
191
+					}
192
+					if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) {
193
+						throw new EE_Error(
194
+							esc_html__(
195
+								// @codingStandardsIgnoreStart
196
+								'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).',
197
+								// @codingStandardsIgnoreEnd
198
+								'event_espresso')
199
+						);
200
+					}
201
+					$callback = $data_for_single_endpoint['callback'];
202
+					$single_endpoint_args = array(
203
+						'methods' => $data_for_single_endpoint['methods'],
204
+						'args'    => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args']
205
+							: array(),
206
+					);
207
+					if (isset($data_for_single_endpoint['_links'])) {
208
+						$single_endpoint_args['_links'] = $data_for_single_endpoint['_links'];
209
+					}
210
+					if (isset($data_for_single_endpoint['callback_args'])) {
211
+						$callback_args = $data_for_single_endpoint['callback_args'];
212
+						$single_endpoint_args['callback'] = function (\WP_REST_Request $request) use (
213
+							$callback,
214
+							$callback_args
215
+						) {
216
+							array_unshift($callback_args, $request);
217
+							return call_user_func_array(
218
+								$callback,
219
+								$callback_args
220
+							);
221
+						};
222
+					} else {
223
+						$single_endpoint_args['callback'] = $data_for_single_endpoint['callback'];
224
+					}
225
+					$multiple_endpoint_args[] = $single_endpoint_args;
226
+				}
227
+				if (isset($data_for_multiple_endpoints['schema'])) {
228
+					$schema_route_data = $data_for_multiple_endpoints['schema'];
229
+					$schema_callback = $schema_route_data['schema_callback'];
230
+					$callback_args = $schema_route_data['callback_args'];
231
+					$multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) {
232
+						return call_user_func_array(
233
+							$schema_callback,
234
+							$callback_args
235
+						);
236
+					};
237
+				}
238
+				register_rest_route(
239
+					$namespace,
240
+					$relative_route,
241
+					$multiple_endpoint_args
242
+				);
243
+			}
244
+		}
245
+	}
246
+
247
+
248
+
249
+	/**
250
+	 * Checks if there was a version change or something that merits invalidating the cached
251
+	 * route data. If so, invalidates the cached route data so that it gets refreshed
252
+	 * next time the WP API is used
253
+	 */
254
+	public static function invalidate_cached_route_data_on_version_change()
255
+	{
256
+		if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) {
257
+			EED_Core_Rest_Api::invalidate_cached_route_data();
258
+		}
259
+		foreach (EE_Registry::instance()->addons as $addon) {
260
+			if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) {
261
+				EED_Core_Rest_Api::invalidate_cached_route_data();
262
+			}
263
+		}
264
+	}
265
+
266
+
267
+
268
+	/**
269
+	 * Removes the cached route data so it will get refreshed next time the WP API is used
270
+	 */
271
+	public static function invalidate_cached_route_data()
272
+	{
273
+		//delete the saved EE REST API routes
274
+		foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
275
+			delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
276
+		}
277
+	}
278
+
279
+
280
+
281
+	/**
282
+	 * Gets the EE route data
283
+	 *
284
+	 * @return array top-level key is the namespace, next-level key is the route and its value is array{
285
+	 * @throws \EE_Error
286
+	 * @type string|array $callback
287
+	 * @type string       $methods
288
+	 * @type boolean      $hidden_endpoint
289
+	 * }
290
+	 */
291
+	public static function get_ee_route_data()
292
+	{
293
+		$ee_routes = array();
294
+		foreach (self::versions_served() as $version => $hidden_endpoints) {
295
+			$ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version(
296
+				$version,
297
+				$hidden_endpoints
298
+			);
299
+		}
300
+		return $ee_routes;
301
+	}
302
+
303
+
304
+
305
+	/**
306
+	 * Gets the EE route data from the wp options if it exists already,
307
+	 * otherwise re-generates it and saves it to the option
308
+	 *
309
+	 * @param string  $version
310
+	 * @param boolean $hidden_endpoints
311
+	 * @return array
312
+	 * @throws \EE_Error
313
+	 */
314
+	protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
315
+	{
316
+		$ee_routes = get_option(self::saved_routes_option_names . $version, null);
317
+		if (! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
318
+			$ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
319
+		}
320
+		return $ee_routes;
321
+	}
322
+
323
+
324
+
325
+	/**
326
+	 * Saves the EE REST API route data to a wp option and returns it
327
+	 *
328
+	 * @param string  $version
329
+	 * @param boolean $hidden_endpoints
330
+	 * @return mixed|null
331
+	 * @throws \EE_Error
332
+	 */
333
+	protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false)
334
+	{
335
+		$instance = self::instance();
336
+		$routes = apply_filters(
337
+			'EED_Core_Rest_Api__save_ee_route_data_for_version__routes',
338
+			array_replace_recursive(
339
+				$instance->_get_config_route_data_for_version($version, $hidden_endpoints),
340
+				$instance->_get_meta_route_data_for_version($version, $hidden_endpoints),
341
+				$instance->_get_model_route_data_for_version($version, $hidden_endpoints),
342
+				$instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
343
+			)
344
+		);
345
+		$option_name = self::saved_routes_option_names . $version;
346
+		if (get_option($option_name)) {
347
+			update_option($option_name, $routes, true);
348
+		} else {
349
+			add_option($option_name, $routes, null, 'no');
350
+		}
351
+		return $routes;
352
+	}
353
+
354
+
355
+
356
+	/**
357
+	 * Calculates all the EE routes and saves it to a WordPress option so we don't
358
+	 * need to calculate it on every request
359
+	 *
360
+	 * @deprecated since version 4.9.1
361
+	 * @return void
362
+	 */
363
+	public static function save_ee_routes()
364
+	{
365
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
366
+			$instance = self::instance();
367
+			$routes = apply_filters(
368
+				'EED_Core_Rest_Api__save_ee_routes__routes',
369
+				array_replace_recursive(
370
+					$instance->_register_config_routes(),
371
+					$instance->_register_meta_routes(),
372
+					$instance->_register_model_routes(),
373
+					$instance->_register_rpc_routes()
374
+				)
375
+			);
376
+			update_option(self::saved_routes_option_names, $routes, true);
377
+		}
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 * Gets all the route information relating to EE models
384
+	 *
385
+	 * @return array @see get_ee_route_data
386
+	 * @deprecated since version 4.9.1
387
+	 */
388
+	protected function _register_model_routes()
389
+	{
390
+		$model_routes = array();
391
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
392
+			$model_routes[EED_Core_Rest_Api::ee_api_namespace
393
+						  . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
394
+		}
395
+		return $model_routes;
396
+	}
397
+
398
+
399
+
400
+	/**
401
+	 * Decides whether or not to add write endpoints for this model.
402
+	 *
403
+	 * Currently, this defaults to exclude all global tables and models
404
+	 * which would allow inserting WP core data (we don't want to duplicate
405
+	 * what WP API does, as it's unnecessary, extra work, and potentially extra bugs)
406
+	 * @param EEM_Base $model
407
+	 * @return bool
408
+	 */
409
+	public static function should_have_write_endpoints(EEM_Base $model)
410
+	{
411
+		if ($model->is_wp_core_model()){
412
+			return false;
413
+		}
414
+		foreach($model->get_tables() as $table){
415
+			if( $table->is_global()){
416
+				return false;
417
+			}
418
+		}
419
+		return true;
420
+	}
421
+
422
+
423
+
424
+	/**
425
+	 * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`)
426
+	 * in this versioned namespace of EE4
427
+	 * @param $version
428
+	 * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event')
429
+	 */
430
+	public static function model_names_with_plural_routes($version){
431
+		$model_version_info = new ModelVersionInfo($version);
432
+		$models_to_register = $model_version_info->modelsForRequestedVersion();
433
+		//let's not bother having endpoints for extra metas
434
+		unset(
435
+			$models_to_register['Extra_Meta'],
436
+			$models_to_register['Extra_Join'],
437
+			$models_to_register['Post_Meta']
438
+		);
439
+		return apply_filters(
440
+			'FHEE__EED_Core_REST_API___register_model_routes',
441
+			$models_to_register
442
+		);
443
+	}
444
+
445
+
446
+
447
+	/**
448
+	 * Gets the route data for EE models in the specified version
449
+	 *
450
+	 * @param string  $version
451
+	 * @param boolean $hidden_endpoint
452
+	 * @return array
453
+	 * @throws EE_Error
454
+	 */
455
+	protected function _get_model_route_data_for_version($version, $hidden_endpoint = false)
456
+	{
457
+		$model_routes = array();
458
+		$model_version_info = new ModelVersionInfo($version);
459
+		foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) {
460
+			$model = \EE_Registry::instance()->load_model($model_name);
461
+			//if this isn't a valid model then let's skip iterate to the next item in the loop.
462
+			if (! $model instanceof EEM_Base) {
463
+				continue;
464
+			}
465
+			//yes we could just register one route for ALL models, but then they wouldn't show up in the index
466
+			$plural_model_route = EED_Core_Rest_Api::get_collection_route($model);
467
+			$singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)');
468
+			$model_routes[$plural_model_route] = array(
469
+				array(
470
+					'callback'        => array(
471
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
472
+						'handleRequestGetAll',
473
+					),
474
+					'callback_args'   => array($version, $model_name),
475
+					'methods'         => WP_REST_Server::READABLE,
476
+					'hidden_endpoint' => $hidden_endpoint,
477
+					'args'            => $this->_get_read_query_params($model, $version),
478
+					'_links'          => array(
479
+						'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
480
+					),
481
+				),
482
+				'schema' => array(
483
+					'schema_callback' => array(
484
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
485
+						'handleSchemaRequest',
486
+					),
487
+					'callback_args'   => array($version, $model_name),
488
+				),
489
+			);
490
+			$model_routes[$singular_model_route] = array(
491
+				array(
492
+					'callback'        => array(
493
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
494
+						'handleRequestGetOne',
495
+					),
496
+					'callback_args'   => array($version, $model_name),
497
+					'methods'         => WP_REST_Server::READABLE,
498
+					'hidden_endpoint' => $hidden_endpoint,
499
+					'args'            => $this->_get_response_selection_query_params($model, $version),
500
+				),
501
+			);
502
+			if( apply_filters(
503
+				'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints',
504
+				EED_Core_Rest_Api::should_have_write_endpoints($model),
505
+				$model
506
+			)){
507
+				$model_routes[$plural_model_route][] = array(
508
+					'callback'        => array(
509
+						'EventEspresso\core\libraries\rest_api\controllers\model\Write',
510
+						'handleRequestInsert',
511
+					),
512
+					'callback_args'   => array($version, $model_name),
513
+					'methods'         => WP_REST_Server::CREATABLE,
514
+					'hidden_endpoint' => $hidden_endpoint,
515
+					'args'            => $this->_get_write_params($model_name, $model_version_info, true),
516
+				);
517
+				$model_routes[$singular_model_route] = array_merge(
518
+					$model_routes[$singular_model_route],
519
+					array(
520
+						array(
521
+							'callback'        => array(
522
+								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
523
+								'handleRequestUpdate',
524
+							),
525
+							'callback_args'   => array($version, $model_name),
526
+							'methods'         => WP_REST_Server::EDITABLE,
527
+							'hidden_endpoint' => $hidden_endpoint,
528
+							'args'            => $this->_get_write_params($model_name, $model_version_info),
529
+						),
530
+						array(
531
+							'callback'        => array(
532
+								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
533
+								'handleRequestDelete',
534
+							),
535
+							'callback_args'   => array($version, $model_name),
536
+							'methods'         => WP_REST_Server::DELETABLE,
537
+							'hidden_endpoint' => $hidden_endpoint,
538
+							'args'            => $this->_get_delete_query_params($model, $version),
539
+						)
540
+					)
541
+				);
542
+			}
543
+			foreach ($model->relation_settings() as $relation_name => $relation_obj) {
544
+
545
+				$related_route = EED_Core_Rest_Api::get_relation_route_via(
546
+					$model,
547
+					'(?P<id>[^\/]+)',
548
+					$relation_obj
549
+				);
550
+				$endpoints = array(
551
+					array(
552
+						'callback'        => array(
553
+							'EventEspresso\core\libraries\rest_api\controllers\model\Read',
554
+							'handleRequestGetRelated',
555
+						),
556
+						'callback_args'   => array($version, $model_name, $relation_name),
557
+						'methods'         => WP_REST_Server::READABLE,
558
+						'hidden_endpoint' => $hidden_endpoint,
559
+						'args'            => $this->_get_read_query_params($relation_obj->get_other_model(), $version),
560
+					),
561
+				);
562
+				$model_routes[$related_route] = $endpoints;
563
+			}
564
+		}
565
+		return $model_routes;
566
+	}
567
+
568
+
569
+
570
+	/**
571
+	 * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace,
572
+	 * excluding the preceding slash.
573
+	 * Eg you pass get_plural_route_to('Event') = 'events'
574
+	 *
575
+	 * @param EEM_Base $model
576
+	 * @return string
577
+	 */
578
+	public static function get_collection_route(EEM_Base $model)
579
+	{
580
+		return EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
581
+	}
582
+
583
+
584
+
585
+	/**
586
+	 * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
587
+	 * excluding the preceding slash.
588
+	 * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
589
+	 *
590
+	 * @param EEM_Base $model eg Event or Venue
591
+	 * @param string $id
592
+	 * @return string
593
+	 */
594
+	public static function get_entity_route($model, $id)
595
+	{
596
+		return EED_Core_Rest_Api::get_collection_route($model). '/' . $id;
597
+	}
598
+
599
+
600
+	/**
601
+	 * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
602
+	 * excluding the preceding slash.
603
+	 * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
604
+	 *
605
+	 * @param EEM_Base                 $model eg Event or Venue
606
+	 * @param string                 $id
607
+	 * @param EE_Model_Relation_Base $relation_obj
608
+	 * @return string
609
+	 */
610
+	public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj)
611
+	{
612
+		$related_model_name_endpoint_part = ModelRead::getRelatedEntityName(
613
+			$relation_obj->get_other_model()->get_this_model_name(),
614
+			$relation_obj
615
+		);
616
+		return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part;
617
+	}
618
+
619
+
620
+
621
+	/**
622
+	 * Adds onto the $relative_route the EE4 REST API versioned namespace.
623
+	 * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events'
624
+	 * @param string $relative_route
625
+	 * @param string $version
626
+	 * @return string
627
+	 */
628
+	public static function get_versioned_route_to($relative_route, $version = '4.8.36'){
629
+		return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route;
630
+	}
631
+
632
+
633
+
634
+	/**
635
+	 * Adds all the RPC-style routes (remote procedure call-like routes, ie
636
+	 * routes that don't conform to the traditional REST CRUD-style).
637
+	 *
638
+	 * @deprecated since 4.9.1
639
+	 */
640
+	protected function _register_rpc_routes()
641
+	{
642
+		$routes = array();
643
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
644
+			$routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version(
645
+				$version,
646
+				$hidden_endpoint
647
+			);
648
+		}
649
+		return $routes;
650
+	}
651
+
652
+
653
+
654
+	/**
655
+	 * @param string  $version
656
+	 * @param boolean $hidden_endpoint
657
+	 * @return array
658
+	 */
659
+	protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false)
660
+	{
661
+		$this_versions_routes = array();
662
+		//checkin endpoint
663
+		$this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array(
664
+			array(
665
+				'callback'        => array(
666
+					'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin',
667
+					'handleRequestToggleCheckin',
668
+				),
669
+				'methods'         => WP_REST_Server::CREATABLE,
670
+				'hidden_endpoint' => $hidden_endpoint,
671
+				'args'            => array(
672
+					'force' => array(
673
+						'required'    => false,
674
+						'default'     => false,
675
+						'description' => __(
676
+							// @codingStandardsIgnoreStart
677
+							'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses',
678
+							// @codingStandardsIgnoreEnd
679
+							'event_espresso'
680
+						),
681
+					),
682
+				),
683
+				'callback_args'   => array($version),
684
+			),
685
+		);
686
+		return apply_filters(
687
+			'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
688
+			$this_versions_routes,
689
+			$version,
690
+			$hidden_endpoint
691
+		);
692
+	}
693
+
694
+
695
+
696
+	/**
697
+	 * Gets the query params that can be used when request one or many
698
+	 *
699
+	 * @param EEM_Base $model
700
+	 * @param string   $version
701
+	 * @return array
702
+	 */
703
+	protected function _get_response_selection_query_params(\EEM_Base $model, $version)
704
+	{
705
+		return apply_filters(
706
+			'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
707
+			array(
708
+				'include'   => array(
709
+					'required' => false,
710
+					'default'  => '*',
711
+					'type'     => 'string',
712
+				),
713
+				'calculate' => array(
714
+					'required'          => false,
715
+					'default'           => '',
716
+					'enum'              => self::$_field_calculator->retrieveCalculatedFieldsForModel($model),
717
+					'type'              => 'string',
718
+					//because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization
719
+					//freaks out. We'll just validate this argument while handling the request
720
+					'validate_callback' => null,
721
+					'sanitize_callback' => null,
722
+				),
723
+			),
724
+			$model,
725
+			$version
726
+		);
727
+	}
728
+
729
+
730
+
731
+	/**
732
+	 * Gets the parameters acceptable for delete requests
733
+	 *
734
+	 * @param \EEM_Base $model
735
+	 * @param string    $version
736
+	 * @return array
737
+	 */
738
+	protected function _get_delete_query_params(\EEM_Base $model, $version)
739
+	{
740
+		$params_for_delete = array(
741
+			'allow_blocking' => array(
742
+				'required' => false,
743
+				'default'  => true,
744
+				'type'     => 'boolean',
745
+			),
746
+		);
747
+		$params_for_delete['force'] = array(
748
+			'required' => false,
749
+			'default'  => false,
750
+			'type'     => 'boolean',
751
+		);
752
+		return apply_filters(
753
+			'FHEE__EED_Core_Rest_Api___get_delete_query_params',
754
+			$params_for_delete,
755
+			$model,
756
+			$version
757
+		);
758
+	}
759
+
760
+
761
+
762
+	/**
763
+	 * Gets info about reading query params that are acceptable
764
+	 *
765
+	 * @param \EEM_Base $model eg 'Event' or 'Venue'
766
+	 * @param  string   $version
767
+	 * @return array    describing the args acceptable when querying this model
768
+	 * @throws EE_Error
769
+	 */
770
+	protected function _get_read_query_params(\EEM_Base $model, $version)
771
+	{
772
+		$default_orderby = array();
773
+		foreach ($model->get_combined_primary_key_fields() as $key_field) {
774
+			$default_orderby[$key_field->get_name()] = 'ASC';
775
+		}
776
+		return array_merge(
777
+			$this->_get_response_selection_query_params($model, $version),
778
+			array(
779
+				'where'    => array(
780
+					'required' => false,
781
+					'default'  => array(),
782
+					'type'     => 'object',
783
+					//because we accept an almost infinite list of possible where conditions, WP
784
+					// core validation and sanitization freaks out. We'll just validate this argument
785
+					// while handling the request
786
+					'validate_callback' => null,
787
+					'sanitize_callback' => null,
788
+				),
789
+				'limit'    => array(
790
+					'required' => false,
791
+					'default'  => EED_Core_Rest_Api::get_default_query_limit(),
792
+					'type'     => array(
793
+						'array',
794
+						'string',
795
+						'integer',
796
+					),
797
+					//because we accept a variety of types, WP core validation and sanitization
798
+					//freaks out. We'll just validate this argument while handling the request
799
+					'validate_callback' => null,
800
+					'sanitize_callback' => null,
801
+				),
802
+				'order_by' => array(
803
+					'required' => false,
804
+					'default'  => $default_orderby,
805
+					'type'     => array(
806
+						'object',
807
+						'string',
808
+					),//because we accept a variety of types, WP core validation and sanitization
809
+					//freaks out. We'll just validate this argument while handling the request
810
+					'validate_callback' => null,
811
+					'sanitize_callback' => null,
812
+				),
813
+				'group_by' => array(
814
+					'required' => false,
815
+					'default'  => null,
816
+					'type'     => array(
817
+						'object',
818
+						'string',
819
+					),
820
+					//because we accept  an almost infinite list of possible groupings,
821
+					// WP core validation and sanitization
822
+					//freaks out. We'll just validate this argument while handling the request
823
+					'validate_callback' => null,
824
+					'sanitize_callback' => null,
825
+				),
826
+				'having'   => array(
827
+					'required' => false,
828
+					'default'  => null,
829
+					'type'     => 'object',
830
+					//because we accept an almost infinite list of possible where conditions, WP
831
+					// core validation and sanitization freaks out. We'll just validate this argument
832
+					// while handling the request
833
+					'validate_callback' => null,
834
+					'sanitize_callback' => null,
835
+				),
836
+				'caps'     => array(
837
+					'required' => false,
838
+					'default'  => EEM_Base::caps_read,
839
+					'type'     => 'string',
840
+					'enum'     => array(
841
+						EEM_Base::caps_read,
842
+						EEM_Base::caps_read_admin,
843
+						EEM_Base::caps_edit,
844
+						EEM_Base::caps_delete
845
+					)
846
+				),
847
+			)
848
+		);
849
+	}
850
+
851
+
852
+
853
+	/**
854
+	 * Gets parameter information for a model regarding writing data
855
+	 *
856
+	 * @param string           $model_name
857
+	 * @param ModelVersionInfo $model_version_info
858
+	 * @param boolean          $create                                       whether this is for request to create (in which case we need
859
+	 *                                                                       all required params) or just to update (in which case we don't need those on every request)
860
+	 * @return array
861
+	 */
862
+	protected function _get_write_params(
863
+		$model_name,
864
+		ModelVersionInfo $model_version_info,
865
+		$create = false
866
+	) {
867
+		$model = EE_Registry::instance()->load_model($model_name);
868
+		$fields = $model_version_info->fieldsOnModelInThisVersion($model);
869
+		$args_info = array();
870
+		foreach ($fields as $field_name => $field_obj) {
871
+			if ($field_obj->is_auto_increment()) {
872
+				//totally ignore auto increment IDs
873
+				continue;
874
+			}
875
+			$arg_info = $field_obj->getSchema();
876
+			$required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null;
877
+			$arg_info['required'] = $required;
878
+			//remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right?
879
+			unset($arg_info['readonly']);
880
+			$schema_properties = $field_obj->getSchemaProperties();
881
+			if (
882
+				isset($schema_properties['raw'])
883
+				&& $field_obj->getSchemaType() === 'object'
884
+			) {
885
+				//if there's a "raw" form of this argument, use those properties instead
886
+				$arg_info = array_replace(
887
+					$arg_info,
888
+					$schema_properties['raw']
889
+				);
890
+			}
891
+			$arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson(
892
+				$field_obj,
893
+				$field_obj->get_default_value(),
894
+				$model_version_info->requestedVersion()
895
+			);
896
+			//we do our own validation and sanitization within the controller
897
+			if(function_exists('rest_validate_value_from_schema')){
898
+				$sanitize_callback = array(
899
+					'EED_Core_Rest_Api',
900
+					'default_sanitize_callback',
901
+				);
902
+			} else {
903
+				$sanitize_callback = null;
904
+			}
905
+			$arg_info['sanitize_callback'] = $sanitize_callback;
906
+			$args_info[$field_name] = $arg_info;
907
+			if ($field_obj instanceof EE_Datetime_Field) {
908
+				$gmt_arg_info = $arg_info;
909
+				$gmt_arg_info['description'] = sprintf(
910
+					esc_html__(
911
+						'%1$s - the value for this field in UTC. Ignored if %2$s is provided.',
912
+						'event_espresso'
913
+					),
914
+					$field_obj->get_nicename(),
915
+					$field_name
916
+				);
917
+				$args_info[$field_name . '_gmt'] = $gmt_arg_info;
918
+			}
919
+		}
920
+		return $args_info;
921
+	}
922
+
923
+
924
+
925
+	/**
926
+	 * Replacement for WP API's 'rest_parse_request_arg'.
927
+	 * If the value is blank but not required, don't bother validating it.
928
+	 * Also, it uses our email validation instead of WP API's default.
929
+	 *
930
+	 * @param                 $value
931
+	 * @param WP_REST_Request $request
932
+	 * @param                 $param
933
+	 * @return bool|true|WP_Error
934
+	 * @throws InvalidArgumentException
935
+	 * @throws InvalidInterfaceException
936
+	 * @throws InvalidDataTypeException
937
+	 */
938
+	public static function default_sanitize_callback( $value, WP_REST_Request $request, $param)
939
+	{
940
+		$attributes = $request->get_attributes();
941
+		if (! isset($attributes['args'][$param])
942
+			|| ! is_array($attributes['args'][$param])) {
943
+			$validation_result = true;
944
+		} else {
945
+			$args = $attributes['args'][$param];
946
+			if ((
947
+					$value === ''
948
+					|| $value === null
949
+				)
950
+				&& (! isset($args['required'])
951
+					|| $args['required'] === false
952
+				)
953
+			) {
954
+				//not required and not provided? that's cool
955
+				$validation_result = true;
956
+			} elseif (isset($args['format'])
957
+				&& $args['format'] === 'email'
958
+			) {
959
+				$validation_result = true;
960
+				if (! self::_validate_email($value)) {
961
+					$validation_result = new WP_Error(
962
+						'rest_invalid_param',
963
+						esc_html__(
964
+							'The email address is not valid or does not exist.',
965
+							'event_espresso'
966
+						)
967
+					);
968
+				}
969
+			} else {
970
+				$validation_result = rest_validate_value_from_schema($value, $args, $param);
971
+			}
972
+		}
973
+		if (is_wp_error($validation_result)) {
974
+			return $validation_result;
975
+		}
976
+		return rest_sanitize_request_arg($value, $request, $param);
977
+	}
978
+
979
+
980
+
981
+	/**
982
+	 * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email()
983
+	 *
984
+	 * @param $email
985
+	 * @return bool
986
+	 * @throws InvalidArgumentException
987
+	 * @throws InvalidInterfaceException
988
+	 * @throws InvalidDataTypeException
989
+	 */
990
+	protected static function _validate_email($email){
991
+		try {
992
+			EmailAddressFactory::create($email);
993
+			return true;
994
+		} catch (EmailValidationException $e) {
995
+			return false;
996
+		}
997
+	}
998
+
999
+
1000
+
1001
+	/**
1002
+	 * Gets routes for the config
1003
+	 *
1004
+	 * @return array @see _register_model_routes
1005
+	 * @deprecated since version 4.9.1
1006
+	 */
1007
+	protected function _register_config_routes()
1008
+	{
1009
+		$config_routes = array();
1010
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
1011
+			$config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version(
1012
+				$version,
1013
+				$hidden_endpoint
1014
+			);
1015
+		}
1016
+		return $config_routes;
1017
+	}
1018
+
1019
+
1020
+
1021
+	/**
1022
+	 * Gets routes for the config for the specified version
1023
+	 *
1024
+	 * @param string  $version
1025
+	 * @param boolean $hidden_endpoint
1026
+	 * @return array
1027
+	 */
1028
+	protected function _get_config_route_data_for_version($version, $hidden_endpoint)
1029
+	{
1030
+		return array(
1031
+			'config'    => array(
1032
+				array(
1033
+					'callback'        => array(
1034
+						'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1035
+						'handleRequest',
1036
+					),
1037
+					'methods'         => WP_REST_Server::READABLE,
1038
+					'hidden_endpoint' => $hidden_endpoint,
1039
+					'callback_args'   => array($version),
1040
+				),
1041
+			),
1042
+			'site_info' => array(
1043
+				array(
1044
+					'callback'        => array(
1045
+						'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1046
+						'handleRequestSiteInfo',
1047
+					),
1048
+					'methods'         => WP_REST_Server::READABLE,
1049
+					'hidden_endpoint' => $hidden_endpoint,
1050
+					'callback_args'   => array($version),
1051
+				),
1052
+			),
1053
+		);
1054
+	}
1055
+
1056
+
1057
+
1058
+	/**
1059
+	 * Gets the meta info routes
1060
+	 *
1061
+	 * @return array @see _register_model_routes
1062
+	 * @deprecated since version 4.9.1
1063
+	 */
1064
+	protected function _register_meta_routes()
1065
+	{
1066
+		$meta_routes = array();
1067
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
1068
+			$meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version(
1069
+				$version,
1070
+				$hidden_endpoint
1071
+			);
1072
+		}
1073
+		return $meta_routes;
1074
+	}
1075
+
1076
+
1077
+
1078
+	/**
1079
+	 * @param string  $version
1080
+	 * @param boolean $hidden_endpoint
1081
+	 * @return array
1082
+	 */
1083
+	protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false)
1084
+	{
1085
+		return array(
1086
+			'resources' => array(
1087
+				array(
1088
+					'callback'        => array(
1089
+						'EventEspresso\core\libraries\rest_api\controllers\model\Meta',
1090
+						'handleRequestModelsMeta',
1091
+					),
1092
+					'methods'         => WP_REST_Server::READABLE,
1093
+					'hidden_endpoint' => $hidden_endpoint,
1094
+					'callback_args'   => array($version),
1095
+				),
1096
+			),
1097
+		);
1098
+	}
1099
+
1100
+
1101
+
1102
+	/**
1103
+	 * Tries to hide old 4.6 endpoints from the
1104
+	 *
1105
+	 * @param array $route_data
1106
+	 * @return array
1107
+	 * @throws \EE_Error
1108
+	 */
1109
+	public static function hide_old_endpoints($route_data)
1110
+	{
1111
+		//allow API clients to override which endpoints get hidden, in case
1112
+		//they want to discover particular endpoints
1113
+		//also, we don't have access to the request so we have to just grab it from the superglobal
1114
+		$force_show_ee_namespace = ltrim(
1115
+			EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''),
1116
+			'/'
1117
+		);
1118
+		foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
1119
+			foreach ($relative_urls as $resource_name => $endpoints) {
1120
+				foreach ($endpoints as $key => $endpoint) {
1121
+					//skip schema and other route options
1122
+					if (! is_numeric($key)) {
1123
+						continue;
1124
+					}
1125
+					//by default, hide "hidden_endpoint"s, unless the request indicates
1126
+					//to $force_show_ee_namespace, in which case only show that one
1127
+					//namespace's endpoints (and hide all others)
1128
+					if (
1129
+						($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
1130
+						|| ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '')
1131
+					) {
1132
+						$full_route = '/' . ltrim($namespace, '/');
1133
+						$full_route .= '/' . ltrim($resource_name, '/');
1134
+						unset($route_data[$full_route]);
1135
+					}
1136
+				}
1137
+			}
1138
+		}
1139
+		return $route_data;
1140
+	}
1141
+
1142
+
1143
+
1144
+	/**
1145
+	 * Returns an array describing which versions of core support serving requests for.
1146
+	 * Keys are core versions' major and minor version, and values are the
1147
+	 * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like
1148
+	 * data by just removing a few models and fields from the responses. However, 4.15 might remove
1149
+	 * the answers table entirely, in which case it would be very difficult for
1150
+	 * it to serve 4.6-style responses.
1151
+	 * Versions of core that are missing from this array are unknowns.
1152
+	 * previous ver
1153
+	 *
1154
+	 * @return array
1155
+	 */
1156
+	public static function version_compatibilities()
1157
+	{
1158
+		return apply_filters(
1159
+			'FHEE__EED_Core_REST_API__version_compatibilities',
1160
+			array(
1161
+				'4.8.29' => '4.8.29',
1162
+				'4.8.33' => '4.8.29',
1163
+				'4.8.34' => '4.8.29',
1164
+				'4.8.36' => '4.8.29',
1165
+			)
1166
+		);
1167
+	}
1168
+
1169
+
1170
+
1171
+	/**
1172
+	 * Gets the latest API version served. Eg if there
1173
+	 * are two versions served of the API, 4.8.29 and 4.8.32, and
1174
+	 * we are on core version 4.8.34, it will return the string "4.8.32"
1175
+	 *
1176
+	 * @return string
1177
+	 */
1178
+	public static function latest_rest_api_version()
1179
+	{
1180
+		$versions_served = \EED_Core_Rest_Api::versions_served();
1181
+		$versions_served_keys = array_keys($versions_served);
1182
+		return end($versions_served_keys);
1183
+	}
1184
+
1185
+
1186
+
1187
+	/**
1188
+	 * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of
1189
+	 * EE the API can serve requests for. Eg, if we are on 4.15 of core, and
1190
+	 * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ).
1191
+	 * We also indicate whether or not this version should be put in the index or not
1192
+	 *
1193
+	 * @return array keys are API version numbers (just major and minor numbers), and values
1194
+	 * are whether or not they should be hidden
1195
+	 */
1196
+	public static function versions_served()
1197
+	{
1198
+		$versions_served = array();
1199
+		$possibly_served_versions = EED_Core_Rest_Api::version_compatibilities();
1200
+		$lowest_compatible_version = end($possibly_served_versions);
1201
+		reset($possibly_served_versions);
1202
+		$versions_served_historically = array_keys($possibly_served_versions);
1203
+		$latest_version = end($versions_served_historically);
1204
+		reset($versions_served_historically);
1205
+		//for each version of core we have ever served:
1206
+		foreach ($versions_served_historically as $key_versioned_endpoint) {
1207
+			//if it's not above the current core version, and it's compatible with the current version of core
1208
+			if ($key_versioned_endpoint === $latest_version) {
1209
+				//don't hide the latest version in the index
1210
+				$versions_served[$key_versioned_endpoint] = false;
1211
+			} elseif (
1212
+				$key_versioned_endpoint >= $lowest_compatible_version
1213
+				&& $key_versioned_endpoint < EED_Core_Rest_Api::core_version()
1214
+			) {
1215
+				//include, but hide, previous versions which are still supported
1216
+				$versions_served[$key_versioned_endpoint] = true;
1217
+			} elseif (apply_filters(
1218
+				'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
1219
+				false,
1220
+				$possibly_served_versions
1221
+			)) {
1222
+				//if a version is no longer supported, don't include it in index or list of versions served
1223
+				$versions_served[$key_versioned_endpoint] = true;
1224
+			}
1225
+		}
1226
+		return $versions_served;
1227
+	}
1228
+
1229
+
1230
+
1231
+	/**
1232
+	 * Gets the major and minor version of EE core's version string
1233
+	 *
1234
+	 * @return string
1235
+	 */
1236
+	public static function core_version()
1237
+	{
1238
+		return apply_filters(
1239
+			'FHEE__EED_Core_REST_API__core_version',
1240
+			implode(
1241
+				'.',
1242
+				array_slice(
1243
+					explode(
1244
+						'.',
1245
+						espresso_version()
1246
+					),
1247
+				0,
1248
+				3
1249
+				)
1250
+			)
1251
+		);
1252
+	}
1253
+
1254
+
1255
+
1256
+	/**
1257
+	 * Gets the default limit that should be used when querying for resources
1258
+	 *
1259
+	 * @return int
1260
+	 */
1261
+	public static function get_default_query_limit()
1262
+	{
1263
+		//we actually don't use a const because we want folks to always use
1264
+		//this method, not the const directly
1265
+		return apply_filters(
1266
+			'FHEE__EED_Core_Rest_Api__get_default_query_limit',
1267
+			50
1268
+		);
1269
+	}
1270
+
1271
+
1272
+	/**
1273
+	 *
1274
+	 * @param string $version api version string (i.e. '4.8.36')
1275
+	 * @return array
1276
+	 */
1277
+	public static function getCollectionRoutesIndexedByModelName($version = '')
1278
+	{
1279
+		$version = empty($version) ? self::latest_rest_api_version() : $version;
1280
+		$model_names = self::model_names_with_plural_routes($version);
1281
+		$collection_routes = array();
1282
+		foreach ($model_names as $model_name => $model_class_name) {
1283
+			$collection_routes[strtolower($model_name)] = '/' . self::ee_api_namespace . $version . '/'
1284
+														  . EEH_Inflector::pluralize_and_lower($model_name);
1285
+
1286
+		}
1287
+		return $collection_routes;
1288
+	}
1289
+
1290
+
1291
+
1292
+	/**
1293
+	 *    run - initial module setup
1294
+	 *
1295
+	 * @access    public
1296
+	 * @param  WP $WP
1297
+	 * @return    void
1298
+	 */
1299
+	public function run($WP)
1300
+	{
1301
+	}
1302 1302
 }
1303 1303
 
1304 1304
 // End of file EED_Core_Rest_Api.module.php
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      */
132 132
     protected static function _set_hooks_for_changes()
133 133
     {
134
-        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
134
+        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES.'rest_api'.DS.'changes'), false);
135 135
         foreach ($folder_contents as $classname_in_namespace => $filepath) {
136 136
             //ignore the base parent class
137 137
             //and legacy named classes
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
             ) {
141 141
                 continue;
142 142
             }
143
-            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
143
+            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\'.$classname_in_namespace;
144 144
             if (class_exists($full_classname)) {
145 145
                 $instance_of_class = new $full_classname;
146 146
                 if ($instance_of_class instanceof ChangesInBase) {
@@ -186,10 +186,10 @@  discard block
 block discarded – undo
186 186
                      * }
187 187
                      */
188 188
                     //skip route options
189
-                    if (! is_numeric($endpoint_key)) {
189
+                    if ( ! is_numeric($endpoint_key)) {
190 190
                         continue;
191 191
                     }
192
-                    if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) {
192
+                    if ( ! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) {
193 193
                         throw new EE_Error(
194 194
                             esc_html__(
195 195
                                 // @codingStandardsIgnoreStart
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
                     }
210 210
                     if (isset($data_for_single_endpoint['callback_args'])) {
211 211
                         $callback_args = $data_for_single_endpoint['callback_args'];
212
-                        $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use (
212
+                        $single_endpoint_args['callback'] = function(\WP_REST_Request $request) use (
213 213
                             $callback,
214 214
                             $callback_args
215 215
                         ) {
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
                     $schema_route_data = $data_for_multiple_endpoints['schema'];
229 229
                     $schema_callback = $schema_route_data['schema_callback'];
230 230
                     $callback_args = $schema_route_data['callback_args'];
231
-                    $multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) {
231
+                    $multiple_endpoint_args['schema'] = function() use ($schema_callback, $callback_args) {
232 232
                         return call_user_func_array(
233 233
                             $schema_callback,
234 234
                             $callback_args
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
     {
273 273
         //delete the saved EE REST API routes
274 274
         foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
275
-            delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
275
+            delete_option(EED_Core_Rest_Api::saved_routes_option_names.$version);
276 276
         }
277 277
     }
278 278
 
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
     {
293 293
         $ee_routes = array();
294 294
         foreach (self::versions_served() as $version => $hidden_endpoints) {
295
-            $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version(
295
+            $ee_routes[self::ee_api_namespace.$version] = self::_get_ee_route_data_for_version(
296 296
                 $version,
297 297
                 $hidden_endpoints
298 298
             );
@@ -313,8 +313,8 @@  discard block
 block discarded – undo
313 313
      */
314 314
     protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
315 315
     {
316
-        $ee_routes = get_option(self::saved_routes_option_names . $version, null);
317
-        if (! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
316
+        $ee_routes = get_option(self::saved_routes_option_names.$version, null);
317
+        if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
318 318
             $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
319 319
         }
320 320
         return $ee_routes;
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
                 $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
343 343
             )
344 344
         );
345
-        $option_name = self::saved_routes_option_names . $version;
345
+        $option_name = self::saved_routes_option_names.$version;
346 346
         if (get_option($option_name)) {
347 347
             update_option($option_name, $routes, true);
348 348
         } else {
@@ -408,11 +408,11 @@  discard block
 block discarded – undo
408 408
      */
409 409
     public static function should_have_write_endpoints(EEM_Base $model)
410 410
     {
411
-        if ($model->is_wp_core_model()){
411
+        if ($model->is_wp_core_model()) {
412 412
             return false;
413 413
         }
414
-        foreach($model->get_tables() as $table){
415
-            if( $table->is_global()){
414
+        foreach ($model->get_tables() as $table) {
415
+            if ($table->is_global()) {
416 416
                 return false;
417 417
             }
418 418
         }
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
      * @param $version
428 428
      * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event')
429 429
      */
430
-    public static function model_names_with_plural_routes($version){
430
+    public static function model_names_with_plural_routes($version) {
431 431
         $model_version_info = new ModelVersionInfo($version);
432 432
         $models_to_register = $model_version_info->modelsForRequestedVersion();
433 433
         //let's not bother having endpoints for extra metas
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
         foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) {
460 460
             $model = \EE_Registry::instance()->load_model($model_name);
461 461
             //if this isn't a valid model then let's skip iterate to the next item in the loop.
462
-            if (! $model instanceof EEM_Base) {
462
+            if ( ! $model instanceof EEM_Base) {
463 463
                 continue;
464 464
             }
465 465
             //yes we could just register one route for ALL models, but then they wouldn't show up in the index
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
                     'hidden_endpoint' => $hidden_endpoint,
477 477
                     'args'            => $this->_get_read_query_params($model, $version),
478 478
                     '_links'          => array(
479
-                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
479
+                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace.$version.$singular_model_route),
480 480
                     ),
481 481
                 ),
482 482
                 'schema' => array(
@@ -499,11 +499,11 @@  discard block
 block discarded – undo
499 499
                     'args'            => $this->_get_response_selection_query_params($model, $version),
500 500
                 ),
501 501
             );
502
-            if( apply_filters(
502
+            if (apply_filters(
503 503
                 'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints',
504 504
                 EED_Core_Rest_Api::should_have_write_endpoints($model),
505 505
                 $model
506
-            )){
506
+            )) {
507 507
                 $model_routes[$plural_model_route][] = array(
508 508
                     'callback'        => array(
509 509
                         'EventEspresso\core\libraries\rest_api\controllers\model\Write',
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
      */
594 594
     public static function get_entity_route($model, $id)
595 595
     {
596
-        return EED_Core_Rest_Api::get_collection_route($model). '/' . $id;
596
+        return EED_Core_Rest_Api::get_collection_route($model).'/'.$id;
597 597
     }
598 598
 
599 599
 
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
             $relation_obj->get_other_model()->get_this_model_name(),
614 614
             $relation_obj
615 615
         );
616
-        return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part;
616
+        return EED_Core_Rest_Api::get_entity_route($model, $id).'/'.$related_model_name_endpoint_part;
617 617
     }
618 618
 
619 619
 
@@ -625,8 +625,8 @@  discard block
 block discarded – undo
625 625
      * @param string $version
626 626
      * @return string
627 627
      */
628
-    public static function get_versioned_route_to($relative_route, $version = '4.8.36'){
629
-        return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route;
628
+    public static function get_versioned_route_to($relative_route, $version = '4.8.36') {
629
+        return '/'.EED_Core_Rest_Api::ee_api_namespace.$version.'/'.$relative_route;
630 630
     }
631 631
 
632 632
 
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
     {
642 642
         $routes = array();
643 643
         foreach (self::versions_served() as $version => $hidden_endpoint) {
644
-            $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version(
644
+            $routes[self::ee_api_namespace.$version] = $this->_get_rpc_route_data_for_version(
645 645
                 $version,
646 646
                 $hidden_endpoint
647 647
             );
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
                     'type'     => array(
806 806
                         'object',
807 807
                         'string',
808
-                    ),//because we accept a variety of types, WP core validation and sanitization
808
+                    ), //because we accept a variety of types, WP core validation and sanitization
809 809
                     //freaks out. We'll just validate this argument while handling the request
810 810
                     'validate_callback' => null,
811 811
                     'sanitize_callback' => null,
@@ -894,7 +894,7 @@  discard block
 block discarded – undo
894 894
                 $model_version_info->requestedVersion()
895 895
             );
896 896
             //we do our own validation and sanitization within the controller
897
-            if(function_exists('rest_validate_value_from_schema')){
897
+            if (function_exists('rest_validate_value_from_schema')) {
898 898
                 $sanitize_callback = array(
899 899
                     'EED_Core_Rest_Api',
900 900
                     'default_sanitize_callback',
@@ -914,7 +914,7 @@  discard block
 block discarded – undo
914 914
                     $field_obj->get_nicename(),
915 915
                     $field_name
916 916
                 );
917
-                $args_info[$field_name . '_gmt'] = $gmt_arg_info;
917
+                $args_info[$field_name.'_gmt'] = $gmt_arg_info;
918 918
             }
919 919
         }
920 920
         return $args_info;
@@ -935,10 +935,10 @@  discard block
 block discarded – undo
935 935
      * @throws InvalidInterfaceException
936 936
      * @throws InvalidDataTypeException
937 937
      */
938
-    public static function default_sanitize_callback( $value, WP_REST_Request $request, $param)
938
+    public static function default_sanitize_callback($value, WP_REST_Request $request, $param)
939 939
     {
940 940
         $attributes = $request->get_attributes();
941
-        if (! isset($attributes['args'][$param])
941
+        if ( ! isset($attributes['args'][$param])
942 942
             || ! is_array($attributes['args'][$param])) {
943 943
             $validation_result = true;
944 944
         } else {
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
                     $value === ''
948 948
                     || $value === null
949 949
                 )
950
-                && (! isset($args['required'])
950
+                && ( ! isset($args['required'])
951 951
                     || $args['required'] === false
952 952
                 )
953 953
             ) {
@@ -957,7 +957,7 @@  discard block
 block discarded – undo
957 957
                 && $args['format'] === 'email'
958 958
             ) {
959 959
                 $validation_result = true;
960
-                if (! self::_validate_email($value)) {
960
+                if ( ! self::_validate_email($value)) {
961 961
                     $validation_result = new WP_Error(
962 962
                         'rest_invalid_param',
963 963
                         esc_html__(
@@ -987,7 +987,7 @@  discard block
 block discarded – undo
987 987
      * @throws InvalidInterfaceException
988 988
      * @throws InvalidDataTypeException
989 989
      */
990
-    protected static function _validate_email($email){
990
+    protected static function _validate_email($email) {
991 991
         try {
992 992
             EmailAddressFactory::create($email);
993 993
             return true;
@@ -1008,7 +1008,7 @@  discard block
 block discarded – undo
1008 1008
     {
1009 1009
         $config_routes = array();
1010 1010
         foreach (self::versions_served() as $version => $hidden_endpoint) {
1011
-            $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version(
1011
+            $config_routes[self::ee_api_namespace.$version] = $this->_get_config_route_data_for_version(
1012 1012
                 $version,
1013 1013
                 $hidden_endpoint
1014 1014
             );
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
     {
1066 1066
         $meta_routes = array();
1067 1067
         foreach (self::versions_served() as $version => $hidden_endpoint) {
1068
-            $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version(
1068
+            $meta_routes[self::ee_api_namespace.$version] = $this->_get_meta_route_data_for_version(
1069 1069
                 $version,
1070 1070
                 $hidden_endpoint
1071 1071
             );
@@ -1119,7 +1119,7 @@  discard block
 block discarded – undo
1119 1119
             foreach ($relative_urls as $resource_name => $endpoints) {
1120 1120
                 foreach ($endpoints as $key => $endpoint) {
1121 1121
                     //skip schema and other route options
1122
-                    if (! is_numeric($key)) {
1122
+                    if ( ! is_numeric($key)) {
1123 1123
                         continue;
1124 1124
                     }
1125 1125
                     //by default, hide "hidden_endpoint"s, unless the request indicates
@@ -1129,8 +1129,8 @@  discard block
 block discarded – undo
1129 1129
                         ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
1130 1130
                         || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '')
1131 1131
                     ) {
1132
-                        $full_route = '/' . ltrim($namespace, '/');
1133
-                        $full_route .= '/' . ltrim($resource_name, '/');
1132
+                        $full_route = '/'.ltrim($namespace, '/');
1133
+                        $full_route .= '/'.ltrim($resource_name, '/');
1134 1134
                         unset($route_data[$full_route]);
1135 1135
                     }
1136 1136
                 }
@@ -1280,7 +1280,7 @@  discard block
 block discarded – undo
1280 1280
         $model_names = self::model_names_with_plural_routes($version);
1281 1281
         $collection_routes = array();
1282 1282
         foreach ($model_names as $model_name => $model_class_name) {
1283
-            $collection_routes[strtolower($model_name)] = '/' . self::ee_api_namespace . $version . '/'
1283
+            $collection_routes[strtolower($model_name)] = '/'.self::ee_api_namespace.$version.'/'
1284 1284
                                                           . EEH_Inflector::pluralize_and_lower($model_name);
1285 1285
 
1286 1286
         }
Please login to merge, or discard this patch.
core/services/collections/Collection.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
      *
157 157
      * @access public
158 158
      * @param mixed $identifier
159
-     * @return mixed
159
+     * @return boolean
160 160
      */
161 161
     public function get($identifier)
162 162
     {
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
      * advances pointer to the provided object
279 279
      *
280 280
      * @access public
281
-     * @param $object
281
+     * @param \EventEspresso\core\libraries\form_sections\form_handlers\SequentialStepForm $object
282 282
      * @return boolean
283 283
      */
284 284
     public function setCurrentUsingObject($object)
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
      *
317 317
      * @see http://stackoverflow.com/a/8736013
318 318
      * @param $object
319
-     * @return boolean|int|string
319
+     * @return integer
320 320
      */
321 321
     public function indexOf($object)
322 322
     {
Please login to merge, or discard this patch.
Indentation   +422 added lines, -422 removed lines patch added patch discarded remove patch
@@ -19,426 +19,426 @@
 block discarded – undo
19 19
 class Collection extends SplObjectStorage implements CollectionInterface
20 20
 {
21 21
 
22
-    /**
23
-     * a unique string for identifying this collection
24
-     *
25
-     * @type string $collection_identifier
26
-     */
27
-    protected $collection_identifier;
28
-
29
-
30
-    /**
31
-     * an interface (or class) name to be used for restricting the type of objects added to the storage
32
-     * this should be set from within the child class constructor
33
-     *
34
-     * @type string $interface
35
-     */
36
-    protected $collection_interface;
37
-
38
-
39
-    /**
40
-     * Collection constructor
41
-     *
42
-     * @param string $collection_interface
43
-     * @throws InvalidInterfaceException
44
-     */
45
-    public function __construct($collection_interface)
46
-    {
47
-        $this->setCollectionInterface($collection_interface);
48
-        $this->setCollectionIdentifier();
49
-    }
50
-
51
-
52
-    /**
53
-     * @return string
54
-     */
55
-    public function collectionIdentifier()
56
-    {
57
-        return $this->collection_identifier;
58
-    }
59
-
60
-
61
-    /**
62
-     * creates a very readable unique 9 character identifier like:  CF2-532-DAC
63
-     * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC
64
-     *
65
-     * @return void
66
-     */
67
-    protected function setCollectionIdentifier()
68
-    {
69
-        // hash a few collection details
70
-        $identifier = md5(spl_object_hash($this) . $this->collection_interface . time());
71
-        // grab a few characters from the start, middle, and end of the hash
72
-        $id = array();
73
-        for ($x = 0; $x < 19; $x += 9) {
74
-            $id[] = substr($identifier, $x, 3);
75
-        }
76
-        $identifier = basename(str_replace('\\', '/', get_class($this)));
77
-        $identifier .= '-' . strtoupper(implode('-', $id));
78
-        $this->collection_identifier = $identifier;
79
-    }
80
-
81
-
82
-    /**
83
-     * setCollectionInterface
84
-     *
85
-     * @param  string $collection_interface
86
-     * @throws InvalidInterfaceException
87
-     */
88
-    protected function setCollectionInterface($collection_interface)
89
-    {
90
-        if (! (interface_exists($collection_interface) || class_exists($collection_interface))) {
91
-            throw new InvalidInterfaceException($collection_interface);
92
-        }
93
-        $this->collection_interface = $collection_interface;
94
-    }
95
-
96
-
97
-    /**
98
-     * add
99
-     * attaches an object to the Collection
100
-     * and sets any supplied data associated with the current iterator entry
101
-     * by calling EE_Object_Collection::set_identifier()
102
-     *
103
-     * @param        $object
104
-     * @param  mixed $identifier
105
-     * @return bool
106
-     * @throws InvalidEntityException
107
-     */
108
-    public function add($object, $identifier = null)
109
-    {
110
-        if (! $object instanceof $this->collection_interface) {
111
-            throw new InvalidEntityException($object, $this->collection_interface);
112
-        }
113
-        $this->attach($object);
114
-        $this->setIdentifier($object, $identifier);
115
-        return $this->contains($object);
116
-    }
117
-
118
-
119
-    /**
120
-     * setIdentifier
121
-     * Sets the data associated with an object in the Collection
122
-     * if no $identifier is supplied, then the spl_object_hash() is used
123
-     *
124
-     * @access public
125
-     * @param        $object
126
-     * @param  mixed $identifier
127
-     * @return bool
128
-     */
129
-    public function setIdentifier($object, $identifier = null)
130
-    {
131
-        $identifier = ! empty($identifier)
132
-            ? $identifier
133
-            : spl_object_hash($object);
134
-        $this->rewind();
135
-        while ($this->valid()) {
136
-            if ($object === $this->current()) {
137
-                $this->setInfo($identifier);
138
-                $this->rewind();
139
-                return true;
140
-            }
141
-            $this->next();
142
-        }
143
-        return false;
144
-    }
145
-
146
-
147
-    /**
148
-     * get
149
-     * finds and returns an object in the Collection based on the identifier that was set using addObject()
150
-     * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
151
-     *
152
-     * @access public
153
-     * @param mixed $identifier
154
-     * @return mixed
155
-     */
156
-    public function get($identifier)
157
-    {
158
-        $this->rewind();
159
-        while ($this->valid()) {
160
-            if ($identifier === $this->getInfo()) {
161
-                $object = $this->current();
162
-                $this->rewind();
163
-                return $object;
164
-            }
165
-            $this->next();
166
-        }
167
-        return null;
168
-    }
169
-
170
-
171
-    /**
172
-     * has
173
-     * returns TRUE or FALSE
174
-     * depending on whether the object is within the Collection
175
-     * based on the supplied $identifier
176
-     *
177
-     * @access public
178
-     * @param  mixed $identifier
179
-     * @return bool
180
-     */
181
-    public function has($identifier)
182
-    {
183
-        $this->rewind();
184
-        while ($this->valid()) {
185
-            if ($identifier === $this->getInfo()) {
186
-                $this->rewind();
187
-                return true;
188
-            }
189
-            $this->next();
190
-        }
191
-        return false;
192
-    }
193
-
194
-
195
-    /**
196
-     * hasObject
197
-     * returns TRUE or FALSE depending on whether the supplied object is within the Collection
198
-     *
199
-     * @access public
200
-     * @param $object
201
-     * @return bool
202
-     */
203
-    public function hasObject($object)
204
-    {
205
-        return $this->contains($object);
206
-    }
207
-
208
-
209
-    /**
210
-     * hasObjects
211
-     * returns true if there are objects within the Collection, and false if it is empty
212
-     *
213
-     * @access public
214
-     * @return bool
215
-     */
216
-    public function hasObjects()
217
-    {
218
-        return $this->count() !== 0;
219
-    }
220
-
221
-
222
-    /**
223
-     * isEmpty
224
-     * returns true if there are no objects within the Collection, and false if there are
225
-     *
226
-     * @access public
227
-     * @return bool
228
-     */
229
-    public function isEmpty()
230
-    {
231
-        return $this->count() === 0;
232
-    }
233
-
234
-
235
-    /**
236
-     * remove
237
-     * detaches an object from the Collection
238
-     *
239
-     * @access public
240
-     * @param $object
241
-     * @return bool
242
-     */
243
-    public function remove($object)
244
-    {
245
-        $this->detach($object);
246
-        return true;
247
-    }
248
-
249
-
250
-    /**
251
-     * setCurrent
252
-     * advances pointer to the object whose identifier matches that which was provided
253
-     *
254
-     * @access public
255
-     * @param mixed $identifier
256
-     * @return boolean
257
-     */
258
-    public function setCurrent($identifier)
259
-    {
260
-        $this->rewind();
261
-        while ($this->valid()) {
262
-            if ($identifier === $this->getInfo()) {
263
-                return true;
264
-            }
265
-            $this->next();
266
-        }
267
-        return false;
268
-    }
269
-
270
-
271
-    /**
272
-     * setCurrentUsingObject
273
-     * advances pointer to the provided object
274
-     *
275
-     * @access public
276
-     * @param $object
277
-     * @return boolean
278
-     */
279
-    public function setCurrentUsingObject($object)
280
-    {
281
-        $this->rewind();
282
-        while ($this->valid()) {
283
-            if ($this->current() === $object) {
284
-                return true;
285
-            }
286
-            $this->next();
287
-        }
288
-        return false;
289
-    }
290
-
291
-
292
-    /**
293
-     * Returns the object occupying the index before the current object,
294
-     * unless this is already the first object, in which case it just returns the first object
295
-     *
296
-     * @return mixed
297
-     */
298
-    public function previous()
299
-    {
300
-        $index = $this->indexOf($this->current());
301
-        if ($index === 0) {
302
-            return $this->current();
303
-        }
304
-        $index--;
305
-        return $this->objectAtIndex($index);
306
-    }
307
-
308
-
309
-    /**
310
-     * Returns the index of a given object, or false if not found
311
-     *
312
-     * @see http://stackoverflow.com/a/8736013
313
-     * @param $object
314
-     * @return boolean|int|string
315
-     */
316
-    public function indexOf($object)
317
-    {
318
-        if (! $this->contains($object)) {
319
-            return false;
320
-        }
321
-        foreach ($this as $index => $obj) {
322
-            if ($obj === $object) {
323
-                return $index;
324
-            }
325
-        }
326
-        return false;
327
-    }
328
-
329
-
330
-    /**
331
-     * Returns the object at the given index
332
-     *
333
-     * @see http://stackoverflow.com/a/8736013
334
-     * @param int $index
335
-     * @return mixed
336
-     */
337
-    public function objectAtIndex($index)
338
-    {
339
-        $iterator = new LimitIterator($this, $index, 1);
340
-        $iterator->rewind();
341
-        return $iterator->current();
342
-    }
343
-
344
-
345
-    /**
346
-     * Returns the sequence of objects as specified by the offset and length
347
-     *
348
-     * @see http://stackoverflow.com/a/8736013
349
-     * @param int $offset
350
-     * @param int $length
351
-     * @return array
352
-     */
353
-    public function slice($offset, $length)
354
-    {
355
-        $slice = array();
356
-        $iterator = new LimitIterator($this, $offset, $length);
357
-        foreach ($iterator as $object) {
358
-            $slice[] = $object;
359
-        }
360
-        return $slice;
361
-    }
362
-
363
-
364
-    /**
365
-     * Inserts an object (or an array of objects) at a certain point
366
-     *
367
-     * @see http://stackoverflow.com/a/8736013
368
-     * @param mixed $objects A single object or an array of objects
369
-     * @param int   $index
370
-     */
371
-    public function insertAt($objects, $index)
372
-    {
373
-        if (! is_array($objects)) {
374
-            $objects = array($objects);
375
-        }
376
-        // check to ensure that objects don't already exist in the collection
377
-        foreach ($objects as $key => $object) {
378
-            if ($this->contains($object)) {
379
-                unset($objects[ $key ]);
380
-            }
381
-        }
382
-        // do we have any objects left?
383
-        if (! $objects) {
384
-            return;
385
-        }
386
-        // detach any objects at or past this index
387
-        $remaining = array();
388
-        if ($index < $this->count()) {
389
-            $remaining = $this->slice($index, $this->count() - $index);
390
-            foreach ($remaining as $object) {
391
-                $this->detach($object);
392
-            }
393
-        }
394
-        // add the new objects we're splicing in
395
-        foreach ($objects as $object) {
396
-            $this->attach($object);
397
-        }
398
-        // attach the objects we previously detached
399
-        foreach ($remaining as $object) {
400
-            $this->attach($object);
401
-        }
402
-    }
403
-
404
-
405
-    /**
406
-     * Removes the object at the given index
407
-     *
408
-     * @see http://stackoverflow.com/a/8736013
409
-     * @param int $index
410
-     */
411
-    public function removeAt($index)
412
-    {
413
-        $this->detach($this->objectAtIndex($index));
414
-    }
415
-
416
-
417
-    /**
418
-     * detaches ALL objects from the Collection
419
-     */
420
-    public function detachAll()
421
-    {
422
-        $this->rewind();
423
-        while ($this->valid()) {
424
-            $object = $this->current();
425
-            $this->next();
426
-            $this->detach($object);
427
-        }
428
-    }
429
-
430
-
431
-    /**
432
-     * unsets and detaches ALL objects from the Collection
433
-     */
434
-    public function trashAndDetachAll()
435
-    {
436
-        $this->rewind();
437
-        while ($this->valid()) {
438
-            $object = $this->current();
439
-            $this->next();
440
-            $this->detach($object);
441
-            unset($object);
442
-        }
443
-    }
22
+	/**
23
+	 * a unique string for identifying this collection
24
+	 *
25
+	 * @type string $collection_identifier
26
+	 */
27
+	protected $collection_identifier;
28
+
29
+
30
+	/**
31
+	 * an interface (or class) name to be used for restricting the type of objects added to the storage
32
+	 * this should be set from within the child class constructor
33
+	 *
34
+	 * @type string $interface
35
+	 */
36
+	protected $collection_interface;
37
+
38
+
39
+	/**
40
+	 * Collection constructor
41
+	 *
42
+	 * @param string $collection_interface
43
+	 * @throws InvalidInterfaceException
44
+	 */
45
+	public function __construct($collection_interface)
46
+	{
47
+		$this->setCollectionInterface($collection_interface);
48
+		$this->setCollectionIdentifier();
49
+	}
50
+
51
+
52
+	/**
53
+	 * @return string
54
+	 */
55
+	public function collectionIdentifier()
56
+	{
57
+		return $this->collection_identifier;
58
+	}
59
+
60
+
61
+	/**
62
+	 * creates a very readable unique 9 character identifier like:  CF2-532-DAC
63
+	 * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC
64
+	 *
65
+	 * @return void
66
+	 */
67
+	protected function setCollectionIdentifier()
68
+	{
69
+		// hash a few collection details
70
+		$identifier = md5(spl_object_hash($this) . $this->collection_interface . time());
71
+		// grab a few characters from the start, middle, and end of the hash
72
+		$id = array();
73
+		for ($x = 0; $x < 19; $x += 9) {
74
+			$id[] = substr($identifier, $x, 3);
75
+		}
76
+		$identifier = basename(str_replace('\\', '/', get_class($this)));
77
+		$identifier .= '-' . strtoupper(implode('-', $id));
78
+		$this->collection_identifier = $identifier;
79
+	}
80
+
81
+
82
+	/**
83
+	 * setCollectionInterface
84
+	 *
85
+	 * @param  string $collection_interface
86
+	 * @throws InvalidInterfaceException
87
+	 */
88
+	protected function setCollectionInterface($collection_interface)
89
+	{
90
+		if (! (interface_exists($collection_interface) || class_exists($collection_interface))) {
91
+			throw new InvalidInterfaceException($collection_interface);
92
+		}
93
+		$this->collection_interface = $collection_interface;
94
+	}
95
+
96
+
97
+	/**
98
+	 * add
99
+	 * attaches an object to the Collection
100
+	 * and sets any supplied data associated with the current iterator entry
101
+	 * by calling EE_Object_Collection::set_identifier()
102
+	 *
103
+	 * @param        $object
104
+	 * @param  mixed $identifier
105
+	 * @return bool
106
+	 * @throws InvalidEntityException
107
+	 */
108
+	public function add($object, $identifier = null)
109
+	{
110
+		if (! $object instanceof $this->collection_interface) {
111
+			throw new InvalidEntityException($object, $this->collection_interface);
112
+		}
113
+		$this->attach($object);
114
+		$this->setIdentifier($object, $identifier);
115
+		return $this->contains($object);
116
+	}
117
+
118
+
119
+	/**
120
+	 * setIdentifier
121
+	 * Sets the data associated with an object in the Collection
122
+	 * if no $identifier is supplied, then the spl_object_hash() is used
123
+	 *
124
+	 * @access public
125
+	 * @param        $object
126
+	 * @param  mixed $identifier
127
+	 * @return bool
128
+	 */
129
+	public function setIdentifier($object, $identifier = null)
130
+	{
131
+		$identifier = ! empty($identifier)
132
+			? $identifier
133
+			: spl_object_hash($object);
134
+		$this->rewind();
135
+		while ($this->valid()) {
136
+			if ($object === $this->current()) {
137
+				$this->setInfo($identifier);
138
+				$this->rewind();
139
+				return true;
140
+			}
141
+			$this->next();
142
+		}
143
+		return false;
144
+	}
145
+
146
+
147
+	/**
148
+	 * get
149
+	 * finds and returns an object in the Collection based on the identifier that was set using addObject()
150
+	 * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
151
+	 *
152
+	 * @access public
153
+	 * @param mixed $identifier
154
+	 * @return mixed
155
+	 */
156
+	public function get($identifier)
157
+	{
158
+		$this->rewind();
159
+		while ($this->valid()) {
160
+			if ($identifier === $this->getInfo()) {
161
+				$object = $this->current();
162
+				$this->rewind();
163
+				return $object;
164
+			}
165
+			$this->next();
166
+		}
167
+		return null;
168
+	}
169
+
170
+
171
+	/**
172
+	 * has
173
+	 * returns TRUE or FALSE
174
+	 * depending on whether the object is within the Collection
175
+	 * based on the supplied $identifier
176
+	 *
177
+	 * @access public
178
+	 * @param  mixed $identifier
179
+	 * @return bool
180
+	 */
181
+	public function has($identifier)
182
+	{
183
+		$this->rewind();
184
+		while ($this->valid()) {
185
+			if ($identifier === $this->getInfo()) {
186
+				$this->rewind();
187
+				return true;
188
+			}
189
+			$this->next();
190
+		}
191
+		return false;
192
+	}
193
+
194
+
195
+	/**
196
+	 * hasObject
197
+	 * returns TRUE or FALSE depending on whether the supplied object is within the Collection
198
+	 *
199
+	 * @access public
200
+	 * @param $object
201
+	 * @return bool
202
+	 */
203
+	public function hasObject($object)
204
+	{
205
+		return $this->contains($object);
206
+	}
207
+
208
+
209
+	/**
210
+	 * hasObjects
211
+	 * returns true if there are objects within the Collection, and false if it is empty
212
+	 *
213
+	 * @access public
214
+	 * @return bool
215
+	 */
216
+	public function hasObjects()
217
+	{
218
+		return $this->count() !== 0;
219
+	}
220
+
221
+
222
+	/**
223
+	 * isEmpty
224
+	 * returns true if there are no objects within the Collection, and false if there are
225
+	 *
226
+	 * @access public
227
+	 * @return bool
228
+	 */
229
+	public function isEmpty()
230
+	{
231
+		return $this->count() === 0;
232
+	}
233
+
234
+
235
+	/**
236
+	 * remove
237
+	 * detaches an object from the Collection
238
+	 *
239
+	 * @access public
240
+	 * @param $object
241
+	 * @return bool
242
+	 */
243
+	public function remove($object)
244
+	{
245
+		$this->detach($object);
246
+		return true;
247
+	}
248
+
249
+
250
+	/**
251
+	 * setCurrent
252
+	 * advances pointer to the object whose identifier matches that which was provided
253
+	 *
254
+	 * @access public
255
+	 * @param mixed $identifier
256
+	 * @return boolean
257
+	 */
258
+	public function setCurrent($identifier)
259
+	{
260
+		$this->rewind();
261
+		while ($this->valid()) {
262
+			if ($identifier === $this->getInfo()) {
263
+				return true;
264
+			}
265
+			$this->next();
266
+		}
267
+		return false;
268
+	}
269
+
270
+
271
+	/**
272
+	 * setCurrentUsingObject
273
+	 * advances pointer to the provided object
274
+	 *
275
+	 * @access public
276
+	 * @param $object
277
+	 * @return boolean
278
+	 */
279
+	public function setCurrentUsingObject($object)
280
+	{
281
+		$this->rewind();
282
+		while ($this->valid()) {
283
+			if ($this->current() === $object) {
284
+				return true;
285
+			}
286
+			$this->next();
287
+		}
288
+		return false;
289
+	}
290
+
291
+
292
+	/**
293
+	 * Returns the object occupying the index before the current object,
294
+	 * unless this is already the first object, in which case it just returns the first object
295
+	 *
296
+	 * @return mixed
297
+	 */
298
+	public function previous()
299
+	{
300
+		$index = $this->indexOf($this->current());
301
+		if ($index === 0) {
302
+			return $this->current();
303
+		}
304
+		$index--;
305
+		return $this->objectAtIndex($index);
306
+	}
307
+
308
+
309
+	/**
310
+	 * Returns the index of a given object, or false if not found
311
+	 *
312
+	 * @see http://stackoverflow.com/a/8736013
313
+	 * @param $object
314
+	 * @return boolean|int|string
315
+	 */
316
+	public function indexOf($object)
317
+	{
318
+		if (! $this->contains($object)) {
319
+			return false;
320
+		}
321
+		foreach ($this as $index => $obj) {
322
+			if ($obj === $object) {
323
+				return $index;
324
+			}
325
+		}
326
+		return false;
327
+	}
328
+
329
+
330
+	/**
331
+	 * Returns the object at the given index
332
+	 *
333
+	 * @see http://stackoverflow.com/a/8736013
334
+	 * @param int $index
335
+	 * @return mixed
336
+	 */
337
+	public function objectAtIndex($index)
338
+	{
339
+		$iterator = new LimitIterator($this, $index, 1);
340
+		$iterator->rewind();
341
+		return $iterator->current();
342
+	}
343
+
344
+
345
+	/**
346
+	 * Returns the sequence of objects as specified by the offset and length
347
+	 *
348
+	 * @see http://stackoverflow.com/a/8736013
349
+	 * @param int $offset
350
+	 * @param int $length
351
+	 * @return array
352
+	 */
353
+	public function slice($offset, $length)
354
+	{
355
+		$slice = array();
356
+		$iterator = new LimitIterator($this, $offset, $length);
357
+		foreach ($iterator as $object) {
358
+			$slice[] = $object;
359
+		}
360
+		return $slice;
361
+	}
362
+
363
+
364
+	/**
365
+	 * Inserts an object (or an array of objects) at a certain point
366
+	 *
367
+	 * @see http://stackoverflow.com/a/8736013
368
+	 * @param mixed $objects A single object or an array of objects
369
+	 * @param int   $index
370
+	 */
371
+	public function insertAt($objects, $index)
372
+	{
373
+		if (! is_array($objects)) {
374
+			$objects = array($objects);
375
+		}
376
+		// check to ensure that objects don't already exist in the collection
377
+		foreach ($objects as $key => $object) {
378
+			if ($this->contains($object)) {
379
+				unset($objects[ $key ]);
380
+			}
381
+		}
382
+		// do we have any objects left?
383
+		if (! $objects) {
384
+			return;
385
+		}
386
+		// detach any objects at or past this index
387
+		$remaining = array();
388
+		if ($index < $this->count()) {
389
+			$remaining = $this->slice($index, $this->count() - $index);
390
+			foreach ($remaining as $object) {
391
+				$this->detach($object);
392
+			}
393
+		}
394
+		// add the new objects we're splicing in
395
+		foreach ($objects as $object) {
396
+			$this->attach($object);
397
+		}
398
+		// attach the objects we previously detached
399
+		foreach ($remaining as $object) {
400
+			$this->attach($object);
401
+		}
402
+	}
403
+
404
+
405
+	/**
406
+	 * Removes the object at the given index
407
+	 *
408
+	 * @see http://stackoverflow.com/a/8736013
409
+	 * @param int $index
410
+	 */
411
+	public function removeAt($index)
412
+	{
413
+		$this->detach($this->objectAtIndex($index));
414
+	}
415
+
416
+
417
+	/**
418
+	 * detaches ALL objects from the Collection
419
+	 */
420
+	public function detachAll()
421
+	{
422
+		$this->rewind();
423
+		while ($this->valid()) {
424
+			$object = $this->current();
425
+			$this->next();
426
+			$this->detach($object);
427
+		}
428
+	}
429
+
430
+
431
+	/**
432
+	 * unsets and detaches ALL objects from the Collection
433
+	 */
434
+	public function trashAndDetachAll()
435
+	{
436
+		$this->rewind();
437
+		while ($this->valid()) {
438
+			$object = $this->current();
439
+			$this->next();
440
+			$this->detach($object);
441
+			unset($object);
442
+		}
443
+	}
444 444
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -67,14 +67,14 @@  discard block
 block discarded – undo
67 67
     protected function setCollectionIdentifier()
68 68
     {
69 69
         // hash a few collection details
70
-        $identifier = md5(spl_object_hash($this) . $this->collection_interface . time());
70
+        $identifier = md5(spl_object_hash($this).$this->collection_interface.time());
71 71
         // grab a few characters from the start, middle, and end of the hash
72 72
         $id = array();
73 73
         for ($x = 0; $x < 19; $x += 9) {
74 74
             $id[] = substr($identifier, $x, 3);
75 75
         }
76 76
         $identifier = basename(str_replace('\\', '/', get_class($this)));
77
-        $identifier .= '-' . strtoupper(implode('-', $id));
77
+        $identifier .= '-'.strtoupper(implode('-', $id));
78 78
         $this->collection_identifier = $identifier;
79 79
     }
80 80
 
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
      */
88 88
     protected function setCollectionInterface($collection_interface)
89 89
     {
90
-        if (! (interface_exists($collection_interface) || class_exists($collection_interface))) {
90
+        if ( ! (interface_exists($collection_interface) || class_exists($collection_interface))) {
91 91
             throw new InvalidInterfaceException($collection_interface);
92 92
         }
93 93
         $this->collection_interface = $collection_interface;
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      */
108 108
     public function add($object, $identifier = null)
109 109
     {
110
-        if (! $object instanceof $this->collection_interface) {
110
+        if ( ! $object instanceof $this->collection_interface) {
111 111
             throw new InvalidEntityException($object, $this->collection_interface);
112 112
         }
113 113
         $this->attach($object);
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
      */
316 316
     public function indexOf($object)
317 317
     {
318
-        if (! $this->contains($object)) {
318
+        if ( ! $this->contains($object)) {
319 319
             return false;
320 320
         }
321 321
         foreach ($this as $index => $obj) {
@@ -370,17 +370,17 @@  discard block
 block discarded – undo
370 370
      */
371 371
     public function insertAt($objects, $index)
372 372
     {
373
-        if (! is_array($objects)) {
373
+        if ( ! is_array($objects)) {
374 374
             $objects = array($objects);
375 375
         }
376 376
         // check to ensure that objects don't already exist in the collection
377 377
         foreach ($objects as $key => $object) {
378 378
             if ($this->contains($object)) {
379
-                unset($objects[ $key ]);
379
+                unset($objects[$key]);
380 380
             }
381 381
         }
382 382
         // do we have any objects left?
383
-        if (! $objects) {
383
+        if ( ! $objects) {
384 384
             return;
385 385
         }
386 386
         // detach any objects at or past this index
Please login to merge, or discard this patch.
core/db_classes/EE_Base_Class.class.php 1 patch
Doc Comments   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
      *
713 713
      * @param \EE_Datetime_Field $datetime_field
714 714
      * @param bool               $pretty
715
-     * @param null               $date_or_time
715
+     * @param string|null               $date_or_time
716 716
      * @return void
717 717
      * @throws InvalidArgumentException
718 718
      * @throws InvalidInterfaceException
@@ -1066,7 +1066,7 @@  discard block
 block discarded – undo
1066 1066
      *
1067 1067
      * @param null  $field_to_order_by  What field is being used as the reference point.
1068 1068
      * @param array $query_params       Any additional conditions on the query.
1069
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
1069
+     * @param string  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
1070 1070
      *                                  you can indicate just the columns you want returned
1071 1071
      * @return array|EE_Base_Class
1072 1072
      * @throws ReflectionException
@@ -1095,7 +1095,7 @@  discard block
 block discarded – undo
1095 1095
      *
1096 1096
      * @param null  $field_to_order_by  What field is being used as the reference point.
1097 1097
      * @param array $query_params       Any additional conditions on the query.
1098
-     * @param null  $columns_to_select  If left null, then an EE_Base_Class object is returned, otherwise
1098
+     * @param string  $columns_to_select  If left null, then an EE_Base_Class object is returned, otherwise
1099 1099
      *                                  you can indicate just the column you want returned
1100 1100
      * @return array|EE_Base_Class
1101 1101
      * @throws ReflectionException
@@ -1527,7 +1527,7 @@  discard block
 block discarded – undo
1527 1527
      * sets the time on a datetime property
1528 1528
      *
1529 1529
      * @access protected
1530
-     * @param string|Datetime $time      a valid time string for php datetime functions (or DateTime object)
1530
+     * @param string $time      a valid time string for php datetime functions (or DateTime object)
1531 1531
      * @param string          $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field)
1532 1532
      * @throws ReflectionException
1533 1533
      * @throws InvalidArgumentException
@@ -1545,7 +1545,7 @@  discard block
 block discarded – undo
1545 1545
      * sets the date on a datetime property
1546 1546
      *
1547 1547
      * @access protected
1548
-     * @param string|DateTime $date      a valid date string for php datetime functions ( or DateTime object)
1548
+     * @param string $date      a valid date string for php datetime functions ( or DateTime object)
1549 1549
      * @param string          $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field)
1550 1550
      * @throws ReflectionException
1551 1551
      * @throws InvalidArgumentException
@@ -2067,7 +2067,7 @@  discard block
 block discarded – undo
2067 2067
      *
2068 2068
      * @param  array  $props_n_values   incoming array of properties and their values
2069 2069
      * @param  string $classname        the classname of the child class
2070
-     * @param null    $timezone
2070
+     * @param string|null    $timezone
2071 2071
      * @param array   $date_formats     incoming date_formats in an array where the first value is the
2072 2072
      *                                  date_format and the second value is the time format
2073 2073
      * @return mixed (EE_Base_Class|bool)
@@ -2154,7 +2154,7 @@  discard block
 block discarded – undo
2154 2154
      * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee)
2155 2155
      *
2156 2156
      * @param string $model_classname
2157
-     * @param null   $timezone
2157
+     * @param string|null   $timezone
2158 2158
      * @return EEM_Base
2159 2159
      * @throws ReflectionException
2160 2160
      * @throws InvalidArgumentException
Please login to merge, or discard this patch.
core/libraries/rest_api/controllers/model/Read.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1306,7 +1306,7 @@
 block discarded – undo
1306 1306
      *
1307 1307
      * @param EEM_Base        $model
1308 1308
      * @param WP_REST_Request $request
1309
-     * @param null            $context
1309
+     * @param string            $context
1310 1310
      * @return array|WP_Error
1311 1311
      */
1312 1312
     public function getOneOrReportPermissionError(EEM_Base $model, WP_REST_Request $request, $context = null)
Please login to merge, or discard this patch.
Indentation   +1319 added lines, -1319 removed lines patch added patch discarded remove patch
@@ -35,1323 +35,1323 @@
 block discarded – undo
35 35
 {
36 36
 
37 37
 
38
-    /**
39
-     * @var CalculatedModelFields
40
-     */
41
-    protected $fields_calculator;
42
-
43
-
44
-    /**
45
-     * Read constructor.
46
-     */
47
-    public function __construct()
48
-    {
49
-        parent::__construct();
50
-        $this->fields_calculator = new CalculatedModelFields();
51
-    }
52
-
53
-
54
-    /**
55
-     * Handles requests to get all (or a filtered subset) of entities for a particular model
56
-     *
57
-     * @param WP_REST_Request $request
58
-     * @param string          $version
59
-     * @param string          $model_name
60
-     * @return \WP_REST_Response|WP_Error
61
-     */
62
-    public static function handleRequestGetAll(WP_REST_Request $request, $version, $model_name)
63
-    {
64
-        $controller = new Read();
65
-        try {
66
-            $controller->setRequestedVersion($version);
67
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
68
-                return $controller->sendResponse(
69
-                    new WP_Error(
70
-                        'endpoint_parsing_error',
71
-                        sprintf(
72
-                            __(
73
-                                'There is no model for endpoint %s. Please contact event espresso support',
74
-                                'event_espresso'
75
-                            ),
76
-                            $model_name
77
-                        )
78
-                    )
79
-                );
80
-            }
81
-            return $controller->sendResponse(
82
-                $controller->getEntitiesFromModel(
83
-                    $controller->getModelVersionInfo()->loadModel($model_name),
84
-                    $request
85
-                )
86
-            );
87
-        } catch (Exception $e) {
88
-            return $controller->sendResponse($e);
89
-        }
90
-    }
91
-
92
-
93
-    /**
94
-     * Prepares and returns schema for any OPTIONS request.
95
-     *
96
-     * @param string $version    The API endpoint version being used.
97
-     * @param string $model_name Something like `Event` or `Registration`
98
-     * @return array
99
-     */
100
-    public static function handleSchemaRequest($version, $model_name)
101
-    {
102
-        $controller = new Read();
103
-        try {
104
-            $controller->setRequestedVersion($version);
105
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
106
-                return array();
107
-            }
108
-            // get the model for this version
109
-            $model = $controller->getModelVersionInfo()->loadModel($model_name);
110
-            $model_schema = new JsonModelSchema($model);
111
-            return $model_schema->getModelSchemaForRelations(
112
-                $controller->getModelVersionInfo()->relationSettings($model),
113
-                $controller->customizeSchemaForRestResponse(
114
-                    $model,
115
-                    $model_schema->getModelSchemaForFields(
116
-                        $controller->getModelVersionInfo()->fieldsOnModelInThisVersion($model),
117
-                        $model_schema->getInitialSchemaStructure()
118
-                    )
119
-                )
120
-            );
121
-        } catch (Exception $e) {
122
-            return array();
123
-        }
124
-    }
125
-
126
-
127
-    /**
128
-     * This loops through each field in the given schema for the model and does the following:
129
-     * - add any extra fields that are REST API specific and related to existing fields.
130
-     * - transform default values into the correct format for a REST API response.
131
-     *
132
-     * @param EEM_Base $model
133
-     * @param array    $schema
134
-     * @return array  The final schema.
135
-     */
136
-    protected function customizeSchemaForRestResponse(EEM_Base $model, array $schema)
137
-    {
138
-        foreach ($this->getModelVersionInfo()->fieldsOnModelInThisVersion($model) as $field_name => $field) {
139
-            $schema = $this->translateDefaultsForRestResponse(
140
-                $field_name,
141
-                $field,
142
-                $this->maybeAddExtraFieldsToSchema($field_name, $field, $schema)
143
-            );
144
-        }
145
-        return $schema;
146
-    }
147
-
148
-
149
-    /**
150
-     * This is used to ensure that the 'default' value set in the schema response is formatted correctly for the REST
151
-     * response.
152
-     *
153
-     * @param                      $field_name
154
-     * @param EE_Model_Field_Base  $field
155
-     * @param array                $schema
156
-     * @return array
157
-     * @throws ObjectDetectedException if a default value has a PHP object, which should never do (and if we
158
-     * did, let's know about it ASAP, so let the exception bubble up)
159
-     */
160
-    protected function translateDefaultsForRestResponse($field_name, EE_Model_Field_Base $field, array $schema)
161
-    {
162
-        if (isset($schema['properties'][ $field_name ]['default'])) {
163
-            if (is_array($schema['properties'][ $field_name ]['default'])) {
164
-                foreach ($schema['properties'][ $field_name ]['default'] as $default_key => $default_value) {
165
-                    if ($default_key === 'raw') {
166
-                        $schema['properties'][ $field_name ]['default'][ $default_key ] =
167
-                            ModelDataTranslator::prepareFieldValueForJson(
168
-                                $field,
169
-                                $default_value,
170
-                                $this->getModelVersionInfo()->requestedVersion()
171
-                            );
172
-                    }
173
-                }
174
-            } else {
175
-                $schema['properties'][ $field_name ]['default'] = ModelDataTranslator::prepareFieldValueForJson(
176
-                    $field,
177
-                    $schema['properties'][ $field_name ]['default'],
178
-                    $this->getModelVersionInfo()->requestedVersion()
179
-                );
180
-            }
181
-        }
182
-        return $schema;
183
-    }
184
-
185
-
186
-    /**
187
-     * Adds additional fields to the schema
188
-     * The REST API returns a GMT value field for each datetime field in the resource.  Thus the description about this
189
-     * needs to be added to the schema.
190
-     *
191
-     * @param                      $field_name
192
-     * @param EE_Model_Field_Base  $field
193
-     * @param array                $schema
194
-     * @return array
195
-     */
196
-    protected function maybeAddExtraFieldsToSchema($field_name, EE_Model_Field_Base $field, array $schema)
197
-    {
198
-        if ($field instanceof EE_Datetime_Field) {
199
-            $schema['properties'][ $field_name . '_gmt' ] = $field->getSchema();
200
-            // modify the description
201
-            $schema['properties'][ $field_name . '_gmt' ]['description'] = sprintf(
202
-                esc_html__('%s - the value for this field is in GMT.', 'event_espresso'),
203
-                wp_specialchars_decode($field->get_nicename(), ENT_QUOTES)
204
-            );
205
-        }
206
-        return $schema;
207
-    }
208
-
209
-
210
-    /**
211
-     * Used to figure out the route from the request when a `WP_REST_Request` object is not available
212
-     *
213
-     * @return string
214
-     */
215
-    protected function getRouteFromRequest()
216
-    {
217
-        if (isset($GLOBALS['wp'])
218
-            && $GLOBALS['wp'] instanceof \WP
219
-            && isset($GLOBALS['wp']->query_vars['rest_route'])
220
-        ) {
221
-            return $GLOBALS['wp']->query_vars['rest_route'];
222
-        } else {
223
-            return isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/';
224
-        }
225
-    }
226
-
227
-
228
-    /**
229
-     * Gets a single entity related to the model indicated in the path and its id
230
-     *
231
-     * @param WP_REST_Request $request
232
-     * @param string          $version
233
-     * @param string          $model_name
234
-     * @return \WP_REST_Response|WP_Error
235
-     */
236
-    public static function handleRequestGetOne(WP_REST_Request $request, $version, $model_name)
237
-    {
238
-        $controller = new Read();
239
-        try {
240
-            $controller->setRequestedVersion($version);
241
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
242
-                return $controller->sendResponse(
243
-                    new WP_Error(
244
-                        'endpoint_parsing_error',
245
-                        sprintf(
246
-                            __(
247
-                                'There is no model for endpoint %s. Please contact event espresso support',
248
-                                'event_espresso'
249
-                            ),
250
-                            $model_name
251
-                        )
252
-                    )
253
-                );
254
-            }
255
-            return $controller->sendResponse(
256
-                $controller->getEntityFromModel(
257
-                    $controller->getModelVersionInfo()->loadModel($model_name),
258
-                    $request
259
-                )
260
-            );
261
-        } catch (Exception $e) {
262
-            return $controller->sendResponse($e);
263
-        }
264
-    }
265
-
266
-
267
-    /**
268
-     * Gets all the related entities (or if its a belongs-to relation just the one)
269
-     * to the item with the given id
270
-     *
271
-     * @param WP_REST_Request $request
272
-     * @param string          $version
273
-     * @param string          $model_name
274
-     * @param string          $related_model_name
275
-     * @return \WP_REST_Response|WP_Error
276
-     */
277
-    public static function handleRequestGetRelated(
278
-        WP_REST_Request $request,
279
-        $version,
280
-        $model_name,
281
-        $related_model_name
282
-    ) {
283
-        $controller = new Read();
284
-        try {
285
-            $controller->setRequestedVersion($version);
286
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
287
-                return $controller->sendResponse(
288
-                    new WP_Error(
289
-                        'endpoint_parsing_error',
290
-                        sprintf(
291
-                            __(
292
-                                'There is no model for endpoint %s. Please contact event espresso support',
293
-                                'event_espresso'
294
-                            ),
295
-                            $model_name
296
-                        )
297
-                    )
298
-                );
299
-            }
300
-            $main_model = $controller->getModelVersionInfo()->loadModel($model_name);
301
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($related_model_name)) {
302
-                return $controller->sendResponse(
303
-                    new WP_Error(
304
-                        'endpoint_parsing_error',
305
-                        sprintf(
306
-                            __(
307
-                                'There is no model for endpoint %s. Please contact event espresso support',
308
-                                'event_espresso'
309
-                            ),
310
-                            $related_model_name
311
-                        )
312
-                    )
313
-                );
314
-            }
315
-            return $controller->sendResponse(
316
-                $controller->getEntitiesFromRelation(
317
-                    $request->get_param('id'),
318
-                    $main_model->related_settings_for($related_model_name),
319
-                    $request
320
-                )
321
-            );
322
-        } catch (Exception $e) {
323
-            return $controller->sendResponse($e);
324
-        }
325
-    }
326
-
327
-
328
-    /**
329
-     * Gets a collection for the given model and filters
330
-     *
331
-     * @param EEM_Base        $model
332
-     * @param WP_REST_Request $request
333
-     * @return array|WP_Error
334
-     */
335
-    public function getEntitiesFromModel($model, $request)
336
-    {
337
-        $query_params = $this->createModelQueryParams($model, $request->get_params());
338
-        if (! Capabilities::currentUserHasPartialAccessTo($model, $query_params['caps'])) {
339
-            $model_name_plural = EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
340
-            return new WP_Error(
341
-                sprintf('rest_%s_cannot_list', $model_name_plural),
342
-                sprintf(
343
-                    __('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'),
344
-                    $model_name_plural,
345
-                    Capabilities::getMissingPermissionsString($model, $query_params['caps'])
346
-                ),
347
-                array('status' => 403)
348
-            );
349
-        }
350
-        if (! $request->get_header('no_rest_headers')) {
351
-            $this->setHeadersFromQueryParams($model, $query_params);
352
-        }
353
-        /** @type array $results */
354
-        $results = $model->get_all_wpdb_results($query_params);
355
-        $nice_results = array();
356
-        foreach ($results as $result) {
357
-            $nice_results[] = $this->createEntityFromWpdbResult(
358
-                $model,
359
-                $result,
360
-                $request
361
-            );
362
-        }
363
-        return $nice_results;
364
-    }
365
-
366
-
367
-    /**
368
-     * Gets the collection for given relation object
369
-     * The same as Read::get_entities_from_model(), except if the relation
370
-     * is a HABTM relation, in which case it merges any non-foreign-key fields from
371
-     * the join-model-object into the results
372
-     *
373
-     * @param array                   $primary_model_query_params query params for finding the item from which
374
-     *                                                            relations will be based
375
-     * @param \EE_Model_Relation_Base $relation
376
-     * @param WP_REST_Request         $request
377
-     * @return WP_Error|array
378
-     * @throws RestException
379
-     */
380
-    protected function getEntitiesFromRelationUsingModelQueryParams($primary_model_query_params, $relation, $request)
381
-    {
382
-        $context = $this->validateContext($request->get_param('caps'));
383
-        $model = $relation->get_this_model();
384
-        $related_model = $relation->get_other_model();
385
-        if (! isset($primary_model_query_params[0])) {
386
-            $primary_model_query_params[0] = array();
387
-        }
388
-        // check if they can access the 1st model object
389
-        $primary_model_query_params = array(
390
-            0       => $primary_model_query_params[0],
391
-            'limit' => 1,
392
-        );
393
-        if ($model instanceof \EEM_Soft_Delete_Base) {
394
-            $primary_model_query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included(
395
-                $primary_model_query_params
396
-            );
397
-        }
398
-        $restricted_query_params = $primary_model_query_params;
399
-        $restricted_query_params['caps'] = $context;
400
-        $this->setDebugInfo('main model query params', $restricted_query_params);
401
-        $this->setDebugInfo('missing caps', Capabilities::getMissingPermissionsString($related_model, $context));
402
-        if (! (
403
-            Capabilities::currentUserHasPartialAccessTo($related_model, $context)
404
-            && $model->exists($restricted_query_params)
405
-        )
406
-        ) {
407
-            if ($relation instanceof EE_Belongs_To_Relation) {
408
-                $related_model_name_maybe_plural = strtolower($related_model->get_this_model_name());
409
-            } else {
410
-                $related_model_name_maybe_plural = EEH_Inflector::pluralize_and_lower(
411
-                    $related_model->get_this_model_name()
412
-                );
413
-            }
414
-            return new WP_Error(
415
-                sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural),
416
-                sprintf(
417
-                    __(
418
-                        'Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s',
419
-                        'event_espresso'
420
-                    ),
421
-                    $related_model_name_maybe_plural,
422
-                    $relation->get_this_model()->get_this_model_name(),
423
-                    implode(
424
-                        ',',
425
-                        array_keys(
426
-                            Capabilities::getMissingPermissions($related_model, $context)
427
-                        )
428
-                    )
429
-                ),
430
-                array('status' => 403)
431
-            );
432
-        }
433
-        $query_params = $this->createModelQueryParams($relation->get_other_model(), $request->get_params());
434
-        foreach ($primary_model_query_params[0] as $where_condition_key => $where_condition_value) {
435
-            $query_params[0][ $relation->get_this_model()->get_this_model_name()
436
-                              . '.'
437
-                              . $where_condition_key ] = $where_condition_value;
438
-        }
439
-        $query_params['default_where_conditions'] = 'none';
440
-        $query_params['caps'] = $context;
441
-        if (! $request->get_header('no_rest_headers')) {
442
-            $this->setHeadersFromQueryParams($relation->get_other_model(), $query_params);
443
-        }
444
-        /** @type array $results */
445
-        $results = $relation->get_other_model()->get_all_wpdb_results($query_params);
446
-        $nice_results = array();
447
-        foreach ($results as $result) {
448
-            $nice_result = $this->createEntityFromWpdbResult(
449
-                $relation->get_other_model(),
450
-                $result,
451
-                $request
452
-            );
453
-            if ($relation instanceof \EE_HABTM_Relation) {
454
-                // put the unusual stuff (properties from the HABTM relation) first, and make sure
455
-                // if there are conflicts we prefer the properties from the main model
456
-                $join_model_result = $this->createEntityFromWpdbResult(
457
-                    $relation->get_join_model(),
458
-                    $result,
459
-                    $request
460
-                );
461
-                $joined_result = array_merge($nice_result, $join_model_result);
462
-                // but keep the meta stuff from the main model
463
-                if (isset($nice_result['meta'])) {
464
-                    $joined_result['meta'] = $nice_result['meta'];
465
-                }
466
-                $nice_result = $joined_result;
467
-            }
468
-            $nice_results[] = $nice_result;
469
-        }
470
-        if ($relation instanceof EE_Belongs_To_Relation) {
471
-            return array_shift($nice_results);
472
-        } else {
473
-            return $nice_results;
474
-        }
475
-    }
476
-
477
-
478
-    /**
479
-     * Gets the collection for given relation object
480
-     * The same as Read::get_entities_from_model(), except if the relation
481
-     * is a HABTM relation, in which case it merges any non-foreign-key fields from
482
-     * the join-model-object into the results
483
-     *
484
-     * @param string                  $id the ID of the thing we are fetching related stuff from
485
-     * @param \EE_Model_Relation_Base $relation
486
-     * @param WP_REST_Request         $request
487
-     * @return array|WP_Error
488
-     * @throws EE_Error
489
-     */
490
-    public function getEntitiesFromRelation($id, $relation, $request)
491
-    {
492
-        if (! $relation->get_this_model()->has_primary_key_field()) {
493
-            throw new EE_Error(
494
-                sprintf(
495
-                    __(
496
-                    // @codingStandardsIgnoreStart
497
-                        'Read::get_entities_from_relation should only be called from a model with a primary key, it was called from %1$s',
498
-                        // @codingStandardsIgnoreEnd
499
-                        'event_espresso'
500
-                    ),
501
-                    $relation->get_this_model()->get_this_model_name()
502
-                )
503
-            );
504
-        }
505
-        return $this->getEntitiesFromRelationUsingModelQueryParams(
506
-            array(
507
-                array(
508
-                    $relation->get_this_model()->primary_key_name() => $id,
509
-                ),
510
-            ),
511
-            $relation,
512
-            $request
513
-        );
514
-    }
515
-
516
-
517
-    /**
518
-     * Sets the headers that are based on the model and query params,
519
-     * like the total records. This should only be called on the original request
520
-     * from the client, not on subsequent internal
521
-     *
522
-     * @param EEM_Base $model
523
-     * @param array    $query_params
524
-     * @return void
525
-     */
526
-    protected function setHeadersFromQueryParams($model, $query_params)
527
-    {
528
-        $this->setDebugInfo('model query params', $query_params);
529
-        $this->setDebugInfo(
530
-            'missing caps',
531
-            Capabilities::getMissingPermissionsString($model, $query_params['caps'])
532
-        );
533
-        // normally the limit to a 2-part array, where the 2nd item is the limit
534
-        if (! isset($query_params['limit'])) {
535
-            $query_params['limit'] = EED_Core_Rest_Api::get_default_query_limit();
536
-        }
537
-        if (is_array($query_params['limit'])) {
538
-            $limit_parts = $query_params['limit'];
539
-        } else {
540
-            $limit_parts = explode(',', $query_params['limit']);
541
-            if (count($limit_parts) == 1) {
542
-                $limit_parts = array(0, $limit_parts[0]);
543
-            }
544
-        }
545
-        // remove the group by and having parts of the query, as those will
546
-        // make the sql query return an array of values, instead of just a single value
547
-        unset($query_params['group_by'], $query_params['having'], $query_params['limit']);
548
-        $count = $model->count($query_params, null, true);
549
-        $pages = $count / $limit_parts[1];
550
-        $this->setResponseHeader('Total', $count, false);
551
-        $this->setResponseHeader('PageSize', $limit_parts[1], false);
552
-        $this->setResponseHeader('TotalPages', ceil($pages), false);
553
-    }
554
-
555
-
556
-    /**
557
-     * Changes database results into REST API entities
558
-     *
559
-     * @param EEM_Base        $model
560
-     * @param array           $db_row     like results from $wpdb->get_results()
561
-     * @param WP_REST_Request $rest_request
562
-     * @param string          $deprecated no longer used
563
-     * @return array ready for being converted into json for sending to client
564
-     */
565
-    public function createEntityFromWpdbResult($model, $db_row, $rest_request, $deprecated = null)
566
-    {
567
-        if (! $rest_request instanceof WP_REST_Request) {
568
-            // ok so this was called in the old style, where the 3rd arg was
569
-            // $include, and the 4th arg was $context
570
-            // now setup the request just to avoid fatal errors, although we won't be able
571
-            // to truly make use of it because it's kinda devoid of info
572
-            $rest_request = new WP_REST_Request();
573
-            $rest_request->set_param('include', $rest_request);
574
-            $rest_request->set_param('caps', $deprecated);
575
-        }
576
-        if ($rest_request->get_param('caps') == null) {
577
-            $rest_request->set_param('caps', EEM_Base::caps_read);
578
-        }
579
-        $entity_array = $this->createBareEntityFromWpdbResults($model, $db_row);
580
-        $entity_array = $this->addExtraFields($model, $db_row, $entity_array);
581
-        $entity_array['_links'] = $this->getEntityLinks($model, $db_row, $entity_array);
582
-        $entity_array['_calculated_fields'] = $this->getEntityCalculations($model, $db_row, $rest_request);
583
-        $entity_array = apply_filters(
584
-            'FHEE__Read__create_entity_from_wpdb_results__entity_before_including_requested_models',
585
-            $entity_array,
586
-            $model,
587
-            $rest_request->get_param('caps'),
588
-            $rest_request,
589
-            $this
590
-        );
591
-        $entity_array = $this->includeRequestedModels($model, $rest_request, $entity_array, $db_row);
592
-        $entity_array = apply_filters(
593
-            'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal',
594
-            $entity_array,
595
-            $model,
596
-            $rest_request->get_param('caps'),
597
-            $rest_request,
598
-            $this
599
-        );
600
-        $result_without_inaccessible_fields = Capabilities::filterOutInaccessibleEntityFields(
601
-            $entity_array,
602
-            $model,
603
-            $rest_request->get_param('caps'),
604
-            $this->getModelVersionInfo(),
605
-            $model->get_index_primary_key_string(
606
-                $model->deduce_fields_n_values_from_cols_n_values($db_row)
607
-            )
608
-        );
609
-        $this->setDebugInfo(
610
-            'inaccessible fields',
611
-            array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields))
612
-        );
613
-        return apply_filters(
614
-            'FHEE__Read__create_entity_from_wpdb_results__entity_return',
615
-            $result_without_inaccessible_fields,
616
-            $model,
617
-            $rest_request->get_param('caps')
618
-        );
619
-    }
620
-
621
-
622
-    /**
623
-     * Creates a REST entity array (JSON object we're going to return in the response, but
624
-     * for now still a PHP array, but soon enough we'll call json_encode on it, don't worry),
625
-     * from $wpdb->get_row( $sql, ARRAY_A)
626
-     *
627
-     * @param EEM_Base $model
628
-     * @param array    $db_row
629
-     * @return array entity mostly ready for converting to JSON and sending in the response
630
-     */
631
-    protected function createBareEntityFromWpdbResults(EEM_Base $model, $db_row)
632
-    {
633
-        $result = $model->deduce_fields_n_values_from_cols_n_values($db_row);
634
-        $result = array_intersect_key(
635
-            $result,
636
-            $this->getModelVersionInfo()->fieldsOnModelInThisVersion($model)
637
-        );
638
-        // if this is a CPT, we need to set the global $post to it,
639
-        // otherwise shortcodes etc won't work properly while rendering it
640
-        if ($model instanceof \EEM_CPT_Base) {
641
-            $do_chevy_shuffle = true;
642
-        } else {
643
-            $do_chevy_shuffle = false;
644
-        }
645
-        if ($do_chevy_shuffle) {
646
-            global $post;
647
-            $old_post = $post;
648
-            $post = get_post($result[ $model->primary_key_name() ]);
649
-            if (! $post instanceof \WP_Post) {
650
-                // well that's weird, because $result is what we JUST fetched from the database
651
-                throw new RestException(
652
-                    'error_fetching_post_from_database_results',
653
-                    esc_html__(
654
-                        'An item was retrieved from the database but it\'s not a WP_Post like it should be.',
655
-                        'event_espresso'
656
-                    )
657
-                );
658
-            }
659
-            $model_object_classname = 'EE_' . $model->get_this_model_name();
660
-            $post->{$model_object_classname} = \EE_Registry::instance()->load_class(
661
-                $model_object_classname,
662
-                $result,
663
-                false,
664
-                false
665
-            );
666
-        }
667
-        foreach ($result as $field_name => $field_value) {
668
-            $field_obj = $model->field_settings_for($field_name);
669
-            if ($this->isSubclassOfOne($field_obj, $this->getModelVersionInfo()->fieldsIgnored())) {
670
-                unset($result[ $field_name ]);
671
-            } elseif ($this->isSubclassOfOne(
672
-                $field_obj,
673
-                $this->getModelVersionInfo()->fieldsThatHaveRenderedFormat()
674
-            )
675
-            ) {
676
-                $result[ $field_name ] = array(
677
-                    'raw'      => $this->prepareFieldObjValueForJson($field_obj, $field_value),
678
-                    'rendered' => $this->prepareFieldObjValueForJson($field_obj, $field_value, 'pretty'),
679
-                );
680
-            } elseif ($this->isSubclassOfOne(
681
-                $field_obj,
682
-                $this->getModelVersionInfo()->fieldsThatHavePrettyFormat()
683
-            )
684
-            ) {
685
-                $result[ $field_name ] = array(
686
-                    'raw'    => $this->prepareFieldObjValueForJson($field_obj, $field_value),
687
-                    'pretty' => $this->prepareFieldObjValueForJson($field_obj, $field_value, 'pretty'),
688
-                );
689
-            } elseif ($field_obj instanceof \EE_Datetime_Field) {
690
-                $field_value = $field_obj->prepare_for_set_from_db($field_value);
691
-                $timezone = $field_value->getTimezone();
692
-                EEH_DTT_Helper::setTimezone($field_value, new DateTimeZone('UTC'));
693
-                $result[ $field_name . '_gmt' ] = ModelDataTranslator::prepareFieldValuesForJson(
694
-                    $field_obj,
695
-                    $field_value,
696
-                    $this->getModelVersionInfo()->requestedVersion()
697
-                );
698
-                EEH_DTT_Helper::setTimezone($field_value, $timezone);
699
-                $result[ $field_name ] = ModelDataTranslator::prepareFieldValuesForJson(
700
-                    $field_obj,
701
-                    $field_value,
702
-                    $this->getModelVersionInfo()->requestedVersion()
703
-                );
704
-            } else {
705
-                $result[ $field_name ] = $this->prepareFieldObjValueForJson($field_obj, $field_value);
706
-            }
707
-        }
708
-        if ($do_chevy_shuffle) {
709
-            $post = $old_post;
710
-        }
711
-        return $result;
712
-    }
713
-
714
-
715
-    /**
716
-     * Takes a value all the way from the DB representation, to the model object's representation, to the
717
-     * user-facing PHP representation, to the REST API representation. (Assumes you've already taken from the DB
718
-     * representation using $field_obj->prepare_for_set_from_db())
719
-     *
720
-     * @param EE_Model_Field_Base $field_obj
721
-     * @param mixed               $value  as it's stored on a model object
722
-     * @param string              $format valid values are 'normal' (default), 'pretty', 'datetime_obj'
723
-     * @return mixed
724
-     * @throws ObjectDetectedException if $value contains a PHP object
725
-     */
726
-    protected function prepareFieldObjValueForJson(EE_Model_Field_Base $field_obj, $value, $format = 'normal')
727
-    {
728
-        $value = $field_obj->prepare_for_set_from_db($value);
729
-        switch ($format) {
730
-            case 'pretty':
731
-                $value = $field_obj->prepare_for_pretty_echoing($value);
732
-                break;
733
-            case 'normal':
734
-            default:
735
-                $value = $field_obj->prepare_for_get($value);
736
-                break;
737
-        }
738
-        return ModelDataTranslator::prepareFieldValuesForJson(
739
-            $field_obj,
740
-            $value,
741
-            $this->getModelVersionInfo()->requestedVersion()
742
-        );
743
-    }
744
-
745
-
746
-    /**
747
-     * Adds a few extra fields to the entity response
748
-     *
749
-     * @param EEM_Base $model
750
-     * @param array    $db_row
751
-     * @param array    $entity_array
752
-     * @return array modified entity
753
-     */
754
-    protected function addExtraFields(EEM_Base $model, $db_row, $entity_array)
755
-    {
756
-        if ($model instanceof EEM_CPT_Base) {
757
-            $entity_array['link'] = get_permalink($db_row[ $model->get_primary_key_field()->get_qualified_column() ]);
758
-        }
759
-        return $entity_array;
760
-    }
761
-
762
-
763
-    /**
764
-     * Gets links we want to add to the response
765
-     *
766
-     * @global \WP_REST_Server $wp_rest_server
767
-     * @param EEM_Base         $model
768
-     * @param array            $db_row
769
-     * @param array            $entity_array
770
-     * @return array the _links item in the entity
771
-     */
772
-    protected function getEntityLinks($model, $db_row, $entity_array)
773
-    {
774
-        // add basic links
775
-        $links = array();
776
-        if ($model->has_primary_key_field()) {
777
-            $links['self'] = array(
778
-                array(
779
-                    'href' => $this->getVersionedLinkTo(
780
-                        EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
781
-                        . '/'
782
-                        . $entity_array[ $model->primary_key_name() ]
783
-                    ),
784
-                ),
785
-            );
786
-        }
787
-        $links['collection'] = array(
788
-            array(
789
-                'href' => $this->getVersionedLinkTo(
790
-                    EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
791
-                ),
792
-            ),
793
-        );
794
-        // add links to related models
795
-        if ($model->has_primary_key_field()) {
796
-            foreach ($this->getModelVersionInfo()->relationSettings($model) as $relation_name => $relation_obj) {
797
-                $related_model_part = Read::getRelatedEntityName($relation_name, $relation_obj);
798
-                $links[ EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part ] = array(
799
-                    array(
800
-                        'href'   => $this->getVersionedLinkTo(
801
-                            EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
802
-                            . '/'
803
-                            . $entity_array[ $model->primary_key_name() ]
804
-                            . '/'
805
-                            . $related_model_part
806
-                        ),
807
-                        'single' => $relation_obj instanceof EE_Belongs_To_Relation ? true : false,
808
-                    ),
809
-                );
810
-            }
811
-        }
812
-        return $links;
813
-    }
814
-
815
-
816
-    /**
817
-     * Adds the included models indicated in the request to the entity provided
818
-     *
819
-     * @param EEM_Base        $model
820
-     * @param WP_REST_Request $rest_request
821
-     * @param array           $entity_array
822
-     * @param array           $db_row
823
-     * @return array the modified entity
824
-     */
825
-    protected function includeRequestedModels(
826
-        EEM_Base $model,
827
-        WP_REST_Request $rest_request,
828
-        $entity_array,
829
-        $db_row = array()
830
-    ) {
831
-        // if $db_row not included, hope the entity array has what we need
832
-        if (! $db_row) {
833
-            $db_row = $entity_array;
834
-        }
835
-        $includes_for_this_model = $this->explodeAndGetItemsPrefixedWith($rest_request->get_param('include'), '');
836
-        $includes_for_this_model = $this->removeModelNamesFromArray($includes_for_this_model);
837
-        // if they passed in * or didn't specify any includes, return everything
838
-        if (! in_array('*', $includes_for_this_model)
839
-            && ! empty($includes_for_this_model)
840
-        ) {
841
-            if ($model->has_primary_key_field()) {
842
-                // always include the primary key. ya just gotta know that at least
843
-                $includes_for_this_model[] = $model->primary_key_name();
844
-            }
845
-            if ($this->explodeAndGetItemsPrefixedWith($rest_request->get_param('calculate'), '')) {
846
-                $includes_for_this_model[] = '_calculated_fields';
847
-            }
848
-            $entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model));
849
-        }
850
-        $relation_settings = $this->getModelVersionInfo()->relationSettings($model);
851
-        foreach ($relation_settings as $relation_name => $relation_obj) {
852
-            $related_fields_to_include = $this->explodeAndGetItemsPrefixedWith(
853
-                $rest_request->get_param('include'),
854
-                $relation_name
855
-            );
856
-            $related_fields_to_calculate = $this->explodeAndGetItemsPrefixedWith(
857
-                $rest_request->get_param('calculate'),
858
-                $relation_name
859
-            );
860
-            // did they specify they wanted to include a related model, or
861
-            // specific fields from a related model?
862
-            // or did they specify to calculate a field from a related model?
863
-            if ($related_fields_to_include || $related_fields_to_calculate) {
864
-                // if so, we should include at least some part of the related model
865
-                $pretend_related_request = new WP_REST_Request();
866
-                $pretend_related_request->set_query_params(
867
-                    array(
868
-                        'caps'      => $rest_request->get_param('caps'),
869
-                        'include'   => $related_fields_to_include,
870
-                        'calculate' => $related_fields_to_calculate,
871
-                    )
872
-                );
873
-                $pretend_related_request->add_header('no_rest_headers', true);
874
-                $primary_model_query_params = $model->alter_query_params_to_restrict_by_ID(
875
-                    $model->get_index_primary_key_string(
876
-                        $model->deduce_fields_n_values_from_cols_n_values($db_row)
877
-                    )
878
-                );
879
-                $related_results = $this->getEntitiesFromRelationUsingModelQueryParams(
880
-                    $primary_model_query_params,
881
-                    $relation_obj,
882
-                    $pretend_related_request
883
-                );
884
-                $entity_array[ Read::getRelatedEntityName($relation_name, $relation_obj) ] = $related_results
885
-                                                                                             instanceof
886
-                                                                                             WP_Error
887
-                    ? null
888
-                    : $related_results;
889
-            }
890
-        }
891
-        return $entity_array;
892
-    }
893
-
894
-
895
-    /**
896
-     * Returns a new array with all the names of models removed. Eg
897
-     * array( 'Event', 'Datetime.*', 'foobar' ) would become array( 'Datetime.*', 'foobar' )
898
-     *
899
-     * @param array $arr
900
-     * @return array
901
-     */
902
-    private function removeModelNamesFromArray($arr)
903
-    {
904
-        return array_diff($arr, array_keys(EE_Registry::instance()->non_abstract_db_models));
905
-    }
906
-
907
-
908
-    /**
909
-     * Gets the calculated fields for the response
910
-     *
911
-     * @param EEM_Base        $model
912
-     * @param array           $wpdb_row
913
-     * @param WP_REST_Request $rest_request
914
-     * @return \stdClass the _calculations item in the entity
915
-     * @throws ObjectDetectedException if a default value has a PHP object, which should never do (and if we
916
-     * did, let's know about it ASAP, so let the exception bubble up)
917
-     */
918
-    protected function getEntityCalculations($model, $wpdb_row, $rest_request)
919
-    {
920
-        $calculated_fields = $this->explodeAndGetItemsPrefixedWith(
921
-            $rest_request->get_param('calculate'),
922
-            ''
923
-        );
924
-        // note: setting calculate=* doesn't do anything
925
-        $calculated_fields_to_return = new \stdClass();
926
-        foreach ($calculated_fields as $field_to_calculate) {
927
-            try {
928
-                $calculated_fields_to_return->$field_to_calculate = ModelDataTranslator::prepareFieldValueForJson(
929
-                    null,
930
-                    $this->fields_calculator->retrieveCalculatedFieldValue(
931
-                        $model,
932
-                        $field_to_calculate,
933
-                        $wpdb_row,
934
-                        $rest_request,
935
-                        $this
936
-                    ),
937
-                    $this->getModelVersionInfo()->requestedVersion()
938
-                );
939
-            } catch (RestException $e) {
940
-                // if we don't have permission to read it, just leave it out. but let devs know about the problem
941
-                $this->setResponseHeader(
942
-                    'Notices-Field-Calculation-Errors['
943
-                    . $e->getStringCode()
944
-                    . ']['
945
-                    . $model->get_this_model_name()
946
-                    . ']['
947
-                    . $field_to_calculate
948
-                    . ']',
949
-                    $e->getMessage(),
950
-                    true
951
-                );
952
-            }
953
-        }
954
-        return $calculated_fields_to_return;
955
-    }
956
-
957
-
958
-    /**
959
-     * Gets the full URL to the resource, taking the requested version into account
960
-     *
961
-     * @param string $link_part_after_version_and_slash eg "events/10/datetimes"
962
-     * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes"
963
-     */
964
-    public function getVersionedLinkTo($link_part_after_version_and_slash)
965
-    {
966
-        return rest_url(
967
-            EED_Core_Rest_Api::get_versioned_route_to(
968
-                $link_part_after_version_and_slash,
969
-                $this->getModelVersionInfo()->requestedVersion()
970
-            )
971
-        );
972
-    }
973
-
974
-
975
-    /**
976
-     * Gets the correct lowercase name for the relation in the API according
977
-     * to the relation's type
978
-     *
979
-     * @param string                  $relation_name
980
-     * @param \EE_Model_Relation_Base $relation_obj
981
-     * @return string
982
-     */
983
-    public static function getRelatedEntityName($relation_name, $relation_obj)
984
-    {
985
-        if ($relation_obj instanceof EE_Belongs_To_Relation) {
986
-            return strtolower($relation_name);
987
-        } else {
988
-            return EEH_Inflector::pluralize_and_lower($relation_name);
989
-        }
990
-    }
991
-
992
-
993
-    /**
994
-     * Gets the one model object with the specified id for the specified model
995
-     *
996
-     * @param EEM_Base        $model
997
-     * @param WP_REST_Request $request
998
-     * @return array|WP_Error
999
-     */
1000
-    public function getEntityFromModel($model, $request)
1001
-    {
1002
-        $context = $this->validateContext($request->get_param('caps'));
1003
-        return $this->getOneOrReportPermissionError($model, $request, $context);
1004
-    }
1005
-
1006
-
1007
-    /**
1008
-     * If a context is provided which isn't valid, maybe it was added in a future
1009
-     * version so just treat it as a default read
1010
-     *
1011
-     * @param string $context
1012
-     * @return string array key of EEM_Base::cap_contexts_to_cap_action_map()
1013
-     */
1014
-    public function validateContext($context)
1015
-    {
1016
-        if (! $context) {
1017
-            $context = EEM_Base::caps_read;
1018
-        }
1019
-        $valid_contexts = EEM_Base::valid_cap_contexts();
1020
-        if (in_array($context, $valid_contexts)) {
1021
-            return $context;
1022
-        } else {
1023
-            return EEM_Base::caps_read;
1024
-        }
1025
-    }
1026
-
1027
-
1028
-    /**
1029
-     * Verifies the passed in value is an allowable default where conditions value.
1030
-     *
1031
-     * @param $default_query_params
1032
-     * @return string
1033
-     */
1034
-    public function validateDefaultQueryParams($default_query_params)
1035
-    {
1036
-        $valid_default_where_conditions_for_api_calls = array(
1037
-            EEM_Base::default_where_conditions_all,
1038
-            EEM_Base::default_where_conditions_minimum_all,
1039
-            EEM_Base::default_where_conditions_minimum_others,
1040
-        );
1041
-        if (! $default_query_params) {
1042
-            $default_query_params = EEM_Base::default_where_conditions_all;
1043
-        }
1044
-        if (in_array(
1045
-            $default_query_params,
1046
-            $valid_default_where_conditions_for_api_calls,
1047
-            true
1048
-        )) {
1049
-            return $default_query_params;
1050
-        } else {
1051
-            return EEM_Base::default_where_conditions_all;
1052
-        }
1053
-    }
1054
-
1055
-
1056
-    /**
1057
-     * Translates API filter get parameter into $query_params array used by EEM_Base::get_all().
1058
-     * Note: right now the query parameter keys for fields (and related fields)
1059
-     * can be left as-is, but it's quite possible this will change someday.
1060
-     * Also, this method's contents might be candidate for moving to Model_Data_Translator
1061
-     *
1062
-     * @param EEM_Base $model
1063
-     * @param array    $query_parameters  from $_GET parameter @see Read:handle_request_get_all
1064
-     * @return array like what EEM_Base::get_all() expects or FALSE to indicate
1065
-     *                                    that absolutely no results should be returned
1066
-     * @throws EE_Error
1067
-     * @throws RestException
1068
-     */
1069
-    public function createModelQueryParams($model, $query_parameters)
1070
-    {
1071
-        $model_query_params = array();
1072
-        if (isset($query_parameters['where'])) {
1073
-            $model_query_params[0] = ModelDataTranslator::prepareConditionsQueryParamsForModels(
1074
-                $query_parameters['where'],
1075
-                $model,
1076
-                $this->getModelVersionInfo()->requestedVersion()
1077
-            );
1078
-        }
1079
-        if (isset($query_parameters['order_by'])) {
1080
-            $order_by = $query_parameters['order_by'];
1081
-        } elseif (isset($query_parameters['orderby'])) {
1082
-            $order_by = $query_parameters['orderby'];
1083
-        } else {
1084
-            $order_by = null;
1085
-        }
1086
-        if ($order_by !== null) {
1087
-            if (is_array($order_by)) {
1088
-                $order_by = ModelDataTranslator::prepareFieldNamesInArrayKeysFromJson($order_by);
1089
-            } else {
1090
-                // it's a single item
1091
-                $order_by = ModelDataTranslator::prepareFieldNameFromJson($order_by);
1092
-            }
1093
-            $model_query_params['order_by'] = $order_by;
1094
-        }
1095
-        if (isset($query_parameters['group_by'])) {
1096
-            $group_by = $query_parameters['group_by'];
1097
-        } elseif (isset($query_parameters['groupby'])) {
1098
-            $group_by = $query_parameters['groupby'];
1099
-        } else {
1100
-            $group_by = array_keys($model->get_combined_primary_key_fields());
1101
-        }
1102
-        // make sure they're all real names
1103
-        if (is_array($group_by)) {
1104
-            $group_by = ModelDataTranslator::prepareFieldNamesFromJson($group_by);
1105
-        }
1106
-        if ($group_by !== null) {
1107
-            $model_query_params['group_by'] = $group_by;
1108
-        }
1109
-        if (isset($query_parameters['having'])) {
1110
-            $model_query_params['having'] = ModelDataTranslator::prepareConditionsQueryParamsForModels(
1111
-                $query_parameters['having'],
1112
-                $model,
1113
-                $this->getModelVersionInfo()->requestedVersion()
1114
-            );
1115
-        }
1116
-        if (isset($query_parameters['order'])) {
1117
-            $model_query_params['order'] = $query_parameters['order'];
1118
-        }
1119
-        if (isset($query_parameters['mine'])) {
1120
-            $model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params);
1121
-        }
1122
-        if (isset($query_parameters['limit'])) {
1123
-            // limit should be either a string like '23' or '23,43', or an array with two items in it
1124
-            if (! is_array($query_parameters['limit'])) {
1125
-                $limit_array = explode(',', (string) $query_parameters['limit']);
1126
-            } else {
1127
-                $limit_array = $query_parameters['limit'];
1128
-            }
1129
-            $sanitized_limit = array();
1130
-            foreach ($limit_array as $key => $limit_part) {
1131
-                if ($this->debug_mode && (! is_numeric($limit_part) || count($sanitized_limit) > 2)) {
1132
-                    throw new EE_Error(
1133
-                        sprintf(
1134
-                            __(
1135
-                            // @codingStandardsIgnoreStart
1136
-                                'An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.',
1137
-                                // @codingStandardsIgnoreEnd
1138
-                                'event_espresso'
1139
-                            ),
1140
-                            wp_json_encode($query_parameters['limit'])
1141
-                        )
1142
-                    );
1143
-                }
1144
-                $sanitized_limit[] = (int) $limit_part;
1145
-            }
1146
-            $model_query_params['limit'] = implode(',', $sanitized_limit);
1147
-        } else {
1148
-            $model_query_params['limit'] = EED_Core_Rest_Api::get_default_query_limit();
1149
-        }
1150
-        if (isset($query_parameters['caps'])) {
1151
-            $model_query_params['caps'] = $this->validateContext($query_parameters['caps']);
1152
-        } else {
1153
-            $model_query_params['caps'] = EEM_Base::caps_read;
1154
-        }
1155
-        if (isset($query_parameters['default_where_conditions'])) {
1156
-            $model_query_params['default_where_conditions'] = $this->validateDefaultQueryParams(
1157
-                $query_parameters['default_where_conditions']
1158
-            );
1159
-        }
1160
-        return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model);
1161
-    }
1162
-
1163
-
1164
-    /**
1165
-     * Changes the REST-style query params for use in the models
1166
-     *
1167
-     * @deprecated
1168
-     * @param EEM_Base $model
1169
-     * @param array    $query_params sub-array from @see EEM_Base::get_all()
1170
-     * @return array
1171
-     */
1172
-    public function prepareRestQueryParamsKeyForModels($model, $query_params)
1173
-    {
1174
-        $model_ready_query_params = array();
1175
-        foreach ($query_params as $key => $value) {
1176
-            if (is_array($value)) {
1177
-                $model_ready_query_params[ $key ] = $this->prepareRestQueryParamsKeyForModels($model, $value);
1178
-            } else {
1179
-                $model_ready_query_params[ $key ] = $value;
1180
-            }
1181
-        }
1182
-        return $model_ready_query_params;
1183
-    }
1184
-
1185
-
1186
-    /**
1187
-     * @deprecated instead use ModelDataTranslator::prepareFieldValuesFromJson()
1188
-     * @param $model
1189
-     * @param $query_params
1190
-     * @return array
1191
-     */
1192
-    public function prepareRestQueryParamsValuesForModels($model, $query_params)
1193
-    {
1194
-        $model_ready_query_params = array();
1195
-        foreach ($query_params as $key => $value) {
1196
-            if (is_array($value)) {
1197
-                $model_ready_query_params[ $key ] = $this->prepareRestQueryParamsValuesForModels($model, $value);
1198
-            } else {
1199
-                $model_ready_query_params[ $key ] = $value;
1200
-            }
1201
-        }
1202
-        return $model_ready_query_params;
1203
-    }
1204
-
1205
-
1206
-    /**
1207
-     * Explodes the string on commas, and only returns items with $prefix followed by a period.
1208
-     * If no prefix is specified, returns items with no period.
1209
-     *
1210
-     * @param string|array $string_to_explode eg "jibba,jabba, blah, blah, blah" or array('jibba', 'jabba' )
1211
-     * @param string       $prefix            "Event" or "foobar"
1212
-     * @return array $string_to_exploded exploded on COMMAS, and if a prefix was specified
1213
-     *                                        we only return strings starting with that and a period; if no prefix was
1214
-     *                                        specified we return all items containing NO periods
1215
-     */
1216
-    public function explodeAndGetItemsPrefixedWith($string_to_explode, $prefix)
1217
-    {
1218
-        if (is_string($string_to_explode)) {
1219
-            $exploded_contents = explode(',', $string_to_explode);
1220
-        } elseif (is_array($string_to_explode)) {
1221
-            $exploded_contents = $string_to_explode;
1222
-        } else {
1223
-            $exploded_contents = array();
1224
-        }
1225
-        // if the string was empty, we want an empty array
1226
-        $exploded_contents = array_filter($exploded_contents);
1227
-        $contents_with_prefix = array();
1228
-        foreach ($exploded_contents as $item) {
1229
-            $item = trim($item);
1230
-            // if no prefix was provided, so we look for items with no "." in them
1231
-            if (! $prefix) {
1232
-                // does this item have a period?
1233
-                if (strpos($item, '.') === false) {
1234
-                    // if not, then its what we're looking for
1235
-                    $contents_with_prefix[] = $item;
1236
-                }
1237
-            } elseif (strpos($item, $prefix . '.') === 0) {
1238
-                // this item has the prefix and a period, grab it
1239
-                $contents_with_prefix[] = substr(
1240
-                    $item,
1241
-                    strpos($item, $prefix . '.') + strlen($prefix . '.')
1242
-                );
1243
-            } elseif ($item === $prefix) {
1244
-                // this item is JUST the prefix
1245
-                // so let's grab everything after, which is a blank string
1246
-                $contents_with_prefix[] = '';
1247
-            }
1248
-        }
1249
-        return $contents_with_prefix;
1250
-    }
1251
-
1252
-
1253
-    /**
1254
-     * @deprecated since 4.8.36.rc.001 You should instead use Read::explode_and_get_items_prefixed_with.
1255
-     * Deprecated because its return values were really quite confusing- sometimes it returned
1256
-     * an empty array (when the include string was blank or '*') or sometimes it returned
1257
-     * array('*') (when you provided a model and a model of that kind was found).
1258
-     * Parses the $include_string so we fetch all the field names relating to THIS model
1259
-     * (ie have NO period in them), or for the provided model (ie start with the model
1260
-     * name and then a period).
1261
-     * @param string $include_string @see Read:handle_request_get_all
1262
-     * @param string $model_name
1263
-     * @return array of fields for this model. If $model_name is provided, then
1264
-     *                               the fields for that model, with the model's name removed from each.
1265
-     *                               If $include_string was blank or '*' returns an empty array
1266
-     */
1267
-    public function extractIncludesForThisModel($include_string, $model_name = null)
1268
-    {
1269
-        if (is_array($include_string)) {
1270
-            $include_string = implode(',', $include_string);
1271
-        }
1272
-        if ($include_string === '*' || $include_string === '') {
1273
-            return array();
1274
-        }
1275
-        $includes = explode(',', $include_string);
1276
-        $extracted_fields_to_include = array();
1277
-        if ($model_name) {
1278
-            foreach ($includes as $field_to_include) {
1279
-                $field_to_include = trim($field_to_include);
1280
-                if (strpos($field_to_include, $model_name . '.') === 0) {
1281
-                    // found the model name at the exact start
1282
-                    $field_sans_model_name = str_replace($model_name . '.', '', $field_to_include);
1283
-                    $extracted_fields_to_include[] = $field_sans_model_name;
1284
-                } elseif ($field_to_include == $model_name) {
1285
-                    $extracted_fields_to_include[] = '*';
1286
-                }
1287
-            }
1288
-        } else {
1289
-            // look for ones with no period
1290
-            foreach ($includes as $field_to_include) {
1291
-                $field_to_include = trim($field_to_include);
1292
-                if (strpos($field_to_include, '.') === false
1293
-                    && ! $this->getModelVersionInfo()->isModelNameInThisVersion($field_to_include)
1294
-                ) {
1295
-                    $extracted_fields_to_include[] = $field_to_include;
1296
-                }
1297
-            }
1298
-        }
1299
-        return $extracted_fields_to_include;
1300
-    }
1301
-
1302
-
1303
-    /**
1304
-     * Gets the single item using the model according to the request in the context given, otherwise
1305
-     * returns that it's inaccessible to the current user
1306
-     *
1307
-     * @param EEM_Base        $model
1308
-     * @param WP_REST_Request $request
1309
-     * @param null            $context
1310
-     * @return array|WP_Error
1311
-     */
1312
-    public function getOneOrReportPermissionError(EEM_Base $model, WP_REST_Request $request, $context = null)
1313
-    {
1314
-        $query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1);
1315
-        if ($model instanceof \EEM_Soft_Delete_Base) {
1316
-            $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params);
1317
-        }
1318
-        $restricted_query_params = $query_params;
1319
-        $restricted_query_params['caps'] = $context;
1320
-        $this->setDebugInfo('model query params', $restricted_query_params);
1321
-        $model_rows = $model->get_all_wpdb_results($restricted_query_params);
1322
-        if (! empty($model_rows)) {
1323
-            return $this->createEntityFromWpdbResult(
1324
-                $model,
1325
-                array_shift($model_rows),
1326
-                $request
1327
-            );
1328
-        } else {
1329
-            // ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities
1330
-            $lowercase_model_name = strtolower($model->get_this_model_name());
1331
-            $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params);
1332
-            if (! empty($model_rows_found_sans_restrictions)) {
1333
-                // you got shafted- it existed but we didn't want to tell you!
1334
-                return new WP_Error(
1335
-                    'rest_user_cannot_' . $context,
1336
-                    sprintf(
1337
-                        __('Sorry, you cannot %1$s this %2$s. Missing permissions are: %3$s', 'event_espresso'),
1338
-                        $context,
1339
-                        strtolower($model->get_this_model_name()),
1340
-                        Capabilities::getMissingPermissionsString(
1341
-                            $model,
1342
-                            $context
1343
-                        )
1344
-                    ),
1345
-                    array('status' => 403)
1346
-                );
1347
-            } else {
1348
-                // it's not you. It just doesn't exist
1349
-                return new WP_Error(
1350
-                    sprintf('rest_%s_invalid_id', $lowercase_model_name),
1351
-                    sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name),
1352
-                    array('status' => 404)
1353
-                );
1354
-            }
1355
-        }
1356
-    }
38
+	/**
39
+	 * @var CalculatedModelFields
40
+	 */
41
+	protected $fields_calculator;
42
+
43
+
44
+	/**
45
+	 * Read constructor.
46
+	 */
47
+	public function __construct()
48
+	{
49
+		parent::__construct();
50
+		$this->fields_calculator = new CalculatedModelFields();
51
+	}
52
+
53
+
54
+	/**
55
+	 * Handles requests to get all (or a filtered subset) of entities for a particular model
56
+	 *
57
+	 * @param WP_REST_Request $request
58
+	 * @param string          $version
59
+	 * @param string          $model_name
60
+	 * @return \WP_REST_Response|WP_Error
61
+	 */
62
+	public static function handleRequestGetAll(WP_REST_Request $request, $version, $model_name)
63
+	{
64
+		$controller = new Read();
65
+		try {
66
+			$controller->setRequestedVersion($version);
67
+			if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
68
+				return $controller->sendResponse(
69
+					new WP_Error(
70
+						'endpoint_parsing_error',
71
+						sprintf(
72
+							__(
73
+								'There is no model for endpoint %s. Please contact event espresso support',
74
+								'event_espresso'
75
+							),
76
+							$model_name
77
+						)
78
+					)
79
+				);
80
+			}
81
+			return $controller->sendResponse(
82
+				$controller->getEntitiesFromModel(
83
+					$controller->getModelVersionInfo()->loadModel($model_name),
84
+					$request
85
+				)
86
+			);
87
+		} catch (Exception $e) {
88
+			return $controller->sendResponse($e);
89
+		}
90
+	}
91
+
92
+
93
+	/**
94
+	 * Prepares and returns schema for any OPTIONS request.
95
+	 *
96
+	 * @param string $version    The API endpoint version being used.
97
+	 * @param string $model_name Something like `Event` or `Registration`
98
+	 * @return array
99
+	 */
100
+	public static function handleSchemaRequest($version, $model_name)
101
+	{
102
+		$controller = new Read();
103
+		try {
104
+			$controller->setRequestedVersion($version);
105
+			if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
106
+				return array();
107
+			}
108
+			// get the model for this version
109
+			$model = $controller->getModelVersionInfo()->loadModel($model_name);
110
+			$model_schema = new JsonModelSchema($model);
111
+			return $model_schema->getModelSchemaForRelations(
112
+				$controller->getModelVersionInfo()->relationSettings($model),
113
+				$controller->customizeSchemaForRestResponse(
114
+					$model,
115
+					$model_schema->getModelSchemaForFields(
116
+						$controller->getModelVersionInfo()->fieldsOnModelInThisVersion($model),
117
+						$model_schema->getInitialSchemaStructure()
118
+					)
119
+				)
120
+			);
121
+		} catch (Exception $e) {
122
+			return array();
123
+		}
124
+	}
125
+
126
+
127
+	/**
128
+	 * This loops through each field in the given schema for the model and does the following:
129
+	 * - add any extra fields that are REST API specific and related to existing fields.
130
+	 * - transform default values into the correct format for a REST API response.
131
+	 *
132
+	 * @param EEM_Base $model
133
+	 * @param array    $schema
134
+	 * @return array  The final schema.
135
+	 */
136
+	protected function customizeSchemaForRestResponse(EEM_Base $model, array $schema)
137
+	{
138
+		foreach ($this->getModelVersionInfo()->fieldsOnModelInThisVersion($model) as $field_name => $field) {
139
+			$schema = $this->translateDefaultsForRestResponse(
140
+				$field_name,
141
+				$field,
142
+				$this->maybeAddExtraFieldsToSchema($field_name, $field, $schema)
143
+			);
144
+		}
145
+		return $schema;
146
+	}
147
+
148
+
149
+	/**
150
+	 * This is used to ensure that the 'default' value set in the schema response is formatted correctly for the REST
151
+	 * response.
152
+	 *
153
+	 * @param                      $field_name
154
+	 * @param EE_Model_Field_Base  $field
155
+	 * @param array                $schema
156
+	 * @return array
157
+	 * @throws ObjectDetectedException if a default value has a PHP object, which should never do (and if we
158
+	 * did, let's know about it ASAP, so let the exception bubble up)
159
+	 */
160
+	protected function translateDefaultsForRestResponse($field_name, EE_Model_Field_Base $field, array $schema)
161
+	{
162
+		if (isset($schema['properties'][ $field_name ]['default'])) {
163
+			if (is_array($schema['properties'][ $field_name ]['default'])) {
164
+				foreach ($schema['properties'][ $field_name ]['default'] as $default_key => $default_value) {
165
+					if ($default_key === 'raw') {
166
+						$schema['properties'][ $field_name ]['default'][ $default_key ] =
167
+							ModelDataTranslator::prepareFieldValueForJson(
168
+								$field,
169
+								$default_value,
170
+								$this->getModelVersionInfo()->requestedVersion()
171
+							);
172
+					}
173
+				}
174
+			} else {
175
+				$schema['properties'][ $field_name ]['default'] = ModelDataTranslator::prepareFieldValueForJson(
176
+					$field,
177
+					$schema['properties'][ $field_name ]['default'],
178
+					$this->getModelVersionInfo()->requestedVersion()
179
+				);
180
+			}
181
+		}
182
+		return $schema;
183
+	}
184
+
185
+
186
+	/**
187
+	 * Adds additional fields to the schema
188
+	 * The REST API returns a GMT value field for each datetime field in the resource.  Thus the description about this
189
+	 * needs to be added to the schema.
190
+	 *
191
+	 * @param                      $field_name
192
+	 * @param EE_Model_Field_Base  $field
193
+	 * @param array                $schema
194
+	 * @return array
195
+	 */
196
+	protected function maybeAddExtraFieldsToSchema($field_name, EE_Model_Field_Base $field, array $schema)
197
+	{
198
+		if ($field instanceof EE_Datetime_Field) {
199
+			$schema['properties'][ $field_name . '_gmt' ] = $field->getSchema();
200
+			// modify the description
201
+			$schema['properties'][ $field_name . '_gmt' ]['description'] = sprintf(
202
+				esc_html__('%s - the value for this field is in GMT.', 'event_espresso'),
203
+				wp_specialchars_decode($field->get_nicename(), ENT_QUOTES)
204
+			);
205
+		}
206
+		return $schema;
207
+	}
208
+
209
+
210
+	/**
211
+	 * Used to figure out the route from the request when a `WP_REST_Request` object is not available
212
+	 *
213
+	 * @return string
214
+	 */
215
+	protected function getRouteFromRequest()
216
+	{
217
+		if (isset($GLOBALS['wp'])
218
+			&& $GLOBALS['wp'] instanceof \WP
219
+			&& isset($GLOBALS['wp']->query_vars['rest_route'])
220
+		) {
221
+			return $GLOBALS['wp']->query_vars['rest_route'];
222
+		} else {
223
+			return isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/';
224
+		}
225
+	}
226
+
227
+
228
+	/**
229
+	 * Gets a single entity related to the model indicated in the path and its id
230
+	 *
231
+	 * @param WP_REST_Request $request
232
+	 * @param string          $version
233
+	 * @param string          $model_name
234
+	 * @return \WP_REST_Response|WP_Error
235
+	 */
236
+	public static function handleRequestGetOne(WP_REST_Request $request, $version, $model_name)
237
+	{
238
+		$controller = new Read();
239
+		try {
240
+			$controller->setRequestedVersion($version);
241
+			if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
242
+				return $controller->sendResponse(
243
+					new WP_Error(
244
+						'endpoint_parsing_error',
245
+						sprintf(
246
+							__(
247
+								'There is no model for endpoint %s. Please contact event espresso support',
248
+								'event_espresso'
249
+							),
250
+							$model_name
251
+						)
252
+					)
253
+				);
254
+			}
255
+			return $controller->sendResponse(
256
+				$controller->getEntityFromModel(
257
+					$controller->getModelVersionInfo()->loadModel($model_name),
258
+					$request
259
+				)
260
+			);
261
+		} catch (Exception $e) {
262
+			return $controller->sendResponse($e);
263
+		}
264
+	}
265
+
266
+
267
+	/**
268
+	 * Gets all the related entities (or if its a belongs-to relation just the one)
269
+	 * to the item with the given id
270
+	 *
271
+	 * @param WP_REST_Request $request
272
+	 * @param string          $version
273
+	 * @param string          $model_name
274
+	 * @param string          $related_model_name
275
+	 * @return \WP_REST_Response|WP_Error
276
+	 */
277
+	public static function handleRequestGetRelated(
278
+		WP_REST_Request $request,
279
+		$version,
280
+		$model_name,
281
+		$related_model_name
282
+	) {
283
+		$controller = new Read();
284
+		try {
285
+			$controller->setRequestedVersion($version);
286
+			if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
287
+				return $controller->sendResponse(
288
+					new WP_Error(
289
+						'endpoint_parsing_error',
290
+						sprintf(
291
+							__(
292
+								'There is no model for endpoint %s. Please contact event espresso support',
293
+								'event_espresso'
294
+							),
295
+							$model_name
296
+						)
297
+					)
298
+				);
299
+			}
300
+			$main_model = $controller->getModelVersionInfo()->loadModel($model_name);
301
+			if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($related_model_name)) {
302
+				return $controller->sendResponse(
303
+					new WP_Error(
304
+						'endpoint_parsing_error',
305
+						sprintf(
306
+							__(
307
+								'There is no model for endpoint %s. Please contact event espresso support',
308
+								'event_espresso'
309
+							),
310
+							$related_model_name
311
+						)
312
+					)
313
+				);
314
+			}
315
+			return $controller->sendResponse(
316
+				$controller->getEntitiesFromRelation(
317
+					$request->get_param('id'),
318
+					$main_model->related_settings_for($related_model_name),
319
+					$request
320
+				)
321
+			);
322
+		} catch (Exception $e) {
323
+			return $controller->sendResponse($e);
324
+		}
325
+	}
326
+
327
+
328
+	/**
329
+	 * Gets a collection for the given model and filters
330
+	 *
331
+	 * @param EEM_Base        $model
332
+	 * @param WP_REST_Request $request
333
+	 * @return array|WP_Error
334
+	 */
335
+	public function getEntitiesFromModel($model, $request)
336
+	{
337
+		$query_params = $this->createModelQueryParams($model, $request->get_params());
338
+		if (! Capabilities::currentUserHasPartialAccessTo($model, $query_params['caps'])) {
339
+			$model_name_plural = EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
340
+			return new WP_Error(
341
+				sprintf('rest_%s_cannot_list', $model_name_plural),
342
+				sprintf(
343
+					__('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'),
344
+					$model_name_plural,
345
+					Capabilities::getMissingPermissionsString($model, $query_params['caps'])
346
+				),
347
+				array('status' => 403)
348
+			);
349
+		}
350
+		if (! $request->get_header('no_rest_headers')) {
351
+			$this->setHeadersFromQueryParams($model, $query_params);
352
+		}
353
+		/** @type array $results */
354
+		$results = $model->get_all_wpdb_results($query_params);
355
+		$nice_results = array();
356
+		foreach ($results as $result) {
357
+			$nice_results[] = $this->createEntityFromWpdbResult(
358
+				$model,
359
+				$result,
360
+				$request
361
+			);
362
+		}
363
+		return $nice_results;
364
+	}
365
+
366
+
367
+	/**
368
+	 * Gets the collection for given relation object
369
+	 * The same as Read::get_entities_from_model(), except if the relation
370
+	 * is a HABTM relation, in which case it merges any non-foreign-key fields from
371
+	 * the join-model-object into the results
372
+	 *
373
+	 * @param array                   $primary_model_query_params query params for finding the item from which
374
+	 *                                                            relations will be based
375
+	 * @param \EE_Model_Relation_Base $relation
376
+	 * @param WP_REST_Request         $request
377
+	 * @return WP_Error|array
378
+	 * @throws RestException
379
+	 */
380
+	protected function getEntitiesFromRelationUsingModelQueryParams($primary_model_query_params, $relation, $request)
381
+	{
382
+		$context = $this->validateContext($request->get_param('caps'));
383
+		$model = $relation->get_this_model();
384
+		$related_model = $relation->get_other_model();
385
+		if (! isset($primary_model_query_params[0])) {
386
+			$primary_model_query_params[0] = array();
387
+		}
388
+		// check if they can access the 1st model object
389
+		$primary_model_query_params = array(
390
+			0       => $primary_model_query_params[0],
391
+			'limit' => 1,
392
+		);
393
+		if ($model instanceof \EEM_Soft_Delete_Base) {
394
+			$primary_model_query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included(
395
+				$primary_model_query_params
396
+			);
397
+		}
398
+		$restricted_query_params = $primary_model_query_params;
399
+		$restricted_query_params['caps'] = $context;
400
+		$this->setDebugInfo('main model query params', $restricted_query_params);
401
+		$this->setDebugInfo('missing caps', Capabilities::getMissingPermissionsString($related_model, $context));
402
+		if (! (
403
+			Capabilities::currentUserHasPartialAccessTo($related_model, $context)
404
+			&& $model->exists($restricted_query_params)
405
+		)
406
+		) {
407
+			if ($relation instanceof EE_Belongs_To_Relation) {
408
+				$related_model_name_maybe_plural = strtolower($related_model->get_this_model_name());
409
+			} else {
410
+				$related_model_name_maybe_plural = EEH_Inflector::pluralize_and_lower(
411
+					$related_model->get_this_model_name()
412
+				);
413
+			}
414
+			return new WP_Error(
415
+				sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural),
416
+				sprintf(
417
+					__(
418
+						'Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s',
419
+						'event_espresso'
420
+					),
421
+					$related_model_name_maybe_plural,
422
+					$relation->get_this_model()->get_this_model_name(),
423
+					implode(
424
+						',',
425
+						array_keys(
426
+							Capabilities::getMissingPermissions($related_model, $context)
427
+						)
428
+					)
429
+				),
430
+				array('status' => 403)
431
+			);
432
+		}
433
+		$query_params = $this->createModelQueryParams($relation->get_other_model(), $request->get_params());
434
+		foreach ($primary_model_query_params[0] as $where_condition_key => $where_condition_value) {
435
+			$query_params[0][ $relation->get_this_model()->get_this_model_name()
436
+							  . '.'
437
+							  . $where_condition_key ] = $where_condition_value;
438
+		}
439
+		$query_params['default_where_conditions'] = 'none';
440
+		$query_params['caps'] = $context;
441
+		if (! $request->get_header('no_rest_headers')) {
442
+			$this->setHeadersFromQueryParams($relation->get_other_model(), $query_params);
443
+		}
444
+		/** @type array $results */
445
+		$results = $relation->get_other_model()->get_all_wpdb_results($query_params);
446
+		$nice_results = array();
447
+		foreach ($results as $result) {
448
+			$nice_result = $this->createEntityFromWpdbResult(
449
+				$relation->get_other_model(),
450
+				$result,
451
+				$request
452
+			);
453
+			if ($relation instanceof \EE_HABTM_Relation) {
454
+				// put the unusual stuff (properties from the HABTM relation) first, and make sure
455
+				// if there are conflicts we prefer the properties from the main model
456
+				$join_model_result = $this->createEntityFromWpdbResult(
457
+					$relation->get_join_model(),
458
+					$result,
459
+					$request
460
+				);
461
+				$joined_result = array_merge($nice_result, $join_model_result);
462
+				// but keep the meta stuff from the main model
463
+				if (isset($nice_result['meta'])) {
464
+					$joined_result['meta'] = $nice_result['meta'];
465
+				}
466
+				$nice_result = $joined_result;
467
+			}
468
+			$nice_results[] = $nice_result;
469
+		}
470
+		if ($relation instanceof EE_Belongs_To_Relation) {
471
+			return array_shift($nice_results);
472
+		} else {
473
+			return $nice_results;
474
+		}
475
+	}
476
+
477
+
478
+	/**
479
+	 * Gets the collection for given relation object
480
+	 * The same as Read::get_entities_from_model(), except if the relation
481
+	 * is a HABTM relation, in which case it merges any non-foreign-key fields from
482
+	 * the join-model-object into the results
483
+	 *
484
+	 * @param string                  $id the ID of the thing we are fetching related stuff from
485
+	 * @param \EE_Model_Relation_Base $relation
486
+	 * @param WP_REST_Request         $request
487
+	 * @return array|WP_Error
488
+	 * @throws EE_Error
489
+	 */
490
+	public function getEntitiesFromRelation($id, $relation, $request)
491
+	{
492
+		if (! $relation->get_this_model()->has_primary_key_field()) {
493
+			throw new EE_Error(
494
+				sprintf(
495
+					__(
496
+					// @codingStandardsIgnoreStart
497
+						'Read::get_entities_from_relation should only be called from a model with a primary key, it was called from %1$s',
498
+						// @codingStandardsIgnoreEnd
499
+						'event_espresso'
500
+					),
501
+					$relation->get_this_model()->get_this_model_name()
502
+				)
503
+			);
504
+		}
505
+		return $this->getEntitiesFromRelationUsingModelQueryParams(
506
+			array(
507
+				array(
508
+					$relation->get_this_model()->primary_key_name() => $id,
509
+				),
510
+			),
511
+			$relation,
512
+			$request
513
+		);
514
+	}
515
+
516
+
517
+	/**
518
+	 * Sets the headers that are based on the model and query params,
519
+	 * like the total records. This should only be called on the original request
520
+	 * from the client, not on subsequent internal
521
+	 *
522
+	 * @param EEM_Base $model
523
+	 * @param array    $query_params
524
+	 * @return void
525
+	 */
526
+	protected function setHeadersFromQueryParams($model, $query_params)
527
+	{
528
+		$this->setDebugInfo('model query params', $query_params);
529
+		$this->setDebugInfo(
530
+			'missing caps',
531
+			Capabilities::getMissingPermissionsString($model, $query_params['caps'])
532
+		);
533
+		// normally the limit to a 2-part array, where the 2nd item is the limit
534
+		if (! isset($query_params['limit'])) {
535
+			$query_params['limit'] = EED_Core_Rest_Api::get_default_query_limit();
536
+		}
537
+		if (is_array($query_params['limit'])) {
538
+			$limit_parts = $query_params['limit'];
539
+		} else {
540
+			$limit_parts = explode(',', $query_params['limit']);
541
+			if (count($limit_parts) == 1) {
542
+				$limit_parts = array(0, $limit_parts[0]);
543
+			}
544
+		}
545
+		// remove the group by and having parts of the query, as those will
546
+		// make the sql query return an array of values, instead of just a single value
547
+		unset($query_params['group_by'], $query_params['having'], $query_params['limit']);
548
+		$count = $model->count($query_params, null, true);
549
+		$pages = $count / $limit_parts[1];
550
+		$this->setResponseHeader('Total', $count, false);
551
+		$this->setResponseHeader('PageSize', $limit_parts[1], false);
552
+		$this->setResponseHeader('TotalPages', ceil($pages), false);
553
+	}
554
+
555
+
556
+	/**
557
+	 * Changes database results into REST API entities
558
+	 *
559
+	 * @param EEM_Base        $model
560
+	 * @param array           $db_row     like results from $wpdb->get_results()
561
+	 * @param WP_REST_Request $rest_request
562
+	 * @param string          $deprecated no longer used
563
+	 * @return array ready for being converted into json for sending to client
564
+	 */
565
+	public function createEntityFromWpdbResult($model, $db_row, $rest_request, $deprecated = null)
566
+	{
567
+		if (! $rest_request instanceof WP_REST_Request) {
568
+			// ok so this was called in the old style, where the 3rd arg was
569
+			// $include, and the 4th arg was $context
570
+			// now setup the request just to avoid fatal errors, although we won't be able
571
+			// to truly make use of it because it's kinda devoid of info
572
+			$rest_request = new WP_REST_Request();
573
+			$rest_request->set_param('include', $rest_request);
574
+			$rest_request->set_param('caps', $deprecated);
575
+		}
576
+		if ($rest_request->get_param('caps') == null) {
577
+			$rest_request->set_param('caps', EEM_Base::caps_read);
578
+		}
579
+		$entity_array = $this->createBareEntityFromWpdbResults($model, $db_row);
580
+		$entity_array = $this->addExtraFields($model, $db_row, $entity_array);
581
+		$entity_array['_links'] = $this->getEntityLinks($model, $db_row, $entity_array);
582
+		$entity_array['_calculated_fields'] = $this->getEntityCalculations($model, $db_row, $rest_request);
583
+		$entity_array = apply_filters(
584
+			'FHEE__Read__create_entity_from_wpdb_results__entity_before_including_requested_models',
585
+			$entity_array,
586
+			$model,
587
+			$rest_request->get_param('caps'),
588
+			$rest_request,
589
+			$this
590
+		);
591
+		$entity_array = $this->includeRequestedModels($model, $rest_request, $entity_array, $db_row);
592
+		$entity_array = apply_filters(
593
+			'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal',
594
+			$entity_array,
595
+			$model,
596
+			$rest_request->get_param('caps'),
597
+			$rest_request,
598
+			$this
599
+		);
600
+		$result_without_inaccessible_fields = Capabilities::filterOutInaccessibleEntityFields(
601
+			$entity_array,
602
+			$model,
603
+			$rest_request->get_param('caps'),
604
+			$this->getModelVersionInfo(),
605
+			$model->get_index_primary_key_string(
606
+				$model->deduce_fields_n_values_from_cols_n_values($db_row)
607
+			)
608
+		);
609
+		$this->setDebugInfo(
610
+			'inaccessible fields',
611
+			array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields))
612
+		);
613
+		return apply_filters(
614
+			'FHEE__Read__create_entity_from_wpdb_results__entity_return',
615
+			$result_without_inaccessible_fields,
616
+			$model,
617
+			$rest_request->get_param('caps')
618
+		);
619
+	}
620
+
621
+
622
+	/**
623
+	 * Creates a REST entity array (JSON object we're going to return in the response, but
624
+	 * for now still a PHP array, but soon enough we'll call json_encode on it, don't worry),
625
+	 * from $wpdb->get_row( $sql, ARRAY_A)
626
+	 *
627
+	 * @param EEM_Base $model
628
+	 * @param array    $db_row
629
+	 * @return array entity mostly ready for converting to JSON and sending in the response
630
+	 */
631
+	protected function createBareEntityFromWpdbResults(EEM_Base $model, $db_row)
632
+	{
633
+		$result = $model->deduce_fields_n_values_from_cols_n_values($db_row);
634
+		$result = array_intersect_key(
635
+			$result,
636
+			$this->getModelVersionInfo()->fieldsOnModelInThisVersion($model)
637
+		);
638
+		// if this is a CPT, we need to set the global $post to it,
639
+		// otherwise shortcodes etc won't work properly while rendering it
640
+		if ($model instanceof \EEM_CPT_Base) {
641
+			$do_chevy_shuffle = true;
642
+		} else {
643
+			$do_chevy_shuffle = false;
644
+		}
645
+		if ($do_chevy_shuffle) {
646
+			global $post;
647
+			$old_post = $post;
648
+			$post = get_post($result[ $model->primary_key_name() ]);
649
+			if (! $post instanceof \WP_Post) {
650
+				// well that's weird, because $result is what we JUST fetched from the database
651
+				throw new RestException(
652
+					'error_fetching_post_from_database_results',
653
+					esc_html__(
654
+						'An item was retrieved from the database but it\'s not a WP_Post like it should be.',
655
+						'event_espresso'
656
+					)
657
+				);
658
+			}
659
+			$model_object_classname = 'EE_' . $model->get_this_model_name();
660
+			$post->{$model_object_classname} = \EE_Registry::instance()->load_class(
661
+				$model_object_classname,
662
+				$result,
663
+				false,
664
+				false
665
+			);
666
+		}
667
+		foreach ($result as $field_name => $field_value) {
668
+			$field_obj = $model->field_settings_for($field_name);
669
+			if ($this->isSubclassOfOne($field_obj, $this->getModelVersionInfo()->fieldsIgnored())) {
670
+				unset($result[ $field_name ]);
671
+			} elseif ($this->isSubclassOfOne(
672
+				$field_obj,
673
+				$this->getModelVersionInfo()->fieldsThatHaveRenderedFormat()
674
+			)
675
+			) {
676
+				$result[ $field_name ] = array(
677
+					'raw'      => $this->prepareFieldObjValueForJson($field_obj, $field_value),
678
+					'rendered' => $this->prepareFieldObjValueForJson($field_obj, $field_value, 'pretty'),
679
+				);
680
+			} elseif ($this->isSubclassOfOne(
681
+				$field_obj,
682
+				$this->getModelVersionInfo()->fieldsThatHavePrettyFormat()
683
+			)
684
+			) {
685
+				$result[ $field_name ] = array(
686
+					'raw'    => $this->prepareFieldObjValueForJson($field_obj, $field_value),
687
+					'pretty' => $this->prepareFieldObjValueForJson($field_obj, $field_value, 'pretty'),
688
+				);
689
+			} elseif ($field_obj instanceof \EE_Datetime_Field) {
690
+				$field_value = $field_obj->prepare_for_set_from_db($field_value);
691
+				$timezone = $field_value->getTimezone();
692
+				EEH_DTT_Helper::setTimezone($field_value, new DateTimeZone('UTC'));
693
+				$result[ $field_name . '_gmt' ] = ModelDataTranslator::prepareFieldValuesForJson(
694
+					$field_obj,
695
+					$field_value,
696
+					$this->getModelVersionInfo()->requestedVersion()
697
+				);
698
+				EEH_DTT_Helper::setTimezone($field_value, $timezone);
699
+				$result[ $field_name ] = ModelDataTranslator::prepareFieldValuesForJson(
700
+					$field_obj,
701
+					$field_value,
702
+					$this->getModelVersionInfo()->requestedVersion()
703
+				);
704
+			} else {
705
+				$result[ $field_name ] = $this->prepareFieldObjValueForJson($field_obj, $field_value);
706
+			}
707
+		}
708
+		if ($do_chevy_shuffle) {
709
+			$post = $old_post;
710
+		}
711
+		return $result;
712
+	}
713
+
714
+
715
+	/**
716
+	 * Takes a value all the way from the DB representation, to the model object's representation, to the
717
+	 * user-facing PHP representation, to the REST API representation. (Assumes you've already taken from the DB
718
+	 * representation using $field_obj->prepare_for_set_from_db())
719
+	 *
720
+	 * @param EE_Model_Field_Base $field_obj
721
+	 * @param mixed               $value  as it's stored on a model object
722
+	 * @param string              $format valid values are 'normal' (default), 'pretty', 'datetime_obj'
723
+	 * @return mixed
724
+	 * @throws ObjectDetectedException if $value contains a PHP object
725
+	 */
726
+	protected function prepareFieldObjValueForJson(EE_Model_Field_Base $field_obj, $value, $format = 'normal')
727
+	{
728
+		$value = $field_obj->prepare_for_set_from_db($value);
729
+		switch ($format) {
730
+			case 'pretty':
731
+				$value = $field_obj->prepare_for_pretty_echoing($value);
732
+				break;
733
+			case 'normal':
734
+			default:
735
+				$value = $field_obj->prepare_for_get($value);
736
+				break;
737
+		}
738
+		return ModelDataTranslator::prepareFieldValuesForJson(
739
+			$field_obj,
740
+			$value,
741
+			$this->getModelVersionInfo()->requestedVersion()
742
+		);
743
+	}
744
+
745
+
746
+	/**
747
+	 * Adds a few extra fields to the entity response
748
+	 *
749
+	 * @param EEM_Base $model
750
+	 * @param array    $db_row
751
+	 * @param array    $entity_array
752
+	 * @return array modified entity
753
+	 */
754
+	protected function addExtraFields(EEM_Base $model, $db_row, $entity_array)
755
+	{
756
+		if ($model instanceof EEM_CPT_Base) {
757
+			$entity_array['link'] = get_permalink($db_row[ $model->get_primary_key_field()->get_qualified_column() ]);
758
+		}
759
+		return $entity_array;
760
+	}
761
+
762
+
763
+	/**
764
+	 * Gets links we want to add to the response
765
+	 *
766
+	 * @global \WP_REST_Server $wp_rest_server
767
+	 * @param EEM_Base         $model
768
+	 * @param array            $db_row
769
+	 * @param array            $entity_array
770
+	 * @return array the _links item in the entity
771
+	 */
772
+	protected function getEntityLinks($model, $db_row, $entity_array)
773
+	{
774
+		// add basic links
775
+		$links = array();
776
+		if ($model->has_primary_key_field()) {
777
+			$links['self'] = array(
778
+				array(
779
+					'href' => $this->getVersionedLinkTo(
780
+						EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
781
+						. '/'
782
+						. $entity_array[ $model->primary_key_name() ]
783
+					),
784
+				),
785
+			);
786
+		}
787
+		$links['collection'] = array(
788
+			array(
789
+				'href' => $this->getVersionedLinkTo(
790
+					EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
791
+				),
792
+			),
793
+		);
794
+		// add links to related models
795
+		if ($model->has_primary_key_field()) {
796
+			foreach ($this->getModelVersionInfo()->relationSettings($model) as $relation_name => $relation_obj) {
797
+				$related_model_part = Read::getRelatedEntityName($relation_name, $relation_obj);
798
+				$links[ EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part ] = array(
799
+					array(
800
+						'href'   => $this->getVersionedLinkTo(
801
+							EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
802
+							. '/'
803
+							. $entity_array[ $model->primary_key_name() ]
804
+							. '/'
805
+							. $related_model_part
806
+						),
807
+						'single' => $relation_obj instanceof EE_Belongs_To_Relation ? true : false,
808
+					),
809
+				);
810
+			}
811
+		}
812
+		return $links;
813
+	}
814
+
815
+
816
+	/**
817
+	 * Adds the included models indicated in the request to the entity provided
818
+	 *
819
+	 * @param EEM_Base        $model
820
+	 * @param WP_REST_Request $rest_request
821
+	 * @param array           $entity_array
822
+	 * @param array           $db_row
823
+	 * @return array the modified entity
824
+	 */
825
+	protected function includeRequestedModels(
826
+		EEM_Base $model,
827
+		WP_REST_Request $rest_request,
828
+		$entity_array,
829
+		$db_row = array()
830
+	) {
831
+		// if $db_row not included, hope the entity array has what we need
832
+		if (! $db_row) {
833
+			$db_row = $entity_array;
834
+		}
835
+		$includes_for_this_model = $this->explodeAndGetItemsPrefixedWith($rest_request->get_param('include'), '');
836
+		$includes_for_this_model = $this->removeModelNamesFromArray($includes_for_this_model);
837
+		// if they passed in * or didn't specify any includes, return everything
838
+		if (! in_array('*', $includes_for_this_model)
839
+			&& ! empty($includes_for_this_model)
840
+		) {
841
+			if ($model->has_primary_key_field()) {
842
+				// always include the primary key. ya just gotta know that at least
843
+				$includes_for_this_model[] = $model->primary_key_name();
844
+			}
845
+			if ($this->explodeAndGetItemsPrefixedWith($rest_request->get_param('calculate'), '')) {
846
+				$includes_for_this_model[] = '_calculated_fields';
847
+			}
848
+			$entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model));
849
+		}
850
+		$relation_settings = $this->getModelVersionInfo()->relationSettings($model);
851
+		foreach ($relation_settings as $relation_name => $relation_obj) {
852
+			$related_fields_to_include = $this->explodeAndGetItemsPrefixedWith(
853
+				$rest_request->get_param('include'),
854
+				$relation_name
855
+			);
856
+			$related_fields_to_calculate = $this->explodeAndGetItemsPrefixedWith(
857
+				$rest_request->get_param('calculate'),
858
+				$relation_name
859
+			);
860
+			// did they specify they wanted to include a related model, or
861
+			// specific fields from a related model?
862
+			// or did they specify to calculate a field from a related model?
863
+			if ($related_fields_to_include || $related_fields_to_calculate) {
864
+				// if so, we should include at least some part of the related model
865
+				$pretend_related_request = new WP_REST_Request();
866
+				$pretend_related_request->set_query_params(
867
+					array(
868
+						'caps'      => $rest_request->get_param('caps'),
869
+						'include'   => $related_fields_to_include,
870
+						'calculate' => $related_fields_to_calculate,
871
+					)
872
+				);
873
+				$pretend_related_request->add_header('no_rest_headers', true);
874
+				$primary_model_query_params = $model->alter_query_params_to_restrict_by_ID(
875
+					$model->get_index_primary_key_string(
876
+						$model->deduce_fields_n_values_from_cols_n_values($db_row)
877
+					)
878
+				);
879
+				$related_results = $this->getEntitiesFromRelationUsingModelQueryParams(
880
+					$primary_model_query_params,
881
+					$relation_obj,
882
+					$pretend_related_request
883
+				);
884
+				$entity_array[ Read::getRelatedEntityName($relation_name, $relation_obj) ] = $related_results
885
+																							 instanceof
886
+																							 WP_Error
887
+					? null
888
+					: $related_results;
889
+			}
890
+		}
891
+		return $entity_array;
892
+	}
893
+
894
+
895
+	/**
896
+	 * Returns a new array with all the names of models removed. Eg
897
+	 * array( 'Event', 'Datetime.*', 'foobar' ) would become array( 'Datetime.*', 'foobar' )
898
+	 *
899
+	 * @param array $arr
900
+	 * @return array
901
+	 */
902
+	private function removeModelNamesFromArray($arr)
903
+	{
904
+		return array_diff($arr, array_keys(EE_Registry::instance()->non_abstract_db_models));
905
+	}
906
+
907
+
908
+	/**
909
+	 * Gets the calculated fields for the response
910
+	 *
911
+	 * @param EEM_Base        $model
912
+	 * @param array           $wpdb_row
913
+	 * @param WP_REST_Request $rest_request
914
+	 * @return \stdClass the _calculations item in the entity
915
+	 * @throws ObjectDetectedException if a default value has a PHP object, which should never do (and if we
916
+	 * did, let's know about it ASAP, so let the exception bubble up)
917
+	 */
918
+	protected function getEntityCalculations($model, $wpdb_row, $rest_request)
919
+	{
920
+		$calculated_fields = $this->explodeAndGetItemsPrefixedWith(
921
+			$rest_request->get_param('calculate'),
922
+			''
923
+		);
924
+		// note: setting calculate=* doesn't do anything
925
+		$calculated_fields_to_return = new \stdClass();
926
+		foreach ($calculated_fields as $field_to_calculate) {
927
+			try {
928
+				$calculated_fields_to_return->$field_to_calculate = ModelDataTranslator::prepareFieldValueForJson(
929
+					null,
930
+					$this->fields_calculator->retrieveCalculatedFieldValue(
931
+						$model,
932
+						$field_to_calculate,
933
+						$wpdb_row,
934
+						$rest_request,
935
+						$this
936
+					),
937
+					$this->getModelVersionInfo()->requestedVersion()
938
+				);
939
+			} catch (RestException $e) {
940
+				// if we don't have permission to read it, just leave it out. but let devs know about the problem
941
+				$this->setResponseHeader(
942
+					'Notices-Field-Calculation-Errors['
943
+					. $e->getStringCode()
944
+					. ']['
945
+					. $model->get_this_model_name()
946
+					. ']['
947
+					. $field_to_calculate
948
+					. ']',
949
+					$e->getMessage(),
950
+					true
951
+				);
952
+			}
953
+		}
954
+		return $calculated_fields_to_return;
955
+	}
956
+
957
+
958
+	/**
959
+	 * Gets the full URL to the resource, taking the requested version into account
960
+	 *
961
+	 * @param string $link_part_after_version_and_slash eg "events/10/datetimes"
962
+	 * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes"
963
+	 */
964
+	public function getVersionedLinkTo($link_part_after_version_and_slash)
965
+	{
966
+		return rest_url(
967
+			EED_Core_Rest_Api::get_versioned_route_to(
968
+				$link_part_after_version_and_slash,
969
+				$this->getModelVersionInfo()->requestedVersion()
970
+			)
971
+		);
972
+	}
973
+
974
+
975
+	/**
976
+	 * Gets the correct lowercase name for the relation in the API according
977
+	 * to the relation's type
978
+	 *
979
+	 * @param string                  $relation_name
980
+	 * @param \EE_Model_Relation_Base $relation_obj
981
+	 * @return string
982
+	 */
983
+	public static function getRelatedEntityName($relation_name, $relation_obj)
984
+	{
985
+		if ($relation_obj instanceof EE_Belongs_To_Relation) {
986
+			return strtolower($relation_name);
987
+		} else {
988
+			return EEH_Inflector::pluralize_and_lower($relation_name);
989
+		}
990
+	}
991
+
992
+
993
+	/**
994
+	 * Gets the one model object with the specified id for the specified model
995
+	 *
996
+	 * @param EEM_Base        $model
997
+	 * @param WP_REST_Request $request
998
+	 * @return array|WP_Error
999
+	 */
1000
+	public function getEntityFromModel($model, $request)
1001
+	{
1002
+		$context = $this->validateContext($request->get_param('caps'));
1003
+		return $this->getOneOrReportPermissionError($model, $request, $context);
1004
+	}
1005
+
1006
+
1007
+	/**
1008
+	 * If a context is provided which isn't valid, maybe it was added in a future
1009
+	 * version so just treat it as a default read
1010
+	 *
1011
+	 * @param string $context
1012
+	 * @return string array key of EEM_Base::cap_contexts_to_cap_action_map()
1013
+	 */
1014
+	public function validateContext($context)
1015
+	{
1016
+		if (! $context) {
1017
+			$context = EEM_Base::caps_read;
1018
+		}
1019
+		$valid_contexts = EEM_Base::valid_cap_contexts();
1020
+		if (in_array($context, $valid_contexts)) {
1021
+			return $context;
1022
+		} else {
1023
+			return EEM_Base::caps_read;
1024
+		}
1025
+	}
1026
+
1027
+
1028
+	/**
1029
+	 * Verifies the passed in value is an allowable default where conditions value.
1030
+	 *
1031
+	 * @param $default_query_params
1032
+	 * @return string
1033
+	 */
1034
+	public function validateDefaultQueryParams($default_query_params)
1035
+	{
1036
+		$valid_default_where_conditions_for_api_calls = array(
1037
+			EEM_Base::default_where_conditions_all,
1038
+			EEM_Base::default_where_conditions_minimum_all,
1039
+			EEM_Base::default_where_conditions_minimum_others,
1040
+		);
1041
+		if (! $default_query_params) {
1042
+			$default_query_params = EEM_Base::default_where_conditions_all;
1043
+		}
1044
+		if (in_array(
1045
+			$default_query_params,
1046
+			$valid_default_where_conditions_for_api_calls,
1047
+			true
1048
+		)) {
1049
+			return $default_query_params;
1050
+		} else {
1051
+			return EEM_Base::default_where_conditions_all;
1052
+		}
1053
+	}
1054
+
1055
+
1056
+	/**
1057
+	 * Translates API filter get parameter into $query_params array used by EEM_Base::get_all().
1058
+	 * Note: right now the query parameter keys for fields (and related fields)
1059
+	 * can be left as-is, but it's quite possible this will change someday.
1060
+	 * Also, this method's contents might be candidate for moving to Model_Data_Translator
1061
+	 *
1062
+	 * @param EEM_Base $model
1063
+	 * @param array    $query_parameters  from $_GET parameter @see Read:handle_request_get_all
1064
+	 * @return array like what EEM_Base::get_all() expects or FALSE to indicate
1065
+	 *                                    that absolutely no results should be returned
1066
+	 * @throws EE_Error
1067
+	 * @throws RestException
1068
+	 */
1069
+	public function createModelQueryParams($model, $query_parameters)
1070
+	{
1071
+		$model_query_params = array();
1072
+		if (isset($query_parameters['where'])) {
1073
+			$model_query_params[0] = ModelDataTranslator::prepareConditionsQueryParamsForModels(
1074
+				$query_parameters['where'],
1075
+				$model,
1076
+				$this->getModelVersionInfo()->requestedVersion()
1077
+			);
1078
+		}
1079
+		if (isset($query_parameters['order_by'])) {
1080
+			$order_by = $query_parameters['order_by'];
1081
+		} elseif (isset($query_parameters['orderby'])) {
1082
+			$order_by = $query_parameters['orderby'];
1083
+		} else {
1084
+			$order_by = null;
1085
+		}
1086
+		if ($order_by !== null) {
1087
+			if (is_array($order_by)) {
1088
+				$order_by = ModelDataTranslator::prepareFieldNamesInArrayKeysFromJson($order_by);
1089
+			} else {
1090
+				// it's a single item
1091
+				$order_by = ModelDataTranslator::prepareFieldNameFromJson($order_by);
1092
+			}
1093
+			$model_query_params['order_by'] = $order_by;
1094
+		}
1095
+		if (isset($query_parameters['group_by'])) {
1096
+			$group_by = $query_parameters['group_by'];
1097
+		} elseif (isset($query_parameters['groupby'])) {
1098
+			$group_by = $query_parameters['groupby'];
1099
+		} else {
1100
+			$group_by = array_keys($model->get_combined_primary_key_fields());
1101
+		}
1102
+		// make sure they're all real names
1103
+		if (is_array($group_by)) {
1104
+			$group_by = ModelDataTranslator::prepareFieldNamesFromJson($group_by);
1105
+		}
1106
+		if ($group_by !== null) {
1107
+			$model_query_params['group_by'] = $group_by;
1108
+		}
1109
+		if (isset($query_parameters['having'])) {
1110
+			$model_query_params['having'] = ModelDataTranslator::prepareConditionsQueryParamsForModels(
1111
+				$query_parameters['having'],
1112
+				$model,
1113
+				$this->getModelVersionInfo()->requestedVersion()
1114
+			);
1115
+		}
1116
+		if (isset($query_parameters['order'])) {
1117
+			$model_query_params['order'] = $query_parameters['order'];
1118
+		}
1119
+		if (isset($query_parameters['mine'])) {
1120
+			$model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params);
1121
+		}
1122
+		if (isset($query_parameters['limit'])) {
1123
+			// limit should be either a string like '23' or '23,43', or an array with two items in it
1124
+			if (! is_array($query_parameters['limit'])) {
1125
+				$limit_array = explode(',', (string) $query_parameters['limit']);
1126
+			} else {
1127
+				$limit_array = $query_parameters['limit'];
1128
+			}
1129
+			$sanitized_limit = array();
1130
+			foreach ($limit_array as $key => $limit_part) {
1131
+				if ($this->debug_mode && (! is_numeric($limit_part) || count($sanitized_limit) > 2)) {
1132
+					throw new EE_Error(
1133
+						sprintf(
1134
+							__(
1135
+							// @codingStandardsIgnoreStart
1136
+								'An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.',
1137
+								// @codingStandardsIgnoreEnd
1138
+								'event_espresso'
1139
+							),
1140
+							wp_json_encode($query_parameters['limit'])
1141
+						)
1142
+					);
1143
+				}
1144
+				$sanitized_limit[] = (int) $limit_part;
1145
+			}
1146
+			$model_query_params['limit'] = implode(',', $sanitized_limit);
1147
+		} else {
1148
+			$model_query_params['limit'] = EED_Core_Rest_Api::get_default_query_limit();
1149
+		}
1150
+		if (isset($query_parameters['caps'])) {
1151
+			$model_query_params['caps'] = $this->validateContext($query_parameters['caps']);
1152
+		} else {
1153
+			$model_query_params['caps'] = EEM_Base::caps_read;
1154
+		}
1155
+		if (isset($query_parameters['default_where_conditions'])) {
1156
+			$model_query_params['default_where_conditions'] = $this->validateDefaultQueryParams(
1157
+				$query_parameters['default_where_conditions']
1158
+			);
1159
+		}
1160
+		return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model);
1161
+	}
1162
+
1163
+
1164
+	/**
1165
+	 * Changes the REST-style query params for use in the models
1166
+	 *
1167
+	 * @deprecated
1168
+	 * @param EEM_Base $model
1169
+	 * @param array    $query_params sub-array from @see EEM_Base::get_all()
1170
+	 * @return array
1171
+	 */
1172
+	public function prepareRestQueryParamsKeyForModels($model, $query_params)
1173
+	{
1174
+		$model_ready_query_params = array();
1175
+		foreach ($query_params as $key => $value) {
1176
+			if (is_array($value)) {
1177
+				$model_ready_query_params[ $key ] = $this->prepareRestQueryParamsKeyForModels($model, $value);
1178
+			} else {
1179
+				$model_ready_query_params[ $key ] = $value;
1180
+			}
1181
+		}
1182
+		return $model_ready_query_params;
1183
+	}
1184
+
1185
+
1186
+	/**
1187
+	 * @deprecated instead use ModelDataTranslator::prepareFieldValuesFromJson()
1188
+	 * @param $model
1189
+	 * @param $query_params
1190
+	 * @return array
1191
+	 */
1192
+	public function prepareRestQueryParamsValuesForModels($model, $query_params)
1193
+	{
1194
+		$model_ready_query_params = array();
1195
+		foreach ($query_params as $key => $value) {
1196
+			if (is_array($value)) {
1197
+				$model_ready_query_params[ $key ] = $this->prepareRestQueryParamsValuesForModels($model, $value);
1198
+			} else {
1199
+				$model_ready_query_params[ $key ] = $value;
1200
+			}
1201
+		}
1202
+		return $model_ready_query_params;
1203
+	}
1204
+
1205
+
1206
+	/**
1207
+	 * Explodes the string on commas, and only returns items with $prefix followed by a period.
1208
+	 * If no prefix is specified, returns items with no period.
1209
+	 *
1210
+	 * @param string|array $string_to_explode eg "jibba,jabba, blah, blah, blah" or array('jibba', 'jabba' )
1211
+	 * @param string       $prefix            "Event" or "foobar"
1212
+	 * @return array $string_to_exploded exploded on COMMAS, and if a prefix was specified
1213
+	 *                                        we only return strings starting with that and a period; if no prefix was
1214
+	 *                                        specified we return all items containing NO periods
1215
+	 */
1216
+	public function explodeAndGetItemsPrefixedWith($string_to_explode, $prefix)
1217
+	{
1218
+		if (is_string($string_to_explode)) {
1219
+			$exploded_contents = explode(',', $string_to_explode);
1220
+		} elseif (is_array($string_to_explode)) {
1221
+			$exploded_contents = $string_to_explode;
1222
+		} else {
1223
+			$exploded_contents = array();
1224
+		}
1225
+		// if the string was empty, we want an empty array
1226
+		$exploded_contents = array_filter($exploded_contents);
1227
+		$contents_with_prefix = array();
1228
+		foreach ($exploded_contents as $item) {
1229
+			$item = trim($item);
1230
+			// if no prefix was provided, so we look for items with no "." in them
1231
+			if (! $prefix) {
1232
+				// does this item have a period?
1233
+				if (strpos($item, '.') === false) {
1234
+					// if not, then its what we're looking for
1235
+					$contents_with_prefix[] = $item;
1236
+				}
1237
+			} elseif (strpos($item, $prefix . '.') === 0) {
1238
+				// this item has the prefix and a period, grab it
1239
+				$contents_with_prefix[] = substr(
1240
+					$item,
1241
+					strpos($item, $prefix . '.') + strlen($prefix . '.')
1242
+				);
1243
+			} elseif ($item === $prefix) {
1244
+				// this item is JUST the prefix
1245
+				// so let's grab everything after, which is a blank string
1246
+				$contents_with_prefix[] = '';
1247
+			}
1248
+		}
1249
+		return $contents_with_prefix;
1250
+	}
1251
+
1252
+
1253
+	/**
1254
+	 * @deprecated since 4.8.36.rc.001 You should instead use Read::explode_and_get_items_prefixed_with.
1255
+	 * Deprecated because its return values were really quite confusing- sometimes it returned
1256
+	 * an empty array (when the include string was blank or '*') or sometimes it returned
1257
+	 * array('*') (when you provided a model and a model of that kind was found).
1258
+	 * Parses the $include_string so we fetch all the field names relating to THIS model
1259
+	 * (ie have NO period in them), or for the provided model (ie start with the model
1260
+	 * name and then a period).
1261
+	 * @param string $include_string @see Read:handle_request_get_all
1262
+	 * @param string $model_name
1263
+	 * @return array of fields for this model. If $model_name is provided, then
1264
+	 *                               the fields for that model, with the model's name removed from each.
1265
+	 *                               If $include_string was blank or '*' returns an empty array
1266
+	 */
1267
+	public function extractIncludesForThisModel($include_string, $model_name = null)
1268
+	{
1269
+		if (is_array($include_string)) {
1270
+			$include_string = implode(',', $include_string);
1271
+		}
1272
+		if ($include_string === '*' || $include_string === '') {
1273
+			return array();
1274
+		}
1275
+		$includes = explode(',', $include_string);
1276
+		$extracted_fields_to_include = array();
1277
+		if ($model_name) {
1278
+			foreach ($includes as $field_to_include) {
1279
+				$field_to_include = trim($field_to_include);
1280
+				if (strpos($field_to_include, $model_name . '.') === 0) {
1281
+					// found the model name at the exact start
1282
+					$field_sans_model_name = str_replace($model_name . '.', '', $field_to_include);
1283
+					$extracted_fields_to_include[] = $field_sans_model_name;
1284
+				} elseif ($field_to_include == $model_name) {
1285
+					$extracted_fields_to_include[] = '*';
1286
+				}
1287
+			}
1288
+		} else {
1289
+			// look for ones with no period
1290
+			foreach ($includes as $field_to_include) {
1291
+				$field_to_include = trim($field_to_include);
1292
+				if (strpos($field_to_include, '.') === false
1293
+					&& ! $this->getModelVersionInfo()->isModelNameInThisVersion($field_to_include)
1294
+				) {
1295
+					$extracted_fields_to_include[] = $field_to_include;
1296
+				}
1297
+			}
1298
+		}
1299
+		return $extracted_fields_to_include;
1300
+	}
1301
+
1302
+
1303
+	/**
1304
+	 * Gets the single item using the model according to the request in the context given, otherwise
1305
+	 * returns that it's inaccessible to the current user
1306
+	 *
1307
+	 * @param EEM_Base        $model
1308
+	 * @param WP_REST_Request $request
1309
+	 * @param null            $context
1310
+	 * @return array|WP_Error
1311
+	 */
1312
+	public function getOneOrReportPermissionError(EEM_Base $model, WP_REST_Request $request, $context = null)
1313
+	{
1314
+		$query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1);
1315
+		if ($model instanceof \EEM_Soft_Delete_Base) {
1316
+			$query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params);
1317
+		}
1318
+		$restricted_query_params = $query_params;
1319
+		$restricted_query_params['caps'] = $context;
1320
+		$this->setDebugInfo('model query params', $restricted_query_params);
1321
+		$model_rows = $model->get_all_wpdb_results($restricted_query_params);
1322
+		if (! empty($model_rows)) {
1323
+			return $this->createEntityFromWpdbResult(
1324
+				$model,
1325
+				array_shift($model_rows),
1326
+				$request
1327
+			);
1328
+		} else {
1329
+			// ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities
1330
+			$lowercase_model_name = strtolower($model->get_this_model_name());
1331
+			$model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params);
1332
+			if (! empty($model_rows_found_sans_restrictions)) {
1333
+				// you got shafted- it existed but we didn't want to tell you!
1334
+				return new WP_Error(
1335
+					'rest_user_cannot_' . $context,
1336
+					sprintf(
1337
+						__('Sorry, you cannot %1$s this %2$s. Missing permissions are: %3$s', 'event_espresso'),
1338
+						$context,
1339
+						strtolower($model->get_this_model_name()),
1340
+						Capabilities::getMissingPermissionsString(
1341
+							$model,
1342
+							$context
1343
+						)
1344
+					),
1345
+					array('status' => 403)
1346
+				);
1347
+			} else {
1348
+				// it's not you. It just doesn't exist
1349
+				return new WP_Error(
1350
+					sprintf('rest_%s_invalid_id', $lowercase_model_name),
1351
+					sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name),
1352
+					array('status' => 404)
1353
+				);
1354
+			}
1355
+		}
1356
+	}
1357 1357
 }
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
         $controller = new Read();
65 65
         try {
66 66
             $controller->setRequestedVersion($version);
67
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
67
+            if ( ! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
68 68
                 return $controller->sendResponse(
69 69
                     new WP_Error(
70 70
                         'endpoint_parsing_error',
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
         $controller = new Read();
103 103
         try {
104 104
             $controller->setRequestedVersion($version);
105
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
105
+            if ( ! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
106 106
                 return array();
107 107
             }
108 108
             // get the model for this version
@@ -159,11 +159,11 @@  discard block
 block discarded – undo
159 159
      */
160 160
     protected function translateDefaultsForRestResponse($field_name, EE_Model_Field_Base $field, array $schema)
161 161
     {
162
-        if (isset($schema['properties'][ $field_name ]['default'])) {
163
-            if (is_array($schema['properties'][ $field_name ]['default'])) {
164
-                foreach ($schema['properties'][ $field_name ]['default'] as $default_key => $default_value) {
162
+        if (isset($schema['properties'][$field_name]['default'])) {
163
+            if (is_array($schema['properties'][$field_name]['default'])) {
164
+                foreach ($schema['properties'][$field_name]['default'] as $default_key => $default_value) {
165 165
                     if ($default_key === 'raw') {
166
-                        $schema['properties'][ $field_name ]['default'][ $default_key ] =
166
+                        $schema['properties'][$field_name]['default'][$default_key] =
167 167
                             ModelDataTranslator::prepareFieldValueForJson(
168 168
                                 $field,
169 169
                                 $default_value,
@@ -172,9 +172,9 @@  discard block
 block discarded – undo
172 172
                     }
173 173
                 }
174 174
             } else {
175
-                $schema['properties'][ $field_name ]['default'] = ModelDataTranslator::prepareFieldValueForJson(
175
+                $schema['properties'][$field_name]['default'] = ModelDataTranslator::prepareFieldValueForJson(
176 176
                     $field,
177
-                    $schema['properties'][ $field_name ]['default'],
177
+                    $schema['properties'][$field_name]['default'],
178 178
                     $this->getModelVersionInfo()->requestedVersion()
179 179
                 );
180 180
             }
@@ -196,9 +196,9 @@  discard block
 block discarded – undo
196 196
     protected function maybeAddExtraFieldsToSchema($field_name, EE_Model_Field_Base $field, array $schema)
197 197
     {
198 198
         if ($field instanceof EE_Datetime_Field) {
199
-            $schema['properties'][ $field_name . '_gmt' ] = $field->getSchema();
199
+            $schema['properties'][$field_name.'_gmt'] = $field->getSchema();
200 200
             // modify the description
201
-            $schema['properties'][ $field_name . '_gmt' ]['description'] = sprintf(
201
+            $schema['properties'][$field_name.'_gmt']['description'] = sprintf(
202 202
                 esc_html__('%s - the value for this field is in GMT.', 'event_espresso'),
203 203
                 wp_specialchars_decode($field->get_nicename(), ENT_QUOTES)
204 204
             );
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
         $controller = new Read();
239 239
         try {
240 240
             $controller->setRequestedVersion($version);
241
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
241
+            if ( ! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
242 242
                 return $controller->sendResponse(
243 243
                     new WP_Error(
244 244
                         'endpoint_parsing_error',
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
         $controller = new Read();
284 284
         try {
285 285
             $controller->setRequestedVersion($version);
286
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
286
+            if ( ! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
287 287
                 return $controller->sendResponse(
288 288
                     new WP_Error(
289 289
                         'endpoint_parsing_error',
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
                 );
299 299
             }
300 300
             $main_model = $controller->getModelVersionInfo()->loadModel($model_name);
301
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($related_model_name)) {
301
+            if ( ! $controller->getModelVersionInfo()->isModelNameInThisVersion($related_model_name)) {
302 302
                 return $controller->sendResponse(
303 303
                     new WP_Error(
304 304
                         'endpoint_parsing_error',
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
     public function getEntitiesFromModel($model, $request)
336 336
     {
337 337
         $query_params = $this->createModelQueryParams($model, $request->get_params());
338
-        if (! Capabilities::currentUserHasPartialAccessTo($model, $query_params['caps'])) {
338
+        if ( ! Capabilities::currentUserHasPartialAccessTo($model, $query_params['caps'])) {
339 339
             $model_name_plural = EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
340 340
             return new WP_Error(
341 341
                 sprintf('rest_%s_cannot_list', $model_name_plural),
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
                 array('status' => 403)
348 348
             );
349 349
         }
350
-        if (! $request->get_header('no_rest_headers')) {
350
+        if ( ! $request->get_header('no_rest_headers')) {
351 351
             $this->setHeadersFromQueryParams($model, $query_params);
352 352
         }
353 353
         /** @type array $results */
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
         $context = $this->validateContext($request->get_param('caps'));
383 383
         $model = $relation->get_this_model();
384 384
         $related_model = $relation->get_other_model();
385
-        if (! isset($primary_model_query_params[0])) {
385
+        if ( ! isset($primary_model_query_params[0])) {
386 386
             $primary_model_query_params[0] = array();
387 387
         }
388 388
         // check if they can access the 1st model object
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
         $restricted_query_params['caps'] = $context;
400 400
         $this->setDebugInfo('main model query params', $restricted_query_params);
401 401
         $this->setDebugInfo('missing caps', Capabilities::getMissingPermissionsString($related_model, $context));
402
-        if (! (
402
+        if ( ! (
403 403
             Capabilities::currentUserHasPartialAccessTo($related_model, $context)
404 404
             && $model->exists($restricted_query_params)
405 405
         )
@@ -432,13 +432,13 @@  discard block
 block discarded – undo
432 432
         }
433 433
         $query_params = $this->createModelQueryParams($relation->get_other_model(), $request->get_params());
434 434
         foreach ($primary_model_query_params[0] as $where_condition_key => $where_condition_value) {
435
-            $query_params[0][ $relation->get_this_model()->get_this_model_name()
435
+            $query_params[0][$relation->get_this_model()->get_this_model_name()
436 436
                               . '.'
437
-                              . $where_condition_key ] = $where_condition_value;
437
+                              . $where_condition_key] = $where_condition_value;
438 438
         }
439 439
         $query_params['default_where_conditions'] = 'none';
440 440
         $query_params['caps'] = $context;
441
-        if (! $request->get_header('no_rest_headers')) {
441
+        if ( ! $request->get_header('no_rest_headers')) {
442 442
             $this->setHeadersFromQueryParams($relation->get_other_model(), $query_params);
443 443
         }
444 444
         /** @type array $results */
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
      */
490 490
     public function getEntitiesFromRelation($id, $relation, $request)
491 491
     {
492
-        if (! $relation->get_this_model()->has_primary_key_field()) {
492
+        if ( ! $relation->get_this_model()->has_primary_key_field()) {
493 493
             throw new EE_Error(
494 494
                 sprintf(
495 495
                     __(
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
             Capabilities::getMissingPermissionsString($model, $query_params['caps'])
532 532
         );
533 533
         // normally the limit to a 2-part array, where the 2nd item is the limit
534
-        if (! isset($query_params['limit'])) {
534
+        if ( ! isset($query_params['limit'])) {
535 535
             $query_params['limit'] = EED_Core_Rest_Api::get_default_query_limit();
536 536
         }
537 537
         if (is_array($query_params['limit'])) {
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
      */
565 565
     public function createEntityFromWpdbResult($model, $db_row, $rest_request, $deprecated = null)
566 566
     {
567
-        if (! $rest_request instanceof WP_REST_Request) {
567
+        if ( ! $rest_request instanceof WP_REST_Request) {
568 568
             // ok so this was called in the old style, where the 3rd arg was
569 569
             // $include, and the 4th arg was $context
570 570
             // now setup the request just to avoid fatal errors, although we won't be able
@@ -645,8 +645,8 @@  discard block
 block discarded – undo
645 645
         if ($do_chevy_shuffle) {
646 646
             global $post;
647 647
             $old_post = $post;
648
-            $post = get_post($result[ $model->primary_key_name() ]);
649
-            if (! $post instanceof \WP_Post) {
648
+            $post = get_post($result[$model->primary_key_name()]);
649
+            if ( ! $post instanceof \WP_Post) {
650 650
                 // well that's weird, because $result is what we JUST fetched from the database
651 651
                 throw new RestException(
652 652
                     'error_fetching_post_from_database_results',
@@ -656,7 +656,7 @@  discard block
 block discarded – undo
656 656
                     )
657 657
                 );
658 658
             }
659
-            $model_object_classname = 'EE_' . $model->get_this_model_name();
659
+            $model_object_classname = 'EE_'.$model->get_this_model_name();
660 660
             $post->{$model_object_classname} = \EE_Registry::instance()->load_class(
661 661
                 $model_object_classname,
662 662
                 $result,
@@ -667,13 +667,13 @@  discard block
 block discarded – undo
667 667
         foreach ($result as $field_name => $field_value) {
668 668
             $field_obj = $model->field_settings_for($field_name);
669 669
             if ($this->isSubclassOfOne($field_obj, $this->getModelVersionInfo()->fieldsIgnored())) {
670
-                unset($result[ $field_name ]);
670
+                unset($result[$field_name]);
671 671
             } elseif ($this->isSubclassOfOne(
672 672
                 $field_obj,
673 673
                 $this->getModelVersionInfo()->fieldsThatHaveRenderedFormat()
674 674
             )
675 675
             ) {
676
-                $result[ $field_name ] = array(
676
+                $result[$field_name] = array(
677 677
                     'raw'      => $this->prepareFieldObjValueForJson($field_obj, $field_value),
678 678
                     'rendered' => $this->prepareFieldObjValueForJson($field_obj, $field_value, 'pretty'),
679 679
                 );
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
                 $this->getModelVersionInfo()->fieldsThatHavePrettyFormat()
683 683
             )
684 684
             ) {
685
-                $result[ $field_name ] = array(
685
+                $result[$field_name] = array(
686 686
                     'raw'    => $this->prepareFieldObjValueForJson($field_obj, $field_value),
687 687
                     'pretty' => $this->prepareFieldObjValueForJson($field_obj, $field_value, 'pretty'),
688 688
                 );
@@ -690,19 +690,19 @@  discard block
 block discarded – undo
690 690
                 $field_value = $field_obj->prepare_for_set_from_db($field_value);
691 691
                 $timezone = $field_value->getTimezone();
692 692
                 EEH_DTT_Helper::setTimezone($field_value, new DateTimeZone('UTC'));
693
-                $result[ $field_name . '_gmt' ] = ModelDataTranslator::prepareFieldValuesForJson(
693
+                $result[$field_name.'_gmt'] = ModelDataTranslator::prepareFieldValuesForJson(
694 694
                     $field_obj,
695 695
                     $field_value,
696 696
                     $this->getModelVersionInfo()->requestedVersion()
697 697
                 );
698 698
                 EEH_DTT_Helper::setTimezone($field_value, $timezone);
699
-                $result[ $field_name ] = ModelDataTranslator::prepareFieldValuesForJson(
699
+                $result[$field_name] = ModelDataTranslator::prepareFieldValuesForJson(
700 700
                     $field_obj,
701 701
                     $field_value,
702 702
                     $this->getModelVersionInfo()->requestedVersion()
703 703
                 );
704 704
             } else {
705
-                $result[ $field_name ] = $this->prepareFieldObjValueForJson($field_obj, $field_value);
705
+                $result[$field_name] = $this->prepareFieldObjValueForJson($field_obj, $field_value);
706 706
             }
707 707
         }
708 708
         if ($do_chevy_shuffle) {
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
     protected function addExtraFields(EEM_Base $model, $db_row, $entity_array)
755 755
     {
756 756
         if ($model instanceof EEM_CPT_Base) {
757
-            $entity_array['link'] = get_permalink($db_row[ $model->get_primary_key_field()->get_qualified_column() ]);
757
+            $entity_array['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]);
758 758
         }
759 759
         return $entity_array;
760 760
     }
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
                     'href' => $this->getVersionedLinkTo(
780 780
                         EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
781 781
                         . '/'
782
-                        . $entity_array[ $model->primary_key_name() ]
782
+                        . $entity_array[$model->primary_key_name()]
783 783
                     ),
784 784
                 ),
785 785
             );
@@ -795,12 +795,12 @@  discard block
 block discarded – undo
795 795
         if ($model->has_primary_key_field()) {
796 796
             foreach ($this->getModelVersionInfo()->relationSettings($model) as $relation_name => $relation_obj) {
797 797
                 $related_model_part = Read::getRelatedEntityName($relation_name, $relation_obj);
798
-                $links[ EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part ] = array(
798
+                $links[EED_Core_Rest_Api::ee_api_link_namespace.$related_model_part] = array(
799 799
                     array(
800 800
                         'href'   => $this->getVersionedLinkTo(
801 801
                             EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
802 802
                             . '/'
803
-                            . $entity_array[ $model->primary_key_name() ]
803
+                            . $entity_array[$model->primary_key_name()]
804 804
                             . '/'
805 805
                             . $related_model_part
806 806
                         ),
@@ -829,13 +829,13 @@  discard block
 block discarded – undo
829 829
         $db_row = array()
830 830
     ) {
831 831
         // if $db_row not included, hope the entity array has what we need
832
-        if (! $db_row) {
832
+        if ( ! $db_row) {
833 833
             $db_row = $entity_array;
834 834
         }
835 835
         $includes_for_this_model = $this->explodeAndGetItemsPrefixedWith($rest_request->get_param('include'), '');
836 836
         $includes_for_this_model = $this->removeModelNamesFromArray($includes_for_this_model);
837 837
         // if they passed in * or didn't specify any includes, return everything
838
-        if (! in_array('*', $includes_for_this_model)
838
+        if ( ! in_array('*', $includes_for_this_model)
839 839
             && ! empty($includes_for_this_model)
840 840
         ) {
841 841
             if ($model->has_primary_key_field()) {
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
                     $relation_obj,
882 882
                     $pretend_related_request
883 883
                 );
884
-                $entity_array[ Read::getRelatedEntityName($relation_name, $relation_obj) ] = $related_results
884
+                $entity_array[Read::getRelatedEntityName($relation_name, $relation_obj)] = $related_results
885 885
                                                                                              instanceof
886 886
                                                                                              WP_Error
887 887
                     ? null
@@ -1013,7 +1013,7 @@  discard block
 block discarded – undo
1013 1013
      */
1014 1014
     public function validateContext($context)
1015 1015
     {
1016
-        if (! $context) {
1016
+        if ( ! $context) {
1017 1017
             $context = EEM_Base::caps_read;
1018 1018
         }
1019 1019
         $valid_contexts = EEM_Base::valid_cap_contexts();
@@ -1038,7 +1038,7 @@  discard block
 block discarded – undo
1038 1038
             EEM_Base::default_where_conditions_minimum_all,
1039 1039
             EEM_Base::default_where_conditions_minimum_others,
1040 1040
         );
1041
-        if (! $default_query_params) {
1041
+        if ( ! $default_query_params) {
1042 1042
             $default_query_params = EEM_Base::default_where_conditions_all;
1043 1043
         }
1044 1044
         if (in_array(
@@ -1121,14 +1121,14 @@  discard block
 block discarded – undo
1121 1121
         }
1122 1122
         if (isset($query_parameters['limit'])) {
1123 1123
             // limit should be either a string like '23' or '23,43', or an array with two items in it
1124
-            if (! is_array($query_parameters['limit'])) {
1124
+            if ( ! is_array($query_parameters['limit'])) {
1125 1125
                 $limit_array = explode(',', (string) $query_parameters['limit']);
1126 1126
             } else {
1127 1127
                 $limit_array = $query_parameters['limit'];
1128 1128
             }
1129 1129
             $sanitized_limit = array();
1130 1130
             foreach ($limit_array as $key => $limit_part) {
1131
-                if ($this->debug_mode && (! is_numeric($limit_part) || count($sanitized_limit) > 2)) {
1131
+                if ($this->debug_mode && ( ! is_numeric($limit_part) || count($sanitized_limit) > 2)) {
1132 1132
                     throw new EE_Error(
1133 1133
                         sprintf(
1134 1134
                             __(
@@ -1174,9 +1174,9 @@  discard block
 block discarded – undo
1174 1174
         $model_ready_query_params = array();
1175 1175
         foreach ($query_params as $key => $value) {
1176 1176
             if (is_array($value)) {
1177
-                $model_ready_query_params[ $key ] = $this->prepareRestQueryParamsKeyForModels($model, $value);
1177
+                $model_ready_query_params[$key] = $this->prepareRestQueryParamsKeyForModels($model, $value);
1178 1178
             } else {
1179
-                $model_ready_query_params[ $key ] = $value;
1179
+                $model_ready_query_params[$key] = $value;
1180 1180
             }
1181 1181
         }
1182 1182
         return $model_ready_query_params;
@@ -1194,9 +1194,9 @@  discard block
 block discarded – undo
1194 1194
         $model_ready_query_params = array();
1195 1195
         foreach ($query_params as $key => $value) {
1196 1196
             if (is_array($value)) {
1197
-                $model_ready_query_params[ $key ] = $this->prepareRestQueryParamsValuesForModels($model, $value);
1197
+                $model_ready_query_params[$key] = $this->prepareRestQueryParamsValuesForModels($model, $value);
1198 1198
             } else {
1199
-                $model_ready_query_params[ $key ] = $value;
1199
+                $model_ready_query_params[$key] = $value;
1200 1200
             }
1201 1201
         }
1202 1202
         return $model_ready_query_params;
@@ -1228,17 +1228,17 @@  discard block
 block discarded – undo
1228 1228
         foreach ($exploded_contents as $item) {
1229 1229
             $item = trim($item);
1230 1230
             // if no prefix was provided, so we look for items with no "." in them
1231
-            if (! $prefix) {
1231
+            if ( ! $prefix) {
1232 1232
                 // does this item have a period?
1233 1233
                 if (strpos($item, '.') === false) {
1234 1234
                     // if not, then its what we're looking for
1235 1235
                     $contents_with_prefix[] = $item;
1236 1236
                 }
1237
-            } elseif (strpos($item, $prefix . '.') === 0) {
1237
+            } elseif (strpos($item, $prefix.'.') === 0) {
1238 1238
                 // this item has the prefix and a period, grab it
1239 1239
                 $contents_with_prefix[] = substr(
1240 1240
                     $item,
1241
-                    strpos($item, $prefix . '.') + strlen($prefix . '.')
1241
+                    strpos($item, $prefix.'.') + strlen($prefix.'.')
1242 1242
                 );
1243 1243
             } elseif ($item === $prefix) {
1244 1244
                 // this item is JUST the prefix
@@ -1277,9 +1277,9 @@  discard block
 block discarded – undo
1277 1277
         if ($model_name) {
1278 1278
             foreach ($includes as $field_to_include) {
1279 1279
                 $field_to_include = trim($field_to_include);
1280
-                if (strpos($field_to_include, $model_name . '.') === 0) {
1280
+                if (strpos($field_to_include, $model_name.'.') === 0) {
1281 1281
                     // found the model name at the exact start
1282
-                    $field_sans_model_name = str_replace($model_name . '.', '', $field_to_include);
1282
+                    $field_sans_model_name = str_replace($model_name.'.', '', $field_to_include);
1283 1283
                     $extracted_fields_to_include[] = $field_sans_model_name;
1284 1284
                 } elseif ($field_to_include == $model_name) {
1285 1285
                     $extracted_fields_to_include[] = '*';
@@ -1319,7 +1319,7 @@  discard block
 block discarded – undo
1319 1319
         $restricted_query_params['caps'] = $context;
1320 1320
         $this->setDebugInfo('model query params', $restricted_query_params);
1321 1321
         $model_rows = $model->get_all_wpdb_results($restricted_query_params);
1322
-        if (! empty($model_rows)) {
1322
+        if ( ! empty($model_rows)) {
1323 1323
             return $this->createEntityFromWpdbResult(
1324 1324
                 $model,
1325 1325
                 array_shift($model_rows),
@@ -1329,10 +1329,10 @@  discard block
 block discarded – undo
1329 1329
             // ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities
1330 1330
             $lowercase_model_name = strtolower($model->get_this_model_name());
1331 1331
             $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params);
1332
-            if (! empty($model_rows_found_sans_restrictions)) {
1332
+            if ( ! empty($model_rows_found_sans_restrictions)) {
1333 1333
                 // you got shafted- it existed but we didn't want to tell you!
1334 1334
                 return new WP_Error(
1335
-                    'rest_user_cannot_' . $context,
1335
+                    'rest_user_cannot_'.$context,
1336 1336
                     sprintf(
1337 1337
                         __('Sorry, you cannot %1$s this %2$s. Missing permissions are: %3$s', 'event_espresso'),
1338 1338
                         $context,
Please login to merge, or discard this patch.
modules/ticket_selector/ProcessTicketSelector.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -473,7 +473,7 @@
 block discarded – undo
473 473
      *
474 474
      * @param EE_Ticket $ticket
475 475
      * @param int       $qty
476
-     * @return TRUE on success, FALSE on fail
476
+     * @return boolean on success, FALSE on fail
477 477
      * @throws InvalidArgumentException
478 478
      * @throws InvalidInterfaceException
479 479
      * @throws InvalidDataTypeException
Please login to merge, or discard this patch.
Indentation   +497 added lines, -497 removed lines patch added patch discarded remove patch
@@ -33,526 +33,526 @@
 block discarded – undo
33 33
 class ProcessTicketSelector
34 34
 {
35 35
 
36
-    /**
37
-     * @var EE_Cart $cart
38
-     */
39
-    private $cart;
36
+	/**
37
+	 * @var EE_Cart $cart
38
+	 */
39
+	private $cart;
40 40
 
41
-    /**
42
-     * @var EE_Core_Config $core_config
43
-     */
44
-    private $core_config;
41
+	/**
42
+	 * @var EE_Core_Config $core_config
43
+	 */
44
+	private $core_config;
45 45
 
46
-    /**
47
-     * @var Request $request
48
-     */
49
-    private $request;
46
+	/**
47
+	 * @var Request $request
48
+	 */
49
+	private $request;
50 50
 
51
-    /**
52
-     * @var EE_Session $session
53
-     */
54
-    private $session;
51
+	/**
52
+	 * @var EE_Session $session
53
+	 */
54
+	private $session;
55 55
 
56
-    /**
57
-     * @var EEM_Ticket $ticket_model
58
-     */
59
-    private $ticket_model;
56
+	/**
57
+	 * @var EEM_Ticket $ticket_model
58
+	 */
59
+	private $ticket_model;
60 60
 
61
-    /**
62
-     * @var TicketDatetimeAvailabilityTracker $tracker
63
-     */
64
-    private $tracker;
61
+	/**
62
+	 * @var TicketDatetimeAvailabilityTracker $tracker
63
+	 */
64
+	private $tracker;
65 65
 
66 66
 
67
-    /**
68
-     * ProcessTicketSelector constructor.
69
-     * NOTE: PLZ use the Loader to instantiate this class if need be
70
-     * so that all dependencies get injected correctly (which will happen automatically)
71
-     * Null values for parameters are only for backwards compatibility but will be removed later on.
72
-     *
73
-     * @param EE_Core_Config                    $core_config
74
-     * @param Request                           $request
75
-     * @param EE_Session                        $session
76
-     * @param EEM_Ticket                        $ticket_model
77
-     * @param TicketDatetimeAvailabilityTracker $tracker
78
-     * @throws InvalidArgumentException
79
-     * @throws InvalidDataTypeException
80
-     * @throws InvalidInterfaceException
81
-     */
82
-    public function __construct(
83
-        EE_Core_Config $core_config = null,
84
-        Request $request = null,
85
-        EE_Session $session = null,
86
-        EEM_Ticket $ticket_model = null,
87
-        TicketDatetimeAvailabilityTracker $tracker = null
88
-    ) {
89
-        /** @var LoaderInterface $loader */
90
-        $loader = LoaderFactory::getLoader();
91
-        $this->core_config = $core_config instanceof EE_Core_Config
92
-            ? $core_config
93
-            : $loader->getShared('EE_Core_Config');
94
-        $this->request = $request instanceof Request
95
-            ? $request
96
-            : $loader->getShared('EventEspresso\core\services\request\Request');
97
-        $this->session = $session instanceof EE_Session
98
-            ? $session
99
-            : $loader->getShared('EE_Session');
100
-        $this->ticket_model = $ticket_model instanceof EEM_Ticket
101
-            ? $ticket_model
102
-            : $loader->getShared('EEM_Ticket');
103
-        $this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker
104
-            ? $tracker
105
-            : $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker');
106
-    }
67
+	/**
68
+	 * ProcessTicketSelector constructor.
69
+	 * NOTE: PLZ use the Loader to instantiate this class if need be
70
+	 * so that all dependencies get injected correctly (which will happen automatically)
71
+	 * Null values for parameters are only for backwards compatibility but will be removed later on.
72
+	 *
73
+	 * @param EE_Core_Config                    $core_config
74
+	 * @param Request                           $request
75
+	 * @param EE_Session                        $session
76
+	 * @param EEM_Ticket                        $ticket_model
77
+	 * @param TicketDatetimeAvailabilityTracker $tracker
78
+	 * @throws InvalidArgumentException
79
+	 * @throws InvalidDataTypeException
80
+	 * @throws InvalidInterfaceException
81
+	 */
82
+	public function __construct(
83
+		EE_Core_Config $core_config = null,
84
+		Request $request = null,
85
+		EE_Session $session = null,
86
+		EEM_Ticket $ticket_model = null,
87
+		TicketDatetimeAvailabilityTracker $tracker = null
88
+	) {
89
+		/** @var LoaderInterface $loader */
90
+		$loader = LoaderFactory::getLoader();
91
+		$this->core_config = $core_config instanceof EE_Core_Config
92
+			? $core_config
93
+			: $loader->getShared('EE_Core_Config');
94
+		$this->request = $request instanceof Request
95
+			? $request
96
+			: $loader->getShared('EventEspresso\core\services\request\Request');
97
+		$this->session = $session instanceof EE_Session
98
+			? $session
99
+			: $loader->getShared('EE_Session');
100
+		$this->ticket_model = $ticket_model instanceof EEM_Ticket
101
+			? $ticket_model
102
+			: $loader->getShared('EEM_Ticket');
103
+		$this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker
104
+			? $tracker
105
+			: $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker');
106
+	}
107 107
 
108 108
 
109
-    /**
110
-     * cancelTicketSelections
111
-     *
112
-     * @return bool
113
-     * @throws EE_Error
114
-     * @throws InvalidArgumentException
115
-     * @throws InvalidInterfaceException
116
-     * @throws InvalidDataTypeException
117
-     */
118
-    public function cancelTicketSelections()
119
-    {
120
-        // check nonce
121
-        if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
122
-            return false;
123
-        }
124
-        $this->session->clear_session(__CLASS__, __FUNCTION__);
125
-        if ($this->request->requestParamIsSet('event_id')) {
126
-            EEH_URL::safeRedirectAndExit(
127
-                EEH_Event_View::event_link_url(
128
-                    $this->request->getRequestParam('event_id')
129
-                )
130
-            );
131
-        }
132
-        EEH_URL::safeRedirectAndExit(
133
-            site_url('/' . $this->core_config->event_cpt_slug . '/')
134
-        );
135
-        return true;
136
-    }
109
+	/**
110
+	 * cancelTicketSelections
111
+	 *
112
+	 * @return bool
113
+	 * @throws EE_Error
114
+	 * @throws InvalidArgumentException
115
+	 * @throws InvalidInterfaceException
116
+	 * @throws InvalidDataTypeException
117
+	 */
118
+	public function cancelTicketSelections()
119
+	{
120
+		// check nonce
121
+		if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
122
+			return false;
123
+		}
124
+		$this->session->clear_session(__CLASS__, __FUNCTION__);
125
+		if ($this->request->requestParamIsSet('event_id')) {
126
+			EEH_URL::safeRedirectAndExit(
127
+				EEH_Event_View::event_link_url(
128
+					$this->request->getRequestParam('event_id')
129
+				)
130
+			);
131
+		}
132
+		EEH_URL::safeRedirectAndExit(
133
+			site_url('/' . $this->core_config->event_cpt_slug . '/')
134
+		);
135
+		return true;
136
+	}
137 137
 
138 138
 
139
-    /**
140
-     * processTicketSelectorNonce
141
-     *
142
-     * @param  string $nonce_name
143
-     * @param string  $id
144
-     * @return bool
145
-     */
146
-    private function processTicketSelectorNonce($nonce_name, $id = '')
147
-    {
148
-        $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
149
-        if (! $this->request->isAdmin()
150
-            && (
151
-                ! $this->request->is_set($nonce_name_with_id)
152
-                || ! wp_verify_nonce(
153
-                    $this->request->get($nonce_name_with_id),
154
-                    $nonce_name
155
-                )
156
-            )
157
-        ) {
158
-            EE_Error::add_error(
159
-                sprintf(
160
-                    esc_html__(
161
-                        'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.',
162
-                        'event_espresso'
163
-                    ),
164
-                    '<br/>'
165
-                ),
166
-                __FILE__,
167
-                __FUNCTION__,
168
-                __LINE__
169
-            );
170
-            return false;
171
-        }
172
-        return true;
173
-    }
139
+	/**
140
+	 * processTicketSelectorNonce
141
+	 *
142
+	 * @param  string $nonce_name
143
+	 * @param string  $id
144
+	 * @return bool
145
+	 */
146
+	private function processTicketSelectorNonce($nonce_name, $id = '')
147
+	{
148
+		$nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
149
+		if (! $this->request->isAdmin()
150
+			&& (
151
+				! $this->request->is_set($nonce_name_with_id)
152
+				|| ! wp_verify_nonce(
153
+					$this->request->get($nonce_name_with_id),
154
+					$nonce_name
155
+				)
156
+			)
157
+		) {
158
+			EE_Error::add_error(
159
+				sprintf(
160
+					esc_html__(
161
+						'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.',
162
+						'event_espresso'
163
+					),
164
+					'<br/>'
165
+				),
166
+				__FILE__,
167
+				__FUNCTION__,
168
+				__LINE__
169
+			);
170
+			return false;
171
+		}
172
+		return true;
173
+	}
174 174
 
175 175
 
176
-    /**
177
-     * process_ticket_selections
178
-     *
179
-     * @return array|bool
180
-     * @throws EE_Error
181
-     * @throws InvalidArgumentException
182
-     * @throws InvalidDataTypeException
183
-     * @throws InvalidInterfaceException
184
-     */
185
-    public function processTicketSelections()
186
-    {
187
-        do_action('EED_Ticket_Selector__process_ticket_selections__before');
188
-        if ($this->request->isBot()) {
189
-            EEH_URL::safeRedirectAndExit(
190
-                apply_filters(
191
-                    'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url',
192
-                    site_url()
193
-                )
194
-            );
195
-        }
196
-        // do we have an event id?
197
-        $id = $this->getEventId();
198
-        // we should really only have 1 registration in the works now
199
-        // (ie, no MER) so unless otherwise requested, clear the session
200
-        if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) {
201
-            $this->session->clear_session(__CLASS__, __FUNCTION__);
202
-        }
203
-        // validate/sanitize/filter data
204
-        $valid = apply_filters(
205
-            'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data',
206
-            $this->validatePostData($id)
207
-        );
208
-        // check total tickets ordered vs max number of attendees that can register
209
-        if ($valid['total_tickets'] > $valid['max_atndz']) {
210
-            $this->maxAttendeesViolation($valid);
211
-        } else {
212
-            // all data appears to be valid
213
-            if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) {
214
-                return true;
215
-            }
216
-        }
217
-        // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT
218
-        // at this point, just return if registration is being made from admin
219
-        if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
220
-            return false;
221
-        }
222
-        if ($valid['return_url']) {
223
-            EEH_URL::safeRedirectAndExit($valid['return_url']);
224
-        }
225
-        if ($id) {
226
-            EEH_URL::safeRedirectAndExit(get_permalink($id));
227
-        }
228
-        echo EE_Error::get_notices();
229
-        return false;
230
-    }
176
+	/**
177
+	 * process_ticket_selections
178
+	 *
179
+	 * @return array|bool
180
+	 * @throws EE_Error
181
+	 * @throws InvalidArgumentException
182
+	 * @throws InvalidDataTypeException
183
+	 * @throws InvalidInterfaceException
184
+	 */
185
+	public function processTicketSelections()
186
+	{
187
+		do_action('EED_Ticket_Selector__process_ticket_selections__before');
188
+		if ($this->request->isBot()) {
189
+			EEH_URL::safeRedirectAndExit(
190
+				apply_filters(
191
+					'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url',
192
+					site_url()
193
+				)
194
+			);
195
+		}
196
+		// do we have an event id?
197
+		$id = $this->getEventId();
198
+		// we should really only have 1 registration in the works now
199
+		// (ie, no MER) so unless otherwise requested, clear the session
200
+		if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) {
201
+			$this->session->clear_session(__CLASS__, __FUNCTION__);
202
+		}
203
+		// validate/sanitize/filter data
204
+		$valid = apply_filters(
205
+			'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data',
206
+			$this->validatePostData($id)
207
+		);
208
+		// check total tickets ordered vs max number of attendees that can register
209
+		if ($valid['total_tickets'] > $valid['max_atndz']) {
210
+			$this->maxAttendeesViolation($valid);
211
+		} else {
212
+			// all data appears to be valid
213
+			if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) {
214
+				return true;
215
+			}
216
+		}
217
+		// die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT
218
+		// at this point, just return if registration is being made from admin
219
+		if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
220
+			return false;
221
+		}
222
+		if ($valid['return_url']) {
223
+			EEH_URL::safeRedirectAndExit($valid['return_url']);
224
+		}
225
+		if ($id) {
226
+			EEH_URL::safeRedirectAndExit(get_permalink($id));
227
+		}
228
+		echo EE_Error::get_notices();
229
+		return false;
230
+	}
231 231
 
232 232
 
233
-    /**
234
-     * @return int
235
-     */
236
-    private function getEventId()
237
-    {
238
-        // do we have an event id?
239
-        if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
240
-            // $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
241
-            EE_Error::add_error(
242
-                sprintf(
243
-                    esc_html__(
244
-                        'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.',
245
-                        'event_espresso'
246
-                    ),
247
-                    '<br/>'
248
-                ),
249
-                __FILE__,
250
-                __FUNCTION__,
251
-                __LINE__
252
-            );
253
-        }
254
-        // if event id is valid
255
-        return absint($this->request->getRequestParam('tkt-slctr-event-id'));
256
-    }
233
+	/**
234
+	 * @return int
235
+	 */
236
+	private function getEventId()
237
+	{
238
+		// do we have an event id?
239
+		if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
240
+			// $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
241
+			EE_Error::add_error(
242
+				sprintf(
243
+					esc_html__(
244
+						'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.',
245
+						'event_espresso'
246
+					),
247
+					'<br/>'
248
+				),
249
+				__FILE__,
250
+				__FUNCTION__,
251
+				__LINE__
252
+			);
253
+		}
254
+		// if event id is valid
255
+		return absint($this->request->getRequestParam('tkt-slctr-event-id'));
256
+	}
257 257
 
258 258
 
259
-    /**
260
-     * validate_post_data
261
-     *
262
-     * @param int $id
263
-     * @return array|FALSE
264
-     */
265
-    private function validatePostData($id = 0)
266
-    {
267
-        if (! $id) {
268
-            EE_Error::add_error(
269
-                esc_html__('The event id provided was not valid.', 'event_espresso'),
270
-                __FILE__,
271
-                __FUNCTION__,
272
-                __LINE__
273
-            );
274
-            return false;
275
-        }
276
-        // start with an empty array()
277
-        $valid_data = array();
278
-        // grab valid id
279
-        $valid_data['id'] = $id;
280
-        // array of other form names
281
-        $inputs_to_clean = array(
282
-            'event_id'   => 'tkt-slctr-event-id',
283
-            'max_atndz'  => 'tkt-slctr-max-atndz-',
284
-            'rows'       => 'tkt-slctr-rows-',
285
-            'qty'        => 'tkt-slctr-qty-',
286
-            'ticket_id'  => 'tkt-slctr-ticket-id-',
287
-            'return_url' => 'tkt-slctr-return-url-',
288
-        );
289
-        // let's track the total number of tickets ordered.'
290
-        $valid_data['total_tickets'] = 0;
291
-        // cycle through $inputs_to_clean array
292
-        foreach ($inputs_to_clean as $what => $input_to_clean) {
293
-            // check for POST data
294
-            if ($this->request->requestParamIsSet($input_to_clean . $id)) {
295
-                // grab value
296
-                $input_value = $this->request->getRequestParam($input_to_clean . $id);
297
-                switch ($what) {
298
-                    // integers
299
-                    case 'event_id':
300
-                        $valid_data[ $what ] = absint($input_value);
301
-                        // get event via the event id we put in the form
302
-                        break;
303
-                    case 'rows':
304
-                    case 'max_atndz':
305
-                        $valid_data[ $what ] = absint($input_value);
306
-                        break;
307
-                    // arrays of integers
308
-                    case 'qty':
309
-                        /** @var array $row_qty */
310
-                        $row_qty = $input_value;
311
-                        // if qty is coming from a radio button input, then we need to assemble an array of rows
312
-                        if (! is_array($row_qty)) {
313
-                            /** @var string $row_qty */
314
-                            // get number of rows
315
-                            $rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id)
316
-                                ? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id))
317
-                                : 1;
318
-                            // explode integers by the dash
319
-                            $row_qty = explode('-', $row_qty);
320
-                            $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1;
321
-                            $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
322
-                            $row_qty = array($row => $qty);
323
-                            for ($x = 1; $x <= $rows; $x++) {
324
-                                if (! isset($row_qty[ $x ])) {
325
-                                    $row_qty[ $x ] = 0;
326
-                                }
327
-                            }
328
-                        }
329
-                        ksort($row_qty);
330
-                        // cycle thru values
331
-                        foreach ($row_qty as $qty) {
332
-                            $qty = absint($qty);
333
-                            // sanitize as integers
334
-                            $valid_data[ $what ][] = $qty;
335
-                            $valid_data['total_tickets'] += $qty;
336
-                        }
337
-                        break;
338
-                    // array of integers
339
-                    case 'ticket_id':
340
-                        // cycle thru values
341
-                        foreach ((array) $input_value as $key => $value) {
342
-                            // allow only integers
343
-                            $valid_data[ $what ][ $key ] = absint($value);
344
-                        }
345
-                        break;
346
-                    case 'return_url':
347
-                        // grab and sanitize return-url
348
-                        $input_value = esc_url_raw($input_value);
349
-                        // was the request coming from an iframe ? if so, then:
350
-                        if (strpos($input_value, 'event_list=iframe')) {
351
-                            // get anchor fragment
352
-                            $input_value = explode('#', $input_value);
353
-                            $input_value = end($input_value);
354
-                            // use event list url instead, but append anchor
355
-                            $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value;
356
-                        }
357
-                        $valid_data[ $what ] = $input_value;
358
-                        break;
359
-                }    // end switch $what
360
-            }
361
-        }    // end foreach $inputs_to_clean
362
-        return $valid_data;
363
-    }
259
+	/**
260
+	 * validate_post_data
261
+	 *
262
+	 * @param int $id
263
+	 * @return array|FALSE
264
+	 */
265
+	private function validatePostData($id = 0)
266
+	{
267
+		if (! $id) {
268
+			EE_Error::add_error(
269
+				esc_html__('The event id provided was not valid.', 'event_espresso'),
270
+				__FILE__,
271
+				__FUNCTION__,
272
+				__LINE__
273
+			);
274
+			return false;
275
+		}
276
+		// start with an empty array()
277
+		$valid_data = array();
278
+		// grab valid id
279
+		$valid_data['id'] = $id;
280
+		// array of other form names
281
+		$inputs_to_clean = array(
282
+			'event_id'   => 'tkt-slctr-event-id',
283
+			'max_atndz'  => 'tkt-slctr-max-atndz-',
284
+			'rows'       => 'tkt-slctr-rows-',
285
+			'qty'        => 'tkt-slctr-qty-',
286
+			'ticket_id'  => 'tkt-slctr-ticket-id-',
287
+			'return_url' => 'tkt-slctr-return-url-',
288
+		);
289
+		// let's track the total number of tickets ordered.'
290
+		$valid_data['total_tickets'] = 0;
291
+		// cycle through $inputs_to_clean array
292
+		foreach ($inputs_to_clean as $what => $input_to_clean) {
293
+			// check for POST data
294
+			if ($this->request->requestParamIsSet($input_to_clean . $id)) {
295
+				// grab value
296
+				$input_value = $this->request->getRequestParam($input_to_clean . $id);
297
+				switch ($what) {
298
+					// integers
299
+					case 'event_id':
300
+						$valid_data[ $what ] = absint($input_value);
301
+						// get event via the event id we put in the form
302
+						break;
303
+					case 'rows':
304
+					case 'max_atndz':
305
+						$valid_data[ $what ] = absint($input_value);
306
+						break;
307
+					// arrays of integers
308
+					case 'qty':
309
+						/** @var array $row_qty */
310
+						$row_qty = $input_value;
311
+						// if qty is coming from a radio button input, then we need to assemble an array of rows
312
+						if (! is_array($row_qty)) {
313
+							/** @var string $row_qty */
314
+							// get number of rows
315
+							$rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id)
316
+								? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id))
317
+								: 1;
318
+							// explode integers by the dash
319
+							$row_qty = explode('-', $row_qty);
320
+							$row = isset($row_qty[0]) ? absint($row_qty[0]) : 1;
321
+							$qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
322
+							$row_qty = array($row => $qty);
323
+							for ($x = 1; $x <= $rows; $x++) {
324
+								if (! isset($row_qty[ $x ])) {
325
+									$row_qty[ $x ] = 0;
326
+								}
327
+							}
328
+						}
329
+						ksort($row_qty);
330
+						// cycle thru values
331
+						foreach ($row_qty as $qty) {
332
+							$qty = absint($qty);
333
+							// sanitize as integers
334
+							$valid_data[ $what ][] = $qty;
335
+							$valid_data['total_tickets'] += $qty;
336
+						}
337
+						break;
338
+					// array of integers
339
+					case 'ticket_id':
340
+						// cycle thru values
341
+						foreach ((array) $input_value as $key => $value) {
342
+							// allow only integers
343
+							$valid_data[ $what ][ $key ] = absint($value);
344
+						}
345
+						break;
346
+					case 'return_url':
347
+						// grab and sanitize return-url
348
+						$input_value = esc_url_raw($input_value);
349
+						// was the request coming from an iframe ? if so, then:
350
+						if (strpos($input_value, 'event_list=iframe')) {
351
+							// get anchor fragment
352
+							$input_value = explode('#', $input_value);
353
+							$input_value = end($input_value);
354
+							// use event list url instead, but append anchor
355
+							$input_value = EEH_Event_View::event_archive_url() . '#' . $input_value;
356
+						}
357
+						$valid_data[ $what ] = $input_value;
358
+						break;
359
+				}    // end switch $what
360
+			}
361
+		}    // end foreach $inputs_to_clean
362
+		return $valid_data;
363
+	}
364 364
 
365 365
 
366
-    /**
367
-     * @param array $valid
368
-     */
369
-    private function maxAttendeesViolation(array $valid)
370
-    {
371
-        // ordering too many tickets !!!
372
-        $total_tickets_string = esc_html(
373
-            _n(
374
-                'You have attempted to purchase %s ticket.',
375
-                'You have attempted to purchase %s tickets.',
376
-                $valid['total_tickets'],
377
-                'event_espresso'
378
-            )
379
-        );
380
-        $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']);
381
-        // dev only message
382
-        $max_attendees_string = esc_html(
383
-            _n(
384
-                'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
385
-                'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
386
-                $valid['max_atndz'],
387
-                'event_espresso'
388
-            )
389
-        );
390
-        $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
391
-        EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
392
-    }
366
+	/**
367
+	 * @param array $valid
368
+	 */
369
+	private function maxAttendeesViolation(array $valid)
370
+	{
371
+		// ordering too many tickets !!!
372
+		$total_tickets_string = esc_html(
373
+			_n(
374
+				'You have attempted to purchase %s ticket.',
375
+				'You have attempted to purchase %s tickets.',
376
+				$valid['total_tickets'],
377
+				'event_espresso'
378
+			)
379
+		);
380
+		$limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']);
381
+		// dev only message
382
+		$max_attendees_string = esc_html(
383
+			_n(
384
+				'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
385
+				'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
386
+				$valid['max_atndz'],
387
+				'event_espresso'
388
+			)
389
+		);
390
+		$limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
391
+		EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
392
+	}
393 393
 
394 394
 
395
-    /**
396
-     * @param array $valid
397
-     * @return int|TRUE
398
-     * @throws EE_Error
399
-     * @throws InvalidArgumentException
400
-     * @throws InvalidDataTypeException
401
-     * @throws InvalidInterfaceException
402
-     */
403
-    private function addTicketsToCart(array $valid)
404
-    {
405
-        $tickets_added = 0;
406
-        $tickets_selected = false;
407
-        if ($valid['total_tickets'] > 0) {
408
-            // load cart using factory because we don't want to do so until actually needed
409
-            $this->cart = CartFactory::getCart();
410
-            // cycle thru the number of data rows sent from the event listing
411
-            for ($x = 0; $x < $valid['rows']; $x++) {
412
-                // does this row actually contain a ticket quantity?
413
-                if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) {
414
-                    // YES we have a ticket quantity
415
-                    $tickets_selected = true;
416
-                    $valid_ticket = false;
417
-                    // \EEH_Debug_Tools::printr(
418
-                    //     $valid['ticket_id'][ $x ],
419
-                    //     '$valid[\'ticket_id\'][ $x ]',
420
-                    //     __FILE__, __LINE__
421
-                    // );
422
-                    if (isset($valid['ticket_id'][ $x ])) {
423
-                        // get ticket via the ticket id we put in the form
424
-                        $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]);
425
-                        if ($ticket instanceof EE_Ticket) {
426
-                            $valid_ticket = true;
427
-                            $tickets_added += $this->addTicketToCart(
428
-                                $ticket,
429
-                                $valid['qty'][ $x ]
430
-                            );
431
-                        }
432
-                    }
433
-                    if ($valid_ticket !== true) {
434
-                        // nothing added to cart retrieved
435
-                        EE_Error::add_error(
436
-                            sprintf(
437
-                                esc_html__(
438
-                                    'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.',
439
-                                    'event_espresso'
440
-                                ),
441
-                                '<br/>'
442
-                            ),
443
-                            __FILE__,
444
-                            __FUNCTION__,
445
-                            __LINE__
446
-                        );
447
-                    }
448
-                    if (EE_Error::has_error()) {
449
-                        break;
450
-                    }
451
-                }
452
-            }
453
-        }
454
-        do_action(
455
-            'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
456
-            $this->cart,
457
-            $this
458
-        );
459
-        if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
460
-            // no ticket quantities were selected
461
-            EE_Error::add_error(
462
-                esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'),
463
-                __FILE__,
464
-                __FUNCTION__,
465
-                __LINE__
466
-            );
467
-        }
468
-        return $tickets_added;
469
-    }
395
+	/**
396
+	 * @param array $valid
397
+	 * @return int|TRUE
398
+	 * @throws EE_Error
399
+	 * @throws InvalidArgumentException
400
+	 * @throws InvalidDataTypeException
401
+	 * @throws InvalidInterfaceException
402
+	 */
403
+	private function addTicketsToCart(array $valid)
404
+	{
405
+		$tickets_added = 0;
406
+		$tickets_selected = false;
407
+		if ($valid['total_tickets'] > 0) {
408
+			// load cart using factory because we don't want to do so until actually needed
409
+			$this->cart = CartFactory::getCart();
410
+			// cycle thru the number of data rows sent from the event listing
411
+			for ($x = 0; $x < $valid['rows']; $x++) {
412
+				// does this row actually contain a ticket quantity?
413
+				if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) {
414
+					// YES we have a ticket quantity
415
+					$tickets_selected = true;
416
+					$valid_ticket = false;
417
+					// \EEH_Debug_Tools::printr(
418
+					//     $valid['ticket_id'][ $x ],
419
+					//     '$valid[\'ticket_id\'][ $x ]',
420
+					//     __FILE__, __LINE__
421
+					// );
422
+					if (isset($valid['ticket_id'][ $x ])) {
423
+						// get ticket via the ticket id we put in the form
424
+						$ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]);
425
+						if ($ticket instanceof EE_Ticket) {
426
+							$valid_ticket = true;
427
+							$tickets_added += $this->addTicketToCart(
428
+								$ticket,
429
+								$valid['qty'][ $x ]
430
+							);
431
+						}
432
+					}
433
+					if ($valid_ticket !== true) {
434
+						// nothing added to cart retrieved
435
+						EE_Error::add_error(
436
+							sprintf(
437
+								esc_html__(
438
+									'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.',
439
+									'event_espresso'
440
+								),
441
+								'<br/>'
442
+							),
443
+							__FILE__,
444
+							__FUNCTION__,
445
+							__LINE__
446
+						);
447
+					}
448
+					if (EE_Error::has_error()) {
449
+						break;
450
+					}
451
+				}
452
+			}
453
+		}
454
+		do_action(
455
+			'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
456
+			$this->cart,
457
+			$this
458
+		);
459
+		if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
460
+			// no ticket quantities were selected
461
+			EE_Error::add_error(
462
+				esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'),
463
+				__FILE__,
464
+				__FUNCTION__,
465
+				__LINE__
466
+			);
467
+		}
468
+		return $tickets_added;
469
+	}
470 470
 
471 471
 
472
-    /**
473
-     * adds a ticket to the cart
474
-     *
475
-     * @param EE_Ticket $ticket
476
-     * @param int       $qty
477
-     * @return TRUE on success, FALSE on fail
478
-     * @throws InvalidArgumentException
479
-     * @throws InvalidInterfaceException
480
-     * @throws InvalidDataTypeException
481
-     * @throws EE_Error
482
-     */
483
-    private function addTicketToCart(EE_Ticket $ticket, $qty = 1)
484
-    {
485
-        // get the number of spaces left for this datetime ticket
486
-        $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket);
487
-        // compare available spaces against the number of tickets being purchased
488
-        if ($available_spaces >= $qty) {
489
-            // allow addons to prevent a ticket from being added to cart
490
-            if (! apply_filters(
491
-                'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
492
-                true,
493
-                $ticket,
494
-                $qty,
495
-                $available_spaces
496
-            )) {
497
-                return false;
498
-            }
499
-            $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket));
500
-            // add event to cart
501
-            if ($this->cart->add_ticket_to_cart($ticket, $qty)) {
502
-                $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty);
503
-                return true;
504
-            }
505
-            return false;
506
-        }
507
-        $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count());
508
-        return false;
509
-    }
472
+	/**
473
+	 * adds a ticket to the cart
474
+	 *
475
+	 * @param EE_Ticket $ticket
476
+	 * @param int       $qty
477
+	 * @return TRUE on success, FALSE on fail
478
+	 * @throws InvalidArgumentException
479
+	 * @throws InvalidInterfaceException
480
+	 * @throws InvalidDataTypeException
481
+	 * @throws EE_Error
482
+	 */
483
+	private function addTicketToCart(EE_Ticket $ticket, $qty = 1)
484
+	{
485
+		// get the number of spaces left for this datetime ticket
486
+		$available_spaces = $this->tracker->ticketDatetimeAvailability($ticket);
487
+		// compare available spaces against the number of tickets being purchased
488
+		if ($available_spaces >= $qty) {
489
+			// allow addons to prevent a ticket from being added to cart
490
+			if (! apply_filters(
491
+				'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
492
+				true,
493
+				$ticket,
494
+				$qty,
495
+				$available_spaces
496
+			)) {
497
+				return false;
498
+			}
499
+			$qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket));
500
+			// add event to cart
501
+			if ($this->cart->add_ticket_to_cart($ticket, $qty)) {
502
+				$this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty);
503
+				return true;
504
+			}
505
+			return false;
506
+		}
507
+		$this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count());
508
+		return false;
509
+	}
510 510
 
511 511
 
512
-    /**
513
-     * @param $tickets_added
514
-     * @return bool
515
-     * @throws InvalidInterfaceException
516
-     * @throws InvalidDataTypeException
517
-     * @throws EE_Error
518
-     * @throws InvalidArgumentException
519
-     */
520
-    private function processSuccessfulCart($tickets_added)
521
-    {
522
-        // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
523
-        if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
524
-            // make sure cart is loaded
525
-            if (! $this->cart instanceof EE_Cart) {
526
-                $this->cart = CartFactory::getCart();
527
-            }
528
-            do_action(
529
-                'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout',
530
-                $this->cart,
531
-                $this
532
-            );
533
-            $this->cart->recalculate_all_cart_totals();
534
-            $this->cart->save_cart(false);
535
-            // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<  OR HERE TO KILL REDIRECT AFTER CART UPDATE
536
-            // just return TRUE for registrations being made from admin
537
-            if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
538
-                return true;
539
-            }
540
-            EEH_URL::safeRedirectAndExit(
541
-                apply_filters(
542
-                    'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url',
543
-                    $this->core_config->reg_page_url()
544
-                )
545
-            );
546
-        }
547
-        if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
548
-            // nothing added to cart
549
-            EE_Error::add_attention(
550
-                esc_html__('No tickets were added for the event', 'event_espresso'),
551
-                __FILE__,
552
-                __FUNCTION__,
553
-                __LINE__
554
-            );
555
-        }
556
-        return false;
557
-    }
512
+	/**
513
+	 * @param $tickets_added
514
+	 * @return bool
515
+	 * @throws InvalidInterfaceException
516
+	 * @throws InvalidDataTypeException
517
+	 * @throws EE_Error
518
+	 * @throws InvalidArgumentException
519
+	 */
520
+	private function processSuccessfulCart($tickets_added)
521
+	{
522
+		// exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
523
+		if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
524
+			// make sure cart is loaded
525
+			if (! $this->cart instanceof EE_Cart) {
526
+				$this->cart = CartFactory::getCart();
527
+			}
528
+			do_action(
529
+				'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout',
530
+				$this->cart,
531
+				$this
532
+			);
533
+			$this->cart->recalculate_all_cart_totals();
534
+			$this->cart->save_cart(false);
535
+			// exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<  OR HERE TO KILL REDIRECT AFTER CART UPDATE
536
+			// just return TRUE for registrations being made from admin
537
+			if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
538
+				return true;
539
+			}
540
+			EEH_URL::safeRedirectAndExit(
541
+				apply_filters(
542
+					'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url',
543
+					$this->core_config->reg_page_url()
544
+				)
545
+			);
546
+		}
547
+		if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
548
+			// nothing added to cart
549
+			EE_Error::add_attention(
550
+				esc_html__('No tickets were added for the event', 'event_espresso'),
551
+				__FILE__,
552
+				__FUNCTION__,
553
+				__LINE__
554
+			);
555
+		}
556
+		return false;
557
+	}
558 558
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
     public function cancelTicketSelections()
119 119
     {
120 120
         // check nonce
121
-        if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
121
+        if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
122 122
             return false;
123 123
         }
124 124
         $this->session->clear_session(__CLASS__, __FUNCTION__);
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
             );
131 131
         }
132 132
         EEH_URL::safeRedirectAndExit(
133
-            site_url('/' . $this->core_config->event_cpt_slug . '/')
133
+            site_url('/'.$this->core_config->event_cpt_slug.'/')
134 134
         );
135 135
         return true;
136 136
     }
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
     private function processTicketSelectorNonce($nonce_name, $id = '')
147 147
     {
148 148
         $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
149
-        if (! $this->request->isAdmin()
149
+        if ( ! $this->request->isAdmin()
150 150
             && (
151 151
                 ! $this->request->is_set($nonce_name_with_id)
152 152
                 || ! wp_verify_nonce(
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
     private function getEventId()
237 237
     {
238 238
         // do we have an event id?
239
-        if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
239
+        if ( ! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
240 240
             // $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
241 241
             EE_Error::add_error(
242 242
                 sprintf(
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
      */
265 265
     private function validatePostData($id = 0)
266 266
     {
267
-        if (! $id) {
267
+        if ( ! $id) {
268 268
             EE_Error::add_error(
269 269
                 esc_html__('The event id provided was not valid.', 'event_espresso'),
270 270
                 __FILE__,
@@ -291,29 +291,29 @@  discard block
 block discarded – undo
291 291
         // cycle through $inputs_to_clean array
292 292
         foreach ($inputs_to_clean as $what => $input_to_clean) {
293 293
             // check for POST data
294
-            if ($this->request->requestParamIsSet($input_to_clean . $id)) {
294
+            if ($this->request->requestParamIsSet($input_to_clean.$id)) {
295 295
                 // grab value
296
-                $input_value = $this->request->getRequestParam($input_to_clean . $id);
296
+                $input_value = $this->request->getRequestParam($input_to_clean.$id);
297 297
                 switch ($what) {
298 298
                     // integers
299 299
                     case 'event_id':
300
-                        $valid_data[ $what ] = absint($input_value);
300
+                        $valid_data[$what] = absint($input_value);
301 301
                         // get event via the event id we put in the form
302 302
                         break;
303 303
                     case 'rows':
304 304
                     case 'max_atndz':
305
-                        $valid_data[ $what ] = absint($input_value);
305
+                        $valid_data[$what] = absint($input_value);
306 306
                         break;
307 307
                     // arrays of integers
308 308
                     case 'qty':
309 309
                         /** @var array $row_qty */
310 310
                         $row_qty = $input_value;
311 311
                         // if qty is coming from a radio button input, then we need to assemble an array of rows
312
-                        if (! is_array($row_qty)) {
312
+                        if ( ! is_array($row_qty)) {
313 313
                             /** @var string $row_qty */
314 314
                             // get number of rows
315
-                            $rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id)
316
-                                ? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id))
315
+                            $rows = $this->request->requestParamIsSet('tkt-slctr-rows-'.$id)
316
+                                ? absint($this->request->getRequestParam('tkt-slctr-rows-'.$id))
317 317
                                 : 1;
318 318
                             // explode integers by the dash
319 319
                             $row_qty = explode('-', $row_qty);
@@ -321,8 +321,8 @@  discard block
 block discarded – undo
321 321
                             $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
322 322
                             $row_qty = array($row => $qty);
323 323
                             for ($x = 1; $x <= $rows; $x++) {
324
-                                if (! isset($row_qty[ $x ])) {
325
-                                    $row_qty[ $x ] = 0;
324
+                                if ( ! isset($row_qty[$x])) {
325
+                                    $row_qty[$x] = 0;
326 326
                                 }
327 327
                             }
328 328
                         }
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
                         foreach ($row_qty as $qty) {
332 332
                             $qty = absint($qty);
333 333
                             // sanitize as integers
334
-                            $valid_data[ $what ][] = $qty;
334
+                            $valid_data[$what][] = $qty;
335 335
                             $valid_data['total_tickets'] += $qty;
336 336
                         }
337 337
                         break;
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
                         // cycle thru values
341 341
                         foreach ((array) $input_value as $key => $value) {
342 342
                             // allow only integers
343
-                            $valid_data[ $what ][ $key ] = absint($value);
343
+                            $valid_data[$what][$key] = absint($value);
344 344
                         }
345 345
                         break;
346 346
                     case 'return_url':
@@ -352,9 +352,9 @@  discard block
 block discarded – undo
352 352
                             $input_value = explode('#', $input_value);
353 353
                             $input_value = end($input_value);
354 354
                             // use event list url instead, but append anchor
355
-                            $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value;
355
+                            $input_value = EEH_Event_View::event_archive_url().'#'.$input_value;
356 356
                         }
357
-                        $valid_data[ $what ] = $input_value;
357
+                        $valid_data[$what] = $input_value;
358 358
                         break;
359 359
                 }    // end switch $what
360 360
             }
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
             )
389 389
         );
390 390
         $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
391
-        EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
391
+        EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__);
392 392
     }
393 393
 
394 394
 
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
             // cycle thru the number of data rows sent from the event listing
411 411
             for ($x = 0; $x < $valid['rows']; $x++) {
412 412
                 // does this row actually contain a ticket quantity?
413
-                if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) {
413
+                if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) {
414 414
                     // YES we have a ticket quantity
415 415
                     $tickets_selected = true;
416 416
                     $valid_ticket = false;
@@ -419,14 +419,14 @@  discard block
 block discarded – undo
419 419
                     //     '$valid[\'ticket_id\'][ $x ]',
420 420
                     //     __FILE__, __LINE__
421 421
                     // );
422
-                    if (isset($valid['ticket_id'][ $x ])) {
422
+                    if (isset($valid['ticket_id'][$x])) {
423 423
                         // get ticket via the ticket id we put in the form
424
-                        $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]);
424
+                        $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][$x]);
425 425
                         if ($ticket instanceof EE_Ticket) {
426 426
                             $valid_ticket = true;
427 427
                             $tickets_added += $this->addTicketToCart(
428 428
                                 $ticket,
429
-                                $valid['qty'][ $x ]
429
+                                $valid['qty'][$x]
430 430
                             );
431 431
                         }
432 432
                     }
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
             $this->cart,
457 457
             $this
458 458
         );
459
-        if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
459
+        if ( ! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
460 460
             // no ticket quantities were selected
461 461
             EE_Error::add_error(
462 462
                 esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'),
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
         // compare available spaces against the number of tickets being purchased
488 488
         if ($available_spaces >= $qty) {
489 489
             // allow addons to prevent a ticket from being added to cart
490
-            if (! apply_filters(
490
+            if ( ! apply_filters(
491 491
                 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
492 492
                 true,
493 493
                 $ticket,
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
         // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
523 523
         if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
524 524
             // make sure cart is loaded
525
-            if (! $this->cart instanceof EE_Cart) {
525
+            if ( ! $this->cart instanceof EE_Cart) {
526 526
                 $this->cart = CartFactory::getCart();
527 527
             }
528 528
             do_action(
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
                 )
545 545
             );
546 546
         }
547
-        if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
547
+        if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
548 548
             // nothing added to cart
549 549
             EE_Error::add_attention(
550 550
                 esc_html__('No tickets were added for the event', 'event_espresso'),
Please login to merge, or discard this patch.