Completed
Branch FET/Gutenberg/11467/espresso-c... (cff346)
by
unknown
30:09 queued 14:32
created
core/services/editor/EspressoGutenbergEditor.php 2 patches
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -20,84 +20,84 @@
 block discarded – undo
20 20
 class EspressoGutenbergEditor extends EditorBlockManager
21 21
 {
22 22
 
23
-    /**
24
-     *  Returns the name of a hookpoint to be used to call initialize()
25
-     *
26
-     * @return string
27
-     */
28
-    public function init_hook()
29
-    {
30
-        return 'AHEE__EE_System__load_CPTs_and_session__complete';
31
-    }
23
+	/**
24
+	 *  Returns the name of a hookpoint to be used to call initialize()
25
+	 *
26
+	 * @return string
27
+	 */
28
+	public function init_hook()
29
+	{
30
+		return 'AHEE__EE_System__load_CPTs_and_session__complete';
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * Perform any early setup required for block editors to functions
36
-     *
37
-     * @return void
38
-     */
39
-    public function initialize()
40
-    {
41
-        $custom_post_types     = EE_Register_CPTs::get_CPTs();
42
-        $espresso_post_types   = array_keys($custom_post_types);
43
-        $espresso_post_types[] = 'espresso_registrations';
44
-        if (
45
-            ($this->action === 'edit' || $this->action === 'create_new' || $this->action === 'edit_attendee')
46
-            && in_array($this->page, $espresso_post_types, true)
47
-        ) {
48
-            $this->loadCustomPostTypeBlockEditor(array_keys($custom_post_types));
49
-        }
50
-        add_action('admin_url', array($this, 'coerceEeCptEditorUrlForGutenberg'), 10, 3);/**/
51
-    }
34
+	/**
35
+	 * Perform any early setup required for block editors to functions
36
+	 *
37
+	 * @return void
38
+	 */
39
+	public function initialize()
40
+	{
41
+		$custom_post_types     = EE_Register_CPTs::get_CPTs();
42
+		$espresso_post_types   = array_keys($custom_post_types);
43
+		$espresso_post_types[] = 'espresso_registrations';
44
+		if (
45
+			($this->action === 'edit' || $this->action === 'create_new' || $this->action === 'edit_attendee')
46
+			&& in_array($this->page, $espresso_post_types, true)
47
+		) {
48
+			$this->loadCustomPostTypeBlockEditor(array_keys($custom_post_types));
49
+		}
50
+		add_action('admin_url', array($this, 'coerceEeCptEditorUrlForGutenberg'), 10, 3);/**/
51
+	}
52 52
 
53 53
 
54
-    public function loadCustomPostTypeBlockEditor(array $custom_post_types)
55
-    {
56
-        $this->modifyWpPostTypes($custom_post_types);
57
-        // add_action('admin_enqueue_scripts', array($this, 'registerAdminScripts'), 20);
58
-        add_filter('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', 'gutenberg_init', 10, 2);
59
-    }
54
+	public function loadCustomPostTypeBlockEditor(array $custom_post_types)
55
+	{
56
+		$this->modifyWpPostTypes($custom_post_types);
57
+		// add_action('admin_enqueue_scripts', array($this, 'registerAdminScripts'), 20);
58
+		add_filter('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', 'gutenberg_init', 10, 2);
59
+	}
60 60
 
61 61
 
62
-    /**
63
-     * Manipulate globals related to EE Post Type so gutenberg loads.
64
-     *
65
-     * @param array $custom_post_types
66
-     */
67
-    private function modifyWpPostTypes(array $custom_post_types)
68
-    {
69
-        global $wp_post_types, $_wp_post_type_features;
70
-        foreach ($custom_post_types as $post_type) {
71
-            $_wp_post_type_features[ $post_type ]['editor'] = true;
72
-            if (isset($wp_post_types[ $post_type ]) && $wp_post_types[ $post_type ] instanceof WP_Post_Type) {
73
-                $post_type_object               = $wp_post_types[ $post_type ];
74
-                $post_type_object->show_in_rest = true;
75
-                $post_type_object->template     = array();
76
-                foreach ($this->blocks as $block) {
77
-                    if ($block->appliesToPostType($post_type)) {
78
-                        $post_type_object->template[] = $block->getEditorContainer();
79
-                    }
80
-                }
81
-            }
82
-        }
83
-    }
62
+	/**
63
+	 * Manipulate globals related to EE Post Type so gutenberg loads.
64
+	 *
65
+	 * @param array $custom_post_types
66
+	 */
67
+	private function modifyWpPostTypes(array $custom_post_types)
68
+	{
69
+		global $wp_post_types, $_wp_post_type_features;
70
+		foreach ($custom_post_types as $post_type) {
71
+			$_wp_post_type_features[ $post_type ]['editor'] = true;
72
+			if (isset($wp_post_types[ $post_type ]) && $wp_post_types[ $post_type ] instanceof WP_Post_Type) {
73
+				$post_type_object               = $wp_post_types[ $post_type ];
74
+				$post_type_object->show_in_rest = true;
75
+				$post_type_object->template     = array();
76
+				foreach ($this->blocks as $block) {
77
+					if ($block->appliesToPostType($post_type)) {
78
+						$post_type_object->template[] = $block->getEditorContainer();
79
+					}
80
+				}
81
+			}
82
+		}
83
+	}
84 84
 
85 85
 
86
-    public function coerceEeCptEditorUrlForGutenberg($url, $path, $blog_id)
87
-    {
88
-        if (
89
-            $this->page === 'espresso_events'
90
-            && ($this->action === 'edit' || $this->action === 'create_new')
91
-            && strpos($path, 'post.php') !== false
92
-        ) {
93
-            return add_query_arg(
94
-                array(
95
-                    'page'   => $this->page,
96
-                    'action' => $this->action
97
-                ),
98
-                get_site_url($blog_id)
99
-            );
100
-        }
101
-        return $url;
102
-    }
86
+	public function coerceEeCptEditorUrlForGutenberg($url, $path, $blog_id)
87
+	{
88
+		if (
89
+			$this->page === 'espresso_events'
90
+			&& ($this->action === 'edit' || $this->action === 'create_new')
91
+			&& strpos($path, 'post.php') !== false
92
+		) {
93
+			return add_query_arg(
94
+				array(
95
+					'page'   => $this->page,
96
+					'action' => $this->action
97
+				),
98
+				get_site_url($blog_id)
99
+			);
100
+		}
101
+		return $url;
102
+	}
103 103
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
         ) {
48 48
             $this->loadCustomPostTypeBlockEditor(array_keys($custom_post_types));
49 49
         }
50
-        add_action('admin_url', array($this, 'coerceEeCptEditorUrlForGutenberg'), 10, 3);/**/
50
+        add_action('admin_url', array($this, 'coerceEeCptEditorUrlForGutenberg'), 10, 3); /**/
51 51
     }
52 52
 
53 53
 
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
     {
69 69
         global $wp_post_types, $_wp_post_type_features;
70 70
         foreach ($custom_post_types as $post_type) {
71
-            $_wp_post_type_features[ $post_type ]['editor'] = true;
72
-            if (isset($wp_post_types[ $post_type ]) && $wp_post_types[ $post_type ] instanceof WP_Post_Type) {
73
-                $post_type_object               = $wp_post_types[ $post_type ];
71
+            $_wp_post_type_features[$post_type]['editor'] = true;
72
+            if (isset($wp_post_types[$post_type]) && $wp_post_types[$post_type] instanceof WP_Post_Type) {
73
+                $post_type_object               = $wp_post_types[$post_type];
74 74
                 $post_type_object->show_in_rest = true;
75 75
                 $post_type_object->template     = array();
76 76
                 foreach ($this->blocks as $block) {
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 1 patch
Indentation   +857 added lines, -857 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use EventEspresso\core\services\request\ResponseInterface;
9 9
 
10 10
 if (! defined('EVENT_ESPRESSO_VERSION')) {
11
-    exit('No direct script access allowed');
11
+	exit('No direct script access allowed');
12 12
 }
13 13
 
14 14
 
@@ -25,862 +25,862 @@  discard block
 block discarded – undo
25 25
 class EE_Dependency_Map
26 26
 {
27 27
 
28
-    /**
29
-     * This means that the requested class dependency is not present in the dependency map
30
-     */
31
-    const not_registered = 0;
32
-
33
-    /**
34
-     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
35
-     */
36
-    const load_new_object = 1;
37
-
38
-    /**
39
-     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
40
-     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
41
-     */
42
-    const load_from_cache = 2;
43
-
44
-    /**
45
-     * When registering a dependency,
46
-     * this indicates to keep any existing dependencies that already exist,
47
-     * and simply discard any new dependencies declared in the incoming data
48
-     */
49
-    const KEEP_EXISTING_DEPENDENCIES = 0;
50
-
51
-    /**
52
-     * When registering a dependency,
53
-     * this indicates to overwrite any existing dependencies that already exist using the incoming data
54
-     */
55
-    const OVERWRITE_DEPENDENCIES = 1;
56
-
57
-
58
-
59
-    /**
60
-     * @type EE_Dependency_Map $_instance
61
-     */
62
-    protected static $_instance;
63
-
64
-    /**
65
-     * @type RequestInterface $request
66
-     */
67
-    protected $request;
68
-
69
-    /**
70
-     * @type LegacyRequestInterface $legacy_request
71
-     */
72
-    protected $legacy_request;
73
-
74
-    /**
75
-     * @type ResponseInterface $response
76
-     */
77
-    protected $response;
78
-
79
-    /**
80
-     * @type LoaderInterface $loader
81
-     */
82
-    protected $loader;
83
-
84
-    /**
85
-     * @type array $_dependency_map
86
-     */
87
-    protected $_dependency_map = array();
88
-
89
-    /**
90
-     * @type array $_class_loaders
91
-     */
92
-    protected $_class_loaders = array();
93
-
94
-    /**
95
-     * @type array $_aliases
96
-     */
97
-    protected $_aliases = array();
98
-
99
-
100
-
101
-    /**
102
-     * EE_Dependency_Map constructor.
103
-     */
104
-    protected function __construct()
105
-    {
106
-        // add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
107
-        do_action('EE_Dependency_Map____construct');
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * @throws InvalidDataTypeException
114
-     * @throws InvalidInterfaceException
115
-     * @throws InvalidArgumentException
116
-     */
117
-    public function initialize()
118
-    {
119
-        $this->_register_core_dependencies();
120
-        $this->_register_core_class_loaders();
121
-        $this->_register_core_aliases();
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * @singleton method used to instantiate class object
128
-     * @return EE_Dependency_Map
129
-     */
130
-    public static function instance() {
131
-        // check if class object is instantiated, and instantiated properly
132
-        if (! self::$_instance instanceof EE_Dependency_Map) {
133
-            self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/);
134
-        }
135
-        return self::$_instance;
136
-    }
137
-
138
-
139
-    /**
140
-     * @param RequestInterface $request
141
-     */
142
-    public function setRequest(RequestInterface $request)
143
-    {
144
-        $this->request = $request;
145
-    }
146
-
147
-
148
-    /**
149
-     * @param LegacyRequestInterface $legacy_request
150
-     */
151
-    public function setLegacyRequest(LegacyRequestInterface $legacy_request)
152
-    {
153
-        $this->legacy_request = $legacy_request;
154
-    }
155
-
156
-
157
-    /**
158
-     * @param ResponseInterface $response
159
-     */
160
-    public function setResponse(ResponseInterface $response)
161
-    {
162
-        $this->response = $response;
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * @param LoaderInterface $loader
169
-     */
170
-    public function setLoader(LoaderInterface $loader)
171
-    {
172
-        $this->loader = $loader;
173
-    }
174
-
175
-
176
-
177
-    /**
178
-     * @param string $class
179
-     * @param array  $dependencies
180
-     * @param int    $overwrite
181
-     * @return bool
182
-     */
183
-    public static function register_dependencies(
184
-        $class,
185
-        array $dependencies,
186
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
187
-    ) {
188
-        return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
189
-    }
190
-
191
-
192
-
193
-    /**
194
-     * Assigns an array of class names and corresponding load sources (new or cached)
195
-     * to the class specified by the first parameter.
196
-     * IMPORTANT !!!
197
-     * The order of elements in the incoming $dependencies array MUST match
198
-     * the order of the constructor parameters for the class in question.
199
-     * This is especially important when overriding any existing dependencies that are registered.
200
-     * the third parameter controls whether any duplicate dependencies are overwritten or not.
201
-     *
202
-     * @param string $class
203
-     * @param array  $dependencies
204
-     * @param int    $overwrite
205
-     * @return bool
206
-     */
207
-    public function registerDependencies(
208
-        $class,
209
-        array $dependencies,
210
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
211
-    ) {
212
-        $class = trim($class, '\\');
213
-        $registered = false;
214
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
215
-            self::$_instance->_dependency_map[ $class ] = array();
216
-        }
217
-        // we need to make sure that any aliases used when registering a dependency
218
-        // get resolved to the correct class name
219
-        foreach ($dependencies as $dependency => $load_source) {
220
-            $alias = self::$_instance->get_alias($dependency);
221
-            if (
222
-                $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
223
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
224
-            ) {
225
-                unset($dependencies[$dependency]);
226
-                $dependencies[$alias] = $load_source;
227
-                $registered = true;
228
-            }
229
-        }
230
-        // now add our two lists of dependencies together.
231
-        // using Union (+=) favours the arrays in precedence from left to right,
232
-        // so $dependencies is NOT overwritten because it is listed first
233
-        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
234
-        // Union is way faster than array_merge() but should be used with caution...
235
-        // especially with numerically indexed arrays
236
-        $dependencies += self::$_instance->_dependency_map[ $class ];
237
-        // now we need to ensure that the resulting dependencies
238
-        // array only has the entries that are required for the class
239
-        // so first count how many dependencies were originally registered for the class
240
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
241
-        // if that count is non-zero (meaning dependencies were already registered)
242
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
243
-            // then truncate the  final array to match that count
244
-            ? array_slice($dependencies, 0, $dependency_count)
245
-            // otherwise just take the incoming array because nothing previously existed
246
-            : $dependencies;
247
-        return $registered;
248
-    }
249
-
250
-
251
-
252
-    /**
253
-     * @param string $class_name
254
-     * @param string $loader
255
-     * @return bool
256
-     * @throws DomainException
257
-     */
258
-    public static function register_class_loader($class_name, $loader = 'load_core')
259
-    {
260
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
261
-            throw new DomainException(
262
-                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
263
-            );
264
-        }
265
-        // check that loader is callable or method starts with "load_" and exists in EE_Registry
266
-        if (
267
-            ! is_callable($loader)
268
-            && (
269
-                strpos($loader, 'load_') !== 0
270
-                || ! method_exists('EE_Registry', $loader)
271
-            )
272
-        ) {
273
-            throw new DomainException(
274
-                sprintf(
275
-                    esc_html__(
276
-                        '"%1$s" is not a valid loader method on EE_Registry.',
277
-                        'event_espresso'
278
-                    ),
279
-                    $loader
280
-                )
281
-            );
282
-        }
283
-        $class_name = self::$_instance->get_alias($class_name);
284
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
285
-            self::$_instance->_class_loaders[$class_name] = $loader;
286
-            return true;
287
-        }
288
-        return false;
289
-    }
290
-
291
-
292
-
293
-    /**
294
-     * @return array
295
-     */
296
-    public function dependency_map()
297
-    {
298
-        return $this->_dependency_map;
299
-    }
300
-
301
-
302
-
303
-    /**
304
-     * returns TRUE if dependency map contains a listing for the provided class name
305
-     *
306
-     * @param string $class_name
307
-     * @return boolean
308
-     */
309
-    public function has($class_name = '')
310
-    {
311
-        // all legacy models have the same dependencies
312
-        if (strpos($class_name, 'EEM_') === 0) {
313
-            $class_name = 'LEGACY_MODELS';
314
-        }
315
-        return isset($this->_dependency_map[$class_name]) ? true : false;
316
-    }
317
-
318
-
319
-
320
-    /**
321
-     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
322
-     *
323
-     * @param string $class_name
324
-     * @param string $dependency
325
-     * @return bool
326
-     */
327
-    public function has_dependency_for_class($class_name = '', $dependency = '')
328
-    {
329
-        // all legacy models have the same dependencies
330
-        if (strpos($class_name, 'EEM_') === 0) {
331
-            $class_name = 'LEGACY_MODELS';
332
-        }
333
-        $dependency = $this->get_alias($dependency);
334
-        return isset($this->_dependency_map[$class_name][$dependency])
335
-            ? true
336
-            : false;
337
-    }
338
-
339
-
340
-
341
-    /**
342
-     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
343
-     *
344
-     * @param string $class_name
345
-     * @param string $dependency
346
-     * @return int
347
-     */
348
-    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
349
-    {
350
-        // all legacy models have the same dependencies
351
-        if (strpos($class_name, 'EEM_') === 0) {
352
-            $class_name = 'LEGACY_MODELS';
353
-        }
354
-        $dependency = $this->get_alias($dependency);
355
-        return $this->has_dependency_for_class($class_name, $dependency)
356
-            ? $this->_dependency_map[$class_name][$dependency]
357
-            : EE_Dependency_Map::not_registered;
358
-    }
359
-
360
-
361
-
362
-    /**
363
-     * @param string $class_name
364
-     * @return string | Closure
365
-     */
366
-    public function class_loader($class_name)
367
-    {
368
-        // all legacy models use load_model()
369
-        if(strpos($class_name, 'EEM_') === 0){
370
-            return 'load_model';
371
-        }
372
-        $class_name = $this->get_alias($class_name);
373
-        return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
374
-    }
375
-
376
-
377
-
378
-    /**
379
-     * @return array
380
-     */
381
-    public function class_loaders()
382
-    {
383
-        return $this->_class_loaders;
384
-    }
385
-
386
-
387
-
388
-    /**
389
-     * adds an alias for a classname
390
-     *
391
-     * @param string $class_name the class name that should be used (concrete class to replace interface)
392
-     * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
393
-     * @param string $for_class  the class that has the dependency (is type hinting for the interface)
394
-     */
395
-    public function add_alias($class_name, $alias, $for_class = '')
396
-    {
397
-        if ($for_class !== '') {
398
-            if (! isset($this->_aliases[$for_class])) {
399
-                $this->_aliases[$for_class] = array();
400
-            }
401
-            $this->_aliases[$for_class][$class_name] = $alias;
402
-        }
403
-        $this->_aliases[$class_name] = $alias;
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * returns TRUE if the provided class name has an alias
410
-     *
411
-     * @param string $class_name
412
-     * @param string $for_class
413
-     * @return bool
414
-     */
415
-    public function has_alias($class_name = '', $for_class = '')
416
-    {
417
-        return isset($this->_aliases[$for_class][$class_name])
418
-               || (
419
-                   isset($this->_aliases[$class_name])
420
-                   && ! is_array($this->_aliases[$class_name])
421
-               );
422
-    }
423
-
424
-
425
-
426
-    /**
427
-     * returns alias for class name if one exists, otherwise returns the original classname
428
-     * functions recursively, so that multiple aliases can be used to drill down to a classname
429
-     *  for example:
430
-     *      if the following two entries were added to the _aliases array:
431
-     *          array(
432
-     *              'interface_alias'           => 'some\namespace\interface'
433
-     *              'some\namespace\interface'  => 'some\namespace\classname'
434
-     *          )
435
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
436
-     *      to load an instance of 'some\namespace\classname'
437
-     *
438
-     * @param string $class_name
439
-     * @param string $for_class
440
-     * @return string
441
-     */
442
-    public function get_alias($class_name = '', $for_class = '')
443
-    {
444
-        if (! $this->has_alias($class_name, $for_class)) {
445
-            return $class_name;
446
-        }
447
-        if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
448
-            return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
449
-        }
450
-        return $this->get_alias($this->_aliases[$class_name]);
451
-    }
452
-
453
-
454
-
455
-    /**
456
-     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
457
-     * if one exists, or whether a new object should be generated every time the requested class is loaded.
458
-     * This is done by using the following class constants:
459
-     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
460
-     *        EE_Dependency_Map::load_new_object - generates a new object every time
461
-     */
462
-    protected function _register_core_dependencies()
463
-    {
464
-        $this->_dependency_map = array(
465
-            'EE_Request_Handler'                                                                                          => array(
466
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
467
-            ),
468
-            'EE_System'                                                                                                   => array(
469
-                'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
470
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
471
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
472
-                'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
473
-            ),
474
-            'EE_Session'                                                                                                  => array(
475
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
476
-                'EventEspresso\core\services\request\Request'             => EE_Dependency_Map::load_from_cache,
477
-                'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
478
-            ),
479
-            'EE_Cart'                                                                                                     => array(
480
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
481
-            ),
482
-            'EE_Front_Controller'                                                                                         => array(
483
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
484
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
485
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
486
-            ),
487
-            'EE_Messenger_Collection_Loader'                                                                              => array(
488
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
489
-            ),
490
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
491
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
492
-            ),
493
-            'EE_Message_Resource_Manager'                                                                                 => array(
494
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
495
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
496
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
497
-            ),
498
-            'EE_Message_Factory'                                                                                          => array(
499
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
500
-            ),
501
-            'EE_messages'                                                                                                 => array(
502
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
503
-            ),
504
-            'EE_Messages_Generator'                                                                                       => array(
505
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
506
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
507
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
508
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
509
-            ),
510
-            'EE_Messages_Processor'                                                                                       => array(
511
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
512
-            ),
513
-            'EE_Messages_Queue'                                                                                           => array(
514
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
515
-            ),
516
-            'EE_Messages_Template_Defaults'                                                                               => array(
517
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
518
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
519
-            ),
520
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
521
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
522
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
523
-            ),
524
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
525
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
526
-            ),
527
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
528
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
529
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
530
-            ),
531
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
532
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
533
-            ),
534
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
535
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
536
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
537
-            ),
538
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
539
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
540
-            ),
541
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
542
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
543
-            ),
544
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
545
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
546
-            ),
547
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
548
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
549
-            ),
550
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
551
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
552
-            ),
553
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
554
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
555
-            ),
556
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
557
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
558
-            ),
559
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
560
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
561
-            ),
562
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
563
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
564
-            ),
565
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
566
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
567
-            ),
568
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
569
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
570
-            ),
571
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
572
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
573
-            ),
574
-            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
575
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
576
-            ),
577
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
578
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
579
-            ),
580
-            'EE_Data_Migration_Class_Base'                                                                                => array(
581
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
582
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
583
-            ),
584
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
585
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
586
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
587
-            ),
588
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
589
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
590
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
591
-            ),
592
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
593
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
594
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
595
-            ),
596
-            'EE_DMS_Core_4_4_0'                                                                                           => array(
597
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
598
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
599
-            ),
600
-            'EE_DMS_Core_4_5_0'                                                                                           => array(
601
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
602
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
603
-            ),
604
-            'EE_DMS_Core_4_6_0'                                                                                           => array(
605
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
606
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
607
-            ),
608
-            'EE_DMS_Core_4_7_0'                                                                                           => array(
609
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
610
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
611
-            ),
612
-            'EE_DMS_Core_4_8_0'                                                                                           => array(
613
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
614
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
615
-            ),
616
-            'EE_DMS_Core_4_9_0'                                                                                           => array(
617
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
618
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
619
-            ),
620
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
621
-                'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
622
-                'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
623
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
624
-            ),
625
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
626
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
627
-            ),
628
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
629
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
630
-            ),
631
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
632
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
633
-            ),
634
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
635
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
636
-            ),
637
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
638
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
639
-            ),
640
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
641
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
642
-            ),
643
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
644
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
645
-            ),
646
-            'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
647
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
648
-            ),
649
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'                  => array(
650
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
651
-            ),
652
-            'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
653
-                'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
654
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
655
-            ),
656
-            'EventEspresso\core\domain\values\EmailAddress'                              => array(
657
-                null,
658
-                'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
659
-            ),
660
-            'EventEspresso\core\services\orm\ModelFieldFactory' => array(
661
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
662
-            ),
663
-            'LEGACY_MODELS'                                                   => array(
664
-                null,
665
-                'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
666
-            ),
667
-            'EE_Module_Request_Router'                                               => array(
668
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
669
-            ),
670
-            'EE_Registration_Processor'                                              => array(
671
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
672
-            ),
673
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array(
674
-                null,
675
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
676
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
677
-            ),
678
-            'EventEspresso\core\services\editor\EditorBlockRegistrationManager'      => array(
679
-                'EventEspresso\core\domain\entities\editor\EditorBlockCollection' => EE_Dependency_Map::load_from_cache,
680
-                'EE_Request'                                                      => EE_Dependency_Map::load_from_cache,
681
-                'EventEspresso\core\domain\Domain'                                => EE_Dependency_Map::load_from_cache,
682
-            ),
683
-            'EventEspresso\core\services\editor\EspressoGutenbergEditor' => array(
684
-                'EventEspresso\core\domain\entities\editor\EditorBlockCollection' => EE_Dependency_Map::load_from_cache,
685
-                'EE_Request'                                                      => EE_Dependency_Map::load_from_cache,
686
-                'EventEspresso\core\domain\Domain'                                => EE_Dependency_Map::load_from_cache,
687
-            ),
688
-            'EventEspresso\core\domain\entities\editor\blocks\shortcodes\EventsList'     => array(
689
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
690
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
691
-            ),
692
-            'EventEspresso\core\domain\entities\editor\blocks\TicketSelector'                   => array(
693
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
694
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
695
-            ),
696
-            'EventEspresso\core\domain\entities\editor\blocks\VenueEditor'                      => array(
697
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
698
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
699
-            ),
700
-            'EventEspresso\core\domain\entities\editor\blocks\common\NextUpcomingEventDatetime' => array(
701
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
702
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
703
-            ),
704
-        );
705
-    }
706
-
707
-
708
-
709
-    /**
710
-     * Registers how core classes are loaded.
711
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
712
-     *        'EE_Request_Handler' => 'load_core'
713
-     *        'EE_Messages_Queue'  => 'load_lib'
714
-     *        'EEH_Debug_Tools'    => 'load_helper'
715
-     * or, if greater control is required, by providing a custom closure. For example:
716
-     *        'Some_Class' => function () {
717
-     *            return new Some_Class();
718
-     *        },
719
-     * This is required for instantiating dependencies
720
-     * where an interface has been type hinted in a class constructor. For example:
721
-     *        'Required_Interface' => function () {
722
-     *            return new A_Class_That_Implements_Required_Interface();
723
-     *        },
724
-     *
725
-     * @throws InvalidInterfaceException
726
-     * @throws InvalidDataTypeException
727
-     * @throws InvalidArgumentException
728
-     */
729
-    protected function _register_core_class_loaders()
730
-    {
731
-        //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
732
-        //be used in a closure.
733
-        $request = &$this->request;
734
-        $response = &$this->response;
735
-        $legacy_request = &$this->legacy_request;
736
-        // $loader = &$this->loader;
737
-        $this->_class_loaders = array(
738
-            //load_core
739
-            'EE_Capabilities'          => 'load_core',
740
-            'EE_Encryption'            => 'load_core',
741
-            'EE_Front_Controller'      => 'load_core',
742
-            'EE_Module_Request_Router' => 'load_core',
743
-            'EE_Registry'              => 'load_core',
744
-            'EE_Request'               => function () use (&$legacy_request) {
745
-                return $legacy_request;
746
-            },
747
-            'EventEspresso\core\services\request\Request' => function () use (&$request) {
748
-                return $request;
749
-            },
750
-            'EventEspresso\core\services\request\Response' => function () use (&$response) {
751
-                return $response;
752
-            },
753
-            'EE_Request_Handler'       => 'load_core',
754
-            'EE_Session'               => 'load_core',
755
-            'EE_Cron_Tasks'            => 'load_core',
756
-            'EE_System'                => 'load_core',
757
-            'EE_Maintenance_Mode'      => 'load_core',
758
-            'EE_Register_CPTs'         => 'load_core',
759
-            'EE_Admin'                 => 'load_core',
760
-            //load_lib
761
-            'EE_Message_Resource_Manager'          => 'load_lib',
762
-            'EE_Message_Type_Collection'           => 'load_lib',
763
-            'EE_Message_Type_Collection_Loader'    => 'load_lib',
764
-            'EE_Messenger_Collection'              => 'load_lib',
765
-            'EE_Messenger_Collection_Loader'       => 'load_lib',
766
-            'EE_Messages_Processor'                => 'load_lib',
767
-            'EE_Message_Repository'                => 'load_lib',
768
-            'EE_Messages_Queue'                    => 'load_lib',
769
-            'EE_Messages_Data_Handler_Collection'  => 'load_lib',
770
-            'EE_Message_Template_Group_Collection' => 'load_lib',
771
-            'EE_Payment_Method_Manager'            => 'load_lib',
772
-            'EE_Messages_Generator'                => function () {
773
-                return EE_Registry::instance()->load_lib(
774
-                    'Messages_Generator',
775
-                    array(),
776
-                    false,
777
-                    false
778
-                );
779
-            },
780
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
781
-                return EE_Registry::instance()->load_lib(
782
-                    'Messages_Template_Defaults',
783
-                    $arguments,
784
-                    false,
785
-                    false
786
-                );
787
-            },
788
-            //load_model
789
-            // 'EEM_Attendee'                         => 'load_model',
790
-            // 'EEM_Message_Template_Group'           => 'load_model',
791
-            // 'EEM_Message_Template'                 => 'load_model',
792
-            //load_helper
793
-            'EEH_Parse_Shortcodes'                 => function () {
794
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
795
-                    return new EEH_Parse_Shortcodes();
796
-                }
797
-                return null;
798
-            },
799
-            'EE_Template_Config'                   => function () {
800
-                return EE_Config::instance()->template_settings;
801
-            },
802
-            'EE_Currency_Config'                   => function () {
803
-                return EE_Config::instance()->currency;
804
-            },
805
-            'EE_Registration_Config'                   => function () {
806
-                return EE_Config::instance()->registration;
807
-            },
808
-            'EventEspresso\core\services\loaders\Loader' => function () {
809
-                return LoaderFactory::getLoader();
810
-            },
811
-        );
812
-    }
813
-
814
-
815
-
816
-    /**
817
-     * can be used for supplying alternate names for classes,
818
-     * or for connecting interface names to instantiable classes
819
-     */
820
-    protected function _register_core_aliases()
821
-    {
822
-        $this->_aliases = array(
823
-            'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
824
-            'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
825
-            'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
826
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
827
-            'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
828
-            'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
829
-            'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
830
-            'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
831
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
832
-            'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
833
-            'CreateRegCodeCommandHandler'                                                  => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
834
-            'CreateRegUrlLinkCommandHandler'                                               => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
835
-            'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
836
-            'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
837
-            'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
838
-            'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
839
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
840
-            'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
841
-            'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
842
-            'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
843
-            'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
844
-            'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
845
-            'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
846
-            'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
847
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
848
-            'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
849
-            'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
850
-            'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
851
-            'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
852
-            'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
853
-            'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
854
-            'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
855
-            'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
856
-            'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
857
-            'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
858
-            'NoticesContainerInterface'                                           => 'EventEspresso\core\services\notices\NoticesContainerInterface',
859
-            'EventEspresso\core\services\notices\NoticesContainerInterface'       => 'EventEspresso\core\services\notices\NoticesContainer',
860
-            'EventEspresso\core\services\request\RequestInterface'                => 'EventEspresso\core\services\request\Request',
861
-            'EventEspresso\core\services\request\ResponseInterface'               => 'EventEspresso\core\services\request\Response',
862
-            'EventEspresso\core\domain\DomainInterface'                           => 'EventEspresso\core\domain\Domain',
863
-        );
864
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
865
-            $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices';
866
-        }
867
-    }
868
-
869
-
870
-
871
-    /**
872
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
873
-     * request Primarily used by unit tests.
874
-     *
875
-     * @throws InvalidDataTypeException
876
-     * @throws InvalidInterfaceException
877
-     * @throws InvalidArgumentException
878
-     */
879
-    public function reset()
880
-    {
881
-        $this->_register_core_class_loaders();
882
-        $this->_register_core_dependencies();
883
-    }
28
+	/**
29
+	 * This means that the requested class dependency is not present in the dependency map
30
+	 */
31
+	const not_registered = 0;
32
+
33
+	/**
34
+	 * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
35
+	 */
36
+	const load_new_object = 1;
37
+
38
+	/**
39
+	 * This instructs class loaders to return a previously instantiated and cached object for the requested class.
40
+	 * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
41
+	 */
42
+	const load_from_cache = 2;
43
+
44
+	/**
45
+	 * When registering a dependency,
46
+	 * this indicates to keep any existing dependencies that already exist,
47
+	 * and simply discard any new dependencies declared in the incoming data
48
+	 */
49
+	const KEEP_EXISTING_DEPENDENCIES = 0;
50
+
51
+	/**
52
+	 * When registering a dependency,
53
+	 * this indicates to overwrite any existing dependencies that already exist using the incoming data
54
+	 */
55
+	const OVERWRITE_DEPENDENCIES = 1;
56
+
57
+
58
+
59
+	/**
60
+	 * @type EE_Dependency_Map $_instance
61
+	 */
62
+	protected static $_instance;
63
+
64
+	/**
65
+	 * @type RequestInterface $request
66
+	 */
67
+	protected $request;
68
+
69
+	/**
70
+	 * @type LegacyRequestInterface $legacy_request
71
+	 */
72
+	protected $legacy_request;
73
+
74
+	/**
75
+	 * @type ResponseInterface $response
76
+	 */
77
+	protected $response;
78
+
79
+	/**
80
+	 * @type LoaderInterface $loader
81
+	 */
82
+	protected $loader;
83
+
84
+	/**
85
+	 * @type array $_dependency_map
86
+	 */
87
+	protected $_dependency_map = array();
88
+
89
+	/**
90
+	 * @type array $_class_loaders
91
+	 */
92
+	protected $_class_loaders = array();
93
+
94
+	/**
95
+	 * @type array $_aliases
96
+	 */
97
+	protected $_aliases = array();
98
+
99
+
100
+
101
+	/**
102
+	 * EE_Dependency_Map constructor.
103
+	 */
104
+	protected function __construct()
105
+	{
106
+		// add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
107
+		do_action('EE_Dependency_Map____construct');
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * @throws InvalidDataTypeException
114
+	 * @throws InvalidInterfaceException
115
+	 * @throws InvalidArgumentException
116
+	 */
117
+	public function initialize()
118
+	{
119
+		$this->_register_core_dependencies();
120
+		$this->_register_core_class_loaders();
121
+		$this->_register_core_aliases();
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * @singleton method used to instantiate class object
128
+	 * @return EE_Dependency_Map
129
+	 */
130
+	public static function instance() {
131
+		// check if class object is instantiated, and instantiated properly
132
+		if (! self::$_instance instanceof EE_Dependency_Map) {
133
+			self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/);
134
+		}
135
+		return self::$_instance;
136
+	}
137
+
138
+
139
+	/**
140
+	 * @param RequestInterface $request
141
+	 */
142
+	public function setRequest(RequestInterface $request)
143
+	{
144
+		$this->request = $request;
145
+	}
146
+
147
+
148
+	/**
149
+	 * @param LegacyRequestInterface $legacy_request
150
+	 */
151
+	public function setLegacyRequest(LegacyRequestInterface $legacy_request)
152
+	{
153
+		$this->legacy_request = $legacy_request;
154
+	}
155
+
156
+
157
+	/**
158
+	 * @param ResponseInterface $response
159
+	 */
160
+	public function setResponse(ResponseInterface $response)
161
+	{
162
+		$this->response = $response;
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * @param LoaderInterface $loader
169
+	 */
170
+	public function setLoader(LoaderInterface $loader)
171
+	{
172
+		$this->loader = $loader;
173
+	}
174
+
175
+
176
+
177
+	/**
178
+	 * @param string $class
179
+	 * @param array  $dependencies
180
+	 * @param int    $overwrite
181
+	 * @return bool
182
+	 */
183
+	public static function register_dependencies(
184
+		$class,
185
+		array $dependencies,
186
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
187
+	) {
188
+		return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
189
+	}
190
+
191
+
192
+
193
+	/**
194
+	 * Assigns an array of class names and corresponding load sources (new or cached)
195
+	 * to the class specified by the first parameter.
196
+	 * IMPORTANT !!!
197
+	 * The order of elements in the incoming $dependencies array MUST match
198
+	 * the order of the constructor parameters for the class in question.
199
+	 * This is especially important when overriding any existing dependencies that are registered.
200
+	 * the third parameter controls whether any duplicate dependencies are overwritten or not.
201
+	 *
202
+	 * @param string $class
203
+	 * @param array  $dependencies
204
+	 * @param int    $overwrite
205
+	 * @return bool
206
+	 */
207
+	public function registerDependencies(
208
+		$class,
209
+		array $dependencies,
210
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
211
+	) {
212
+		$class = trim($class, '\\');
213
+		$registered = false;
214
+		if (empty(self::$_instance->_dependency_map[ $class ])) {
215
+			self::$_instance->_dependency_map[ $class ] = array();
216
+		}
217
+		// we need to make sure that any aliases used when registering a dependency
218
+		// get resolved to the correct class name
219
+		foreach ($dependencies as $dependency => $load_source) {
220
+			$alias = self::$_instance->get_alias($dependency);
221
+			if (
222
+				$overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
223
+				|| ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
224
+			) {
225
+				unset($dependencies[$dependency]);
226
+				$dependencies[$alias] = $load_source;
227
+				$registered = true;
228
+			}
229
+		}
230
+		// now add our two lists of dependencies together.
231
+		// using Union (+=) favours the arrays in precedence from left to right,
232
+		// so $dependencies is NOT overwritten because it is listed first
233
+		// ie: with A = B + C, entries in B take precedence over duplicate entries in C
234
+		// Union is way faster than array_merge() but should be used with caution...
235
+		// especially with numerically indexed arrays
236
+		$dependencies += self::$_instance->_dependency_map[ $class ];
237
+		// now we need to ensure that the resulting dependencies
238
+		// array only has the entries that are required for the class
239
+		// so first count how many dependencies were originally registered for the class
240
+		$dependency_count = count(self::$_instance->_dependency_map[ $class ]);
241
+		// if that count is non-zero (meaning dependencies were already registered)
242
+		self::$_instance->_dependency_map[ $class ] = $dependency_count
243
+			// then truncate the  final array to match that count
244
+			? array_slice($dependencies, 0, $dependency_count)
245
+			// otherwise just take the incoming array because nothing previously existed
246
+			: $dependencies;
247
+		return $registered;
248
+	}
249
+
250
+
251
+
252
+	/**
253
+	 * @param string $class_name
254
+	 * @param string $loader
255
+	 * @return bool
256
+	 * @throws DomainException
257
+	 */
258
+	public static function register_class_loader($class_name, $loader = 'load_core')
259
+	{
260
+		if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
261
+			throw new DomainException(
262
+				esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
263
+			);
264
+		}
265
+		// check that loader is callable or method starts with "load_" and exists in EE_Registry
266
+		if (
267
+			! is_callable($loader)
268
+			&& (
269
+				strpos($loader, 'load_') !== 0
270
+				|| ! method_exists('EE_Registry', $loader)
271
+			)
272
+		) {
273
+			throw new DomainException(
274
+				sprintf(
275
+					esc_html__(
276
+						'"%1$s" is not a valid loader method on EE_Registry.',
277
+						'event_espresso'
278
+					),
279
+					$loader
280
+				)
281
+			);
282
+		}
283
+		$class_name = self::$_instance->get_alias($class_name);
284
+		if (! isset(self::$_instance->_class_loaders[$class_name])) {
285
+			self::$_instance->_class_loaders[$class_name] = $loader;
286
+			return true;
287
+		}
288
+		return false;
289
+	}
290
+
291
+
292
+
293
+	/**
294
+	 * @return array
295
+	 */
296
+	public function dependency_map()
297
+	{
298
+		return $this->_dependency_map;
299
+	}
300
+
301
+
302
+
303
+	/**
304
+	 * returns TRUE if dependency map contains a listing for the provided class name
305
+	 *
306
+	 * @param string $class_name
307
+	 * @return boolean
308
+	 */
309
+	public function has($class_name = '')
310
+	{
311
+		// all legacy models have the same dependencies
312
+		if (strpos($class_name, 'EEM_') === 0) {
313
+			$class_name = 'LEGACY_MODELS';
314
+		}
315
+		return isset($this->_dependency_map[$class_name]) ? true : false;
316
+	}
317
+
318
+
319
+
320
+	/**
321
+	 * returns TRUE if dependency map contains a listing for the provided class name AND dependency
322
+	 *
323
+	 * @param string $class_name
324
+	 * @param string $dependency
325
+	 * @return bool
326
+	 */
327
+	public function has_dependency_for_class($class_name = '', $dependency = '')
328
+	{
329
+		// all legacy models have the same dependencies
330
+		if (strpos($class_name, 'EEM_') === 0) {
331
+			$class_name = 'LEGACY_MODELS';
332
+		}
333
+		$dependency = $this->get_alias($dependency);
334
+		return isset($this->_dependency_map[$class_name][$dependency])
335
+			? true
336
+			: false;
337
+	}
338
+
339
+
340
+
341
+	/**
342
+	 * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
343
+	 *
344
+	 * @param string $class_name
345
+	 * @param string $dependency
346
+	 * @return int
347
+	 */
348
+	public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
349
+	{
350
+		// all legacy models have the same dependencies
351
+		if (strpos($class_name, 'EEM_') === 0) {
352
+			$class_name = 'LEGACY_MODELS';
353
+		}
354
+		$dependency = $this->get_alias($dependency);
355
+		return $this->has_dependency_for_class($class_name, $dependency)
356
+			? $this->_dependency_map[$class_name][$dependency]
357
+			: EE_Dependency_Map::not_registered;
358
+	}
359
+
360
+
361
+
362
+	/**
363
+	 * @param string $class_name
364
+	 * @return string | Closure
365
+	 */
366
+	public function class_loader($class_name)
367
+	{
368
+		// all legacy models use load_model()
369
+		if(strpos($class_name, 'EEM_') === 0){
370
+			return 'load_model';
371
+		}
372
+		$class_name = $this->get_alias($class_name);
373
+		return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
374
+	}
375
+
376
+
377
+
378
+	/**
379
+	 * @return array
380
+	 */
381
+	public function class_loaders()
382
+	{
383
+		return $this->_class_loaders;
384
+	}
385
+
386
+
387
+
388
+	/**
389
+	 * adds an alias for a classname
390
+	 *
391
+	 * @param string $class_name the class name that should be used (concrete class to replace interface)
392
+	 * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
393
+	 * @param string $for_class  the class that has the dependency (is type hinting for the interface)
394
+	 */
395
+	public function add_alias($class_name, $alias, $for_class = '')
396
+	{
397
+		if ($for_class !== '') {
398
+			if (! isset($this->_aliases[$for_class])) {
399
+				$this->_aliases[$for_class] = array();
400
+			}
401
+			$this->_aliases[$for_class][$class_name] = $alias;
402
+		}
403
+		$this->_aliases[$class_name] = $alias;
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * returns TRUE if the provided class name has an alias
410
+	 *
411
+	 * @param string $class_name
412
+	 * @param string $for_class
413
+	 * @return bool
414
+	 */
415
+	public function has_alias($class_name = '', $for_class = '')
416
+	{
417
+		return isset($this->_aliases[$for_class][$class_name])
418
+			   || (
419
+				   isset($this->_aliases[$class_name])
420
+				   && ! is_array($this->_aliases[$class_name])
421
+			   );
422
+	}
423
+
424
+
425
+
426
+	/**
427
+	 * returns alias for class name if one exists, otherwise returns the original classname
428
+	 * functions recursively, so that multiple aliases can be used to drill down to a classname
429
+	 *  for example:
430
+	 *      if the following two entries were added to the _aliases array:
431
+	 *          array(
432
+	 *              'interface_alias'           => 'some\namespace\interface'
433
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
434
+	 *          )
435
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
436
+	 *      to load an instance of 'some\namespace\classname'
437
+	 *
438
+	 * @param string $class_name
439
+	 * @param string $for_class
440
+	 * @return string
441
+	 */
442
+	public function get_alias($class_name = '', $for_class = '')
443
+	{
444
+		if (! $this->has_alias($class_name, $for_class)) {
445
+			return $class_name;
446
+		}
447
+		if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
448
+			return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
449
+		}
450
+		return $this->get_alias($this->_aliases[$class_name]);
451
+	}
452
+
453
+
454
+
455
+	/**
456
+	 * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
457
+	 * if one exists, or whether a new object should be generated every time the requested class is loaded.
458
+	 * This is done by using the following class constants:
459
+	 *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
460
+	 *        EE_Dependency_Map::load_new_object - generates a new object every time
461
+	 */
462
+	protected function _register_core_dependencies()
463
+	{
464
+		$this->_dependency_map = array(
465
+			'EE_Request_Handler'                                                                                          => array(
466
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
467
+			),
468
+			'EE_System'                                                                                                   => array(
469
+				'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
470
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
471
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
472
+				'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
473
+			),
474
+			'EE_Session'                                                                                                  => array(
475
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
476
+				'EventEspresso\core\services\request\Request'             => EE_Dependency_Map::load_from_cache,
477
+				'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
478
+			),
479
+			'EE_Cart'                                                                                                     => array(
480
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
481
+			),
482
+			'EE_Front_Controller'                                                                                         => array(
483
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
484
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
485
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
486
+			),
487
+			'EE_Messenger_Collection_Loader'                                                                              => array(
488
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
489
+			),
490
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
491
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
492
+			),
493
+			'EE_Message_Resource_Manager'                                                                                 => array(
494
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
495
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
496
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
497
+			),
498
+			'EE_Message_Factory'                                                                                          => array(
499
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
500
+			),
501
+			'EE_messages'                                                                                                 => array(
502
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
503
+			),
504
+			'EE_Messages_Generator'                                                                                       => array(
505
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
506
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
507
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
508
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
509
+			),
510
+			'EE_Messages_Processor'                                                                                       => array(
511
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
512
+			),
513
+			'EE_Messages_Queue'                                                                                           => array(
514
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
515
+			),
516
+			'EE_Messages_Template_Defaults'                                                                               => array(
517
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
518
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
519
+			),
520
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
521
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
522
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
523
+			),
524
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
525
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
526
+			),
527
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
528
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
529
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
530
+			),
531
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
532
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
533
+			),
534
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
535
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
536
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
537
+			),
538
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
539
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
540
+			),
541
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
542
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
543
+			),
544
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
545
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
546
+			),
547
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
548
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
549
+			),
550
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
551
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
552
+			),
553
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
554
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
555
+			),
556
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
557
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
558
+			),
559
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
560
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
561
+			),
562
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
563
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
564
+			),
565
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
566
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
567
+			),
568
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
569
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
570
+			),
571
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
572
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
573
+			),
574
+			'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
575
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
576
+			),
577
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
578
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
579
+			),
580
+			'EE_Data_Migration_Class_Base'                                                                                => array(
581
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
582
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
583
+			),
584
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
585
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
586
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
587
+			),
588
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
589
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
590
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
591
+			),
592
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
593
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
594
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
595
+			),
596
+			'EE_DMS_Core_4_4_0'                                                                                           => array(
597
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
598
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
599
+			),
600
+			'EE_DMS_Core_4_5_0'                                                                                           => array(
601
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
602
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
603
+			),
604
+			'EE_DMS_Core_4_6_0'                                                                                           => array(
605
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
606
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
607
+			),
608
+			'EE_DMS_Core_4_7_0'                                                                                           => array(
609
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
610
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
611
+			),
612
+			'EE_DMS_Core_4_8_0'                                                                                           => array(
613
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
614
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
615
+			),
616
+			'EE_DMS_Core_4_9_0'                                                                                           => array(
617
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
618
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
619
+			),
620
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
621
+				'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
622
+				'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
623
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
624
+			),
625
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
626
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
627
+			),
628
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
629
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
630
+			),
631
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
632
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
633
+			),
634
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
635
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
636
+			),
637
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
638
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
639
+			),
640
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
641
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
642
+			),
643
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
644
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
645
+			),
646
+			'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
647
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
648
+			),
649
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'                  => array(
650
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
651
+			),
652
+			'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
653
+				'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
654
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
655
+			),
656
+			'EventEspresso\core\domain\values\EmailAddress'                              => array(
657
+				null,
658
+				'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
659
+			),
660
+			'EventEspresso\core\services\orm\ModelFieldFactory' => array(
661
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
662
+			),
663
+			'LEGACY_MODELS'                                                   => array(
664
+				null,
665
+				'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
666
+			),
667
+			'EE_Module_Request_Router'                                               => array(
668
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
669
+			),
670
+			'EE_Registration_Processor'                                              => array(
671
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
672
+			),
673
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array(
674
+				null,
675
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
676
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
677
+			),
678
+			'EventEspresso\core\services\editor\EditorBlockRegistrationManager'      => array(
679
+				'EventEspresso\core\domain\entities\editor\EditorBlockCollection' => EE_Dependency_Map::load_from_cache,
680
+				'EE_Request'                                                      => EE_Dependency_Map::load_from_cache,
681
+				'EventEspresso\core\domain\Domain'                                => EE_Dependency_Map::load_from_cache,
682
+			),
683
+			'EventEspresso\core\services\editor\EspressoGutenbergEditor' => array(
684
+				'EventEspresso\core\domain\entities\editor\EditorBlockCollection' => EE_Dependency_Map::load_from_cache,
685
+				'EE_Request'                                                      => EE_Dependency_Map::load_from_cache,
686
+				'EventEspresso\core\domain\Domain'                                => EE_Dependency_Map::load_from_cache,
687
+			),
688
+			'EventEspresso\core\domain\entities\editor\blocks\shortcodes\EventsList'     => array(
689
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
690
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
691
+			),
692
+			'EventEspresso\core\domain\entities\editor\blocks\TicketSelector'                   => array(
693
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
694
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
695
+			),
696
+			'EventEspresso\core\domain\entities\editor\blocks\VenueEditor'                      => array(
697
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
698
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
699
+			),
700
+			'EventEspresso\core\domain\entities\editor\blocks\common\NextUpcomingEventDatetime' => array(
701
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
702
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
703
+			),
704
+		);
705
+	}
706
+
707
+
708
+
709
+	/**
710
+	 * Registers how core classes are loaded.
711
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
712
+	 *        'EE_Request_Handler' => 'load_core'
713
+	 *        'EE_Messages_Queue'  => 'load_lib'
714
+	 *        'EEH_Debug_Tools'    => 'load_helper'
715
+	 * or, if greater control is required, by providing a custom closure. For example:
716
+	 *        'Some_Class' => function () {
717
+	 *            return new Some_Class();
718
+	 *        },
719
+	 * This is required for instantiating dependencies
720
+	 * where an interface has been type hinted in a class constructor. For example:
721
+	 *        'Required_Interface' => function () {
722
+	 *            return new A_Class_That_Implements_Required_Interface();
723
+	 *        },
724
+	 *
725
+	 * @throws InvalidInterfaceException
726
+	 * @throws InvalidDataTypeException
727
+	 * @throws InvalidArgumentException
728
+	 */
729
+	protected function _register_core_class_loaders()
730
+	{
731
+		//for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
732
+		//be used in a closure.
733
+		$request = &$this->request;
734
+		$response = &$this->response;
735
+		$legacy_request = &$this->legacy_request;
736
+		// $loader = &$this->loader;
737
+		$this->_class_loaders = array(
738
+			//load_core
739
+			'EE_Capabilities'          => 'load_core',
740
+			'EE_Encryption'            => 'load_core',
741
+			'EE_Front_Controller'      => 'load_core',
742
+			'EE_Module_Request_Router' => 'load_core',
743
+			'EE_Registry'              => 'load_core',
744
+			'EE_Request'               => function () use (&$legacy_request) {
745
+				return $legacy_request;
746
+			},
747
+			'EventEspresso\core\services\request\Request' => function () use (&$request) {
748
+				return $request;
749
+			},
750
+			'EventEspresso\core\services\request\Response' => function () use (&$response) {
751
+				return $response;
752
+			},
753
+			'EE_Request_Handler'       => 'load_core',
754
+			'EE_Session'               => 'load_core',
755
+			'EE_Cron_Tasks'            => 'load_core',
756
+			'EE_System'                => 'load_core',
757
+			'EE_Maintenance_Mode'      => 'load_core',
758
+			'EE_Register_CPTs'         => 'load_core',
759
+			'EE_Admin'                 => 'load_core',
760
+			//load_lib
761
+			'EE_Message_Resource_Manager'          => 'load_lib',
762
+			'EE_Message_Type_Collection'           => 'load_lib',
763
+			'EE_Message_Type_Collection_Loader'    => 'load_lib',
764
+			'EE_Messenger_Collection'              => 'load_lib',
765
+			'EE_Messenger_Collection_Loader'       => 'load_lib',
766
+			'EE_Messages_Processor'                => 'load_lib',
767
+			'EE_Message_Repository'                => 'load_lib',
768
+			'EE_Messages_Queue'                    => 'load_lib',
769
+			'EE_Messages_Data_Handler_Collection'  => 'load_lib',
770
+			'EE_Message_Template_Group_Collection' => 'load_lib',
771
+			'EE_Payment_Method_Manager'            => 'load_lib',
772
+			'EE_Messages_Generator'                => function () {
773
+				return EE_Registry::instance()->load_lib(
774
+					'Messages_Generator',
775
+					array(),
776
+					false,
777
+					false
778
+				);
779
+			},
780
+			'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
781
+				return EE_Registry::instance()->load_lib(
782
+					'Messages_Template_Defaults',
783
+					$arguments,
784
+					false,
785
+					false
786
+				);
787
+			},
788
+			//load_model
789
+			// 'EEM_Attendee'                         => 'load_model',
790
+			// 'EEM_Message_Template_Group'           => 'load_model',
791
+			// 'EEM_Message_Template'                 => 'load_model',
792
+			//load_helper
793
+			'EEH_Parse_Shortcodes'                 => function () {
794
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
795
+					return new EEH_Parse_Shortcodes();
796
+				}
797
+				return null;
798
+			},
799
+			'EE_Template_Config'                   => function () {
800
+				return EE_Config::instance()->template_settings;
801
+			},
802
+			'EE_Currency_Config'                   => function () {
803
+				return EE_Config::instance()->currency;
804
+			},
805
+			'EE_Registration_Config'                   => function () {
806
+				return EE_Config::instance()->registration;
807
+			},
808
+			'EventEspresso\core\services\loaders\Loader' => function () {
809
+				return LoaderFactory::getLoader();
810
+			},
811
+		);
812
+	}
813
+
814
+
815
+
816
+	/**
817
+	 * can be used for supplying alternate names for classes,
818
+	 * or for connecting interface names to instantiable classes
819
+	 */
820
+	protected function _register_core_aliases()
821
+	{
822
+		$this->_aliases = array(
823
+			'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
824
+			'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
825
+			'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
826
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
827
+			'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
828
+			'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
829
+			'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
830
+			'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
831
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
832
+			'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
833
+			'CreateRegCodeCommandHandler'                                                  => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
834
+			'CreateRegUrlLinkCommandHandler'                                               => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
835
+			'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
836
+			'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
837
+			'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
838
+			'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
839
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
840
+			'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
841
+			'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
842
+			'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
843
+			'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
844
+			'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
845
+			'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
846
+			'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
847
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
848
+			'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
849
+			'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
850
+			'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
851
+			'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
852
+			'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
853
+			'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
854
+			'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
855
+			'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
856
+			'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
857
+			'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
858
+			'NoticesContainerInterface'                                           => 'EventEspresso\core\services\notices\NoticesContainerInterface',
859
+			'EventEspresso\core\services\notices\NoticesContainerInterface'       => 'EventEspresso\core\services\notices\NoticesContainer',
860
+			'EventEspresso\core\services\request\RequestInterface'                => 'EventEspresso\core\services\request\Request',
861
+			'EventEspresso\core\services\request\ResponseInterface'               => 'EventEspresso\core\services\request\Response',
862
+			'EventEspresso\core\domain\DomainInterface'                           => 'EventEspresso\core\domain\Domain',
863
+		);
864
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
865
+			$this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices';
866
+		}
867
+	}
868
+
869
+
870
+
871
+	/**
872
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
873
+	 * request Primarily used by unit tests.
874
+	 *
875
+	 * @throws InvalidDataTypeException
876
+	 * @throws InvalidInterfaceException
877
+	 * @throws InvalidArgumentException
878
+	 */
879
+	public function reset()
880
+	{
881
+		$this->_register_core_class_loaders();
882
+		$this->_register_core_dependencies();
883
+	}
884 884
 
885 885
 
886 886
 }
Please login to merge, or discard this patch.
core/EE_System.core.php 1 patch
Indentation   +1276 added lines, -1276 removed lines patch added patch discarded remove patch
@@ -24,1282 +24,1282 @@
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
29
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
30
-     */
31
-    const req_type_normal = 0;
32
-
33
-    /**
34
-     * Indicates this is a brand new installation of EE so we should install
35
-     * tables and default data etc
36
-     */
37
-    const req_type_new_activation = 1;
38
-
39
-    /**
40
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
41
-     * and we just exited maintenance mode). We MUST check the database is setup properly
42
-     * and that default data is setup too
43
-     */
44
-    const req_type_reactivation = 2;
45
-
46
-    /**
47
-     * indicates that EE has been upgraded since its previous request.
48
-     * We may have data migration scripts to call and will want to trigger maintenance mode
49
-     */
50
-    const req_type_upgrade = 3;
51
-
52
-    /**
53
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
54
-     */
55
-    const req_type_downgrade = 4;
56
-
57
-    /**
58
-     * @deprecated since version 4.6.0.dev.006
59
-     * Now whenever a new_activation is detected the request type is still just
60
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
61
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
62
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
63
-     * (Specifically, when the migration manager indicates migrations are finished
64
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
65
-     */
66
-    const req_type_activation_but_not_installed = 5;
67
-
68
-    /**
69
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
70
-     */
71
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
72
-
73
-
74
-    /**
75
-     * @var EE_System $_instance
76
-     */
77
-    private static $_instance;
78
-
79
-    /**
80
-     * @var EE_Registry $registry
81
-     */
82
-    private $registry;
83
-
84
-    /**
85
-     * @var LoaderInterface $loader
86
-     */
87
-    private $loader;
88
-
89
-    /**
90
-     * @var EE_Capabilities $capabilities
91
-     */
92
-    private $capabilities;
93
-
94
-    /**
95
-     * @var RequestInterface $request
96
-     */
97
-    private $request;
98
-
99
-    /**
100
-     * @var EE_Maintenance_Mode $maintenance_mode
101
-     */
102
-    private $maintenance_mode;
103
-
104
-    /**
105
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
106
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
107
-     *
108
-     * @var int $_req_type
109
-     */
110
-    private $_req_type;
111
-
112
-    /**
113
-     * Whether or not there was a non-micro version change in EE core version during this request
114
-     *
115
-     * @var boolean $_major_version_change
116
-     */
117
-    private $_major_version_change = false;
118
-
119
-    /**
120
-     * A Context DTO dedicated solely to identifying the current request type.
121
-     *
122
-     * @var RequestTypeContextCheckerInterface $request_type
123
-     */
124
-    private $request_type;
125
-
126
-
127
-
128
-    /**
129
-     * @singleton method used to instantiate class object
130
-     * @param EE_Registry|null         $registry
131
-     * @param LoaderInterface|null     $loader
132
-     * @param RequestInterface|null          $request
133
-     * @param EE_Maintenance_Mode|null $maintenance_mode
134
-     * @return EE_System
135
-     */
136
-    public static function instance(
137
-        EE_Registry $registry = null,
138
-        LoaderInterface $loader = null,
139
-        RequestInterface $request = null,
140
-        EE_Maintenance_Mode $maintenance_mode = null
141
-    ) {
142
-        // check if class object is instantiated
143
-        if (! self::$_instance instanceof EE_System) {
144
-            self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
145
-        }
146
-        return self::$_instance;
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * resets the instance and returns it
153
-     *
154
-     * @return EE_System
155
-     */
156
-    public static function reset()
157
-    {
158
-        self::$_instance->_req_type = null;
159
-        //make sure none of the old hooks are left hanging around
160
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
161
-        //we need to reset the migration manager in order for it to detect DMSs properly
162
-        EE_Data_Migration_Manager::reset();
163
-        self::instance()->detect_activations_or_upgrades();
164
-        self::instance()->perform_activations_upgrades_and_migrations();
165
-        return self::instance();
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     * sets hooks for running rest of system
172
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
173
-     * starting EE Addons from any other point may lead to problems
174
-     *
175
-     * @param EE_Registry         $registry
176
-     * @param LoaderInterface     $loader
177
-     * @param RequestInterface          $request
178
-     * @param EE_Maintenance_Mode $maintenance_mode
179
-     */
180
-    private function __construct(
181
-        EE_Registry $registry,
182
-        LoaderInterface $loader,
183
-        RequestInterface $request,
184
-        EE_Maintenance_Mode $maintenance_mode
185
-    ) {
186
-        $this->registry         = $registry;
187
-        $this->loader           = $loader;
188
-        $this->request          = $request;
189
-        $this->maintenance_mode = $maintenance_mode;
190
-        do_action('AHEE__EE_System__construct__begin', $this);
191
-        add_action(
192
-            'AHEE__EE_Bootstrap__load_espresso_addons',
193
-            array($this, 'loadCapabilities'),
194
-            5
195
-        );
196
-        add_action(
197
-            'AHEE__EE_Bootstrap__load_espresso_addons',
198
-            array($this, 'loadCommandBus'),
199
-            7
200
-        );
201
-        add_action(
202
-            'AHEE__EE_Bootstrap__load_espresso_addons',
203
-            array($this, 'loadPluginApi'),
204
-            9
205
-        );
206
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
207
-        add_action(
208
-            'AHEE__EE_Bootstrap__load_espresso_addons',
209
-            array($this, 'load_espresso_addons')
210
-        );
211
-        // when an ee addon is activated, we want to call the core hook(s) again
212
-        // because the newly-activated addon didn't get a chance to run at all
213
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
214
-        // detect whether install or upgrade
215
-        add_action(
216
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
217
-            array($this, 'detect_activations_or_upgrades'),
218
-            3
219
-        );
220
-        // load EE_Config, EE_Textdomain, etc
221
-        add_action(
222
-            'AHEE__EE_Bootstrap__load_core_configuration',
223
-            array($this, 'load_core_configuration'),
224
-            5
225
-        );
226
-        // load EE_Config, EE_Textdomain, etc
227
-        add_action(
228
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
229
-            array($this, 'register_shortcodes_modules_and_widgets'),
230
-            7
231
-        );
232
-        // you wanna get going? I wanna get going... let's get going!
233
-        add_action(
234
-            'AHEE__EE_Bootstrap__brew_espresso',
235
-            array($this, 'brew_espresso'),
236
-            9
237
-        );
238
-        //other housekeeping
239
-        //exclude EE critical pages from wp_list_pages
240
-        add_filter(
241
-            'wp_list_pages_excludes',
242
-            array($this, 'remove_pages_from_wp_list_pages'),
243
-            10
244
-        );
245
-        // ALL EE Addons should use the following hook point to attach their initial setup too
246
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
247
-        do_action('AHEE__EE_System__construct__complete', $this);
248
-    }
249
-
250
-
251
-    /**
252
-     * load and setup EE_Capabilities
253
-     *
254
-     * @return void
255
-     * @throws EE_Error
256
-     */
257
-    public function loadCapabilities()
258
-    {
259
-        $this->capabilities = $this->loader->getShared('EE_Capabilities');
260
-        add_action(
261
-            'AHEE__EE_Capabilities__init_caps__before_initialization',
262
-            function ()
263
-            {
264
-                LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
265
-            }
266
-        );
267
-    }
268
-
269
-
270
-
271
-    /**
272
-     * create and cache the CommandBus, and also add middleware
273
-     * The CapChecker middleware requires the use of EE_Capabilities
274
-     * which is why we need to load the CommandBus after Caps are set up
275
-     *
276
-     * @return void
277
-     * @throws EE_Error
278
-     */
279
-    public function loadCommandBus()
280
-    {
281
-        $this->loader->getShared(
282
-            'CommandBusInterface',
283
-            array(
284
-                null,
285
-                apply_filters(
286
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
287
-                    array(
288
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
289
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
290
-                    )
291
-                ),
292
-            )
293
-        );
294
-    }
295
-
296
-
297
-
298
-    /**
299
-     * @return void
300
-     * @throws EE_Error
301
-     */
302
-    public function loadPluginApi()
303
-    {
304
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
305
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
306
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
307
-        $this->loader->getShared('EE_Request_Handler');
308
-    }
309
-
310
-
311
-    /**
312
-     * @param string $addon_name
313
-     * @param string $version_constant
314
-     * @param string $min_version_required
315
-     * @param string $load_callback
316
-     * @param string $plugin_file_constant
317
-     * @return void
318
-     */
319
-    private function deactivateIncompatibleAddon(
320
-        $addon_name,
321
-        $version_constant,
322
-        $min_version_required,
323
-        $load_callback,
324
-        $plugin_file_constant
325
-    ) {
326
-        if (! defined($version_constant)) {
327
-            return;
328
-        }
329
-        $addon_version = constant($version_constant);
330
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
331
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
332
-            if (! function_exists('deactivate_plugins')) {
333
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
334
-            }
335
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
336
-            unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
337
-            EE_Error::add_error(
338
-                sprintf(
339
-                    esc_html__(
340
-                        'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
341
-                        'event_espresso'
342
-                    ),
343
-                    $addon_name,
344
-                    $min_version_required
345
-                ),
346
-                __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
347
-            );
348
-            EE_Error::get_notices(false, true);
349
-        }
350
-    }
351
-
352
-
353
-    /**
354
-     * load_espresso_addons
355
-     * allow addons to load first so that they can set hooks for running DMS's, etc
356
-     * this is hooked into both:
357
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
358
-     *        which runs during the WP 'plugins_loaded' action at priority 5
359
-     *    and the WP 'activate_plugin' hook point
360
-     *
361
-     * @access public
362
-     * @return void
363
-     */
364
-    public function load_espresso_addons()
365
-    {
366
-        $this->deactivateIncompatibleAddon(
367
-            'Wait Lists',
368
-            'EE_WAIT_LISTS_VERSION',
369
-            '1.0.0.beta.074',
370
-            'load_espresso_wait_lists',
371
-            'EE_WAIT_LISTS_PLUGIN_FILE'
372
-        );
373
-        $this->deactivateIncompatibleAddon(
374
-            'Automated Upcoming Event Notifications',
375
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
376
-            '1.0.0.beta.091',
377
-            'load_espresso_automated_upcoming_event_notification',
378
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
379
-        );
380
-        do_action('AHEE__EE_System__load_espresso_addons');
381
-        //if the WP API basic auth plugin isn't already loaded, load it now.
382
-        //We want it for mobile apps. Just include the entire plugin
383
-        //also, don't load the basic auth when a plugin is getting activated, because
384
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
385
-        //and causes a fatal error
386
-        if (
387
-            $this->request->getRequestParam('activate') !== 'true'
388
-            && ! function_exists('json_basic_auth_handler')
389
-            && ! function_exists('json_basic_auth_error')
390
-            && ! in_array(
391
-                $this->request->getRequestParam('action'),
392
-                array('activate', 'activate-selected'),
393
-                true
394
-            )
395
-        ) {
396
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
397
-        }
398
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
399
-    }
400
-
401
-
402
-
403
-    /**
404
-     * detect_activations_or_upgrades
405
-     * Checks for activation or upgrade of core first;
406
-     * then also checks if any registered addons have been activated or upgraded
407
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
408
-     * which runs during the WP 'plugins_loaded' action at priority 3
409
-     *
410
-     * @access public
411
-     * @return void
412
-     */
413
-    public function detect_activations_or_upgrades()
414
-    {
415
-        //first off: let's make sure to handle core
416
-        $this->detect_if_activation_or_upgrade();
417
-        foreach ($this->registry->addons as $addon) {
418
-            if ($addon instanceof EE_Addon) {
419
-                //detect teh request type for that addon
420
-                $addon->detect_activation_or_upgrade();
421
-            }
422
-        }
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     * detect_if_activation_or_upgrade
429
-     * Takes care of detecting whether this is a brand new install or code upgrade,
430
-     * and either setting up the DB or setting up maintenance mode etc.
431
-     *
432
-     * @access public
433
-     * @return void
434
-     */
435
-    public function detect_if_activation_or_upgrade()
436
-    {
437
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
438
-        // check if db has been updated, or if its a brand-new installation
439
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
440
-        $request_type       = $this->detect_req_type($espresso_db_update);
441
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
442
-        switch ($request_type) {
443
-            case EE_System::req_type_new_activation:
444
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
445
-                $this->_handle_core_version_change($espresso_db_update);
446
-                break;
447
-            case EE_System::req_type_reactivation:
448
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
449
-                $this->_handle_core_version_change($espresso_db_update);
450
-                break;
451
-            case EE_System::req_type_upgrade:
452
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
453
-                //migrations may be required now that we've upgraded
454
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
455
-                $this->_handle_core_version_change($espresso_db_update);
456
-                //				echo "done upgrade";die;
457
-                break;
458
-            case EE_System::req_type_downgrade:
459
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
460
-                //its possible migrations are no longer required
461
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
462
-                $this->_handle_core_version_change($espresso_db_update);
463
-                break;
464
-            case EE_System::req_type_normal:
465
-            default:
466
-                break;
467
-        }
468
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
469
-    }
470
-
471
-
472
-
473
-    /**
474
-     * Updates the list of installed versions and sets hooks for
475
-     * initializing the database later during the request
476
-     *
477
-     * @param array $espresso_db_update
478
-     */
479
-    private function _handle_core_version_change($espresso_db_update)
480
-    {
481
-        $this->update_list_of_installed_versions($espresso_db_update);
482
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
483
-        add_action(
484
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
485
-            array($this, 'initialize_db_if_no_migrations_required')
486
-        );
487
-    }
488
-
489
-
490
-
491
-    /**
492
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
493
-     * information about what versions of EE have been installed and activated,
494
-     * NOT necessarily the state of the database
495
-     *
496
-     * @param mixed $espresso_db_update           the value of the WordPress option.
497
-     *                                            If not supplied, fetches it from the options table
498
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
499
-     */
500
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
501
-    {
502
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
503
-        if (! $espresso_db_update) {
504
-            $espresso_db_update = get_option('espresso_db_update');
505
-        }
506
-        // check that option is an array
507
-        if (! is_array($espresso_db_update)) {
508
-            // if option is FALSE, then it never existed
509
-            if ($espresso_db_update === false) {
510
-                // make $espresso_db_update an array and save option with autoload OFF
511
-                $espresso_db_update = array();
512
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
513
-            } else {
514
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
515
-                $espresso_db_update = array($espresso_db_update => array());
516
-                update_option('espresso_db_update', $espresso_db_update);
517
-            }
518
-        } else {
519
-            $corrected_db_update = array();
520
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
521
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
522
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
523
-                    //the key is an int, and the value IS NOT an array
524
-                    //so it must be numerically-indexed, where values are versions installed...
525
-                    //fix it!
526
-                    $version_string                         = $should_be_array;
527
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
528
-                } else {
529
-                    //ok it checks out
530
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
531
-                }
532
-            }
533
-            $espresso_db_update = $corrected_db_update;
534
-            update_option('espresso_db_update', $espresso_db_update);
535
-        }
536
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
537
-        return $espresso_db_update;
538
-    }
539
-
540
-
541
-
542
-    /**
543
-     * Does the traditional work of setting up the plugin's database and adding default data.
544
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
545
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
546
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
547
-     * so that it will be done when migrations are finished
548
-     *
549
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
550
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
551
-     *                                       This is a resource-intensive job
552
-     *                                       so we prefer to only do it when necessary
553
-     * @return void
554
-     * @throws EE_Error
555
-     */
556
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
557
-    {
558
-        $request_type = $this->detect_req_type();
559
-        //only initialize system if we're not in maintenance mode.
560
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
561
-            update_option('ee_flush_rewrite_rules', true);
562
-            if ($verify_schema) {
563
-                EEH_Activation::initialize_db_and_folders();
564
-            }
565
-            EEH_Activation::initialize_db_content();
566
-            EEH_Activation::system_initialization();
567
-            if ($initialize_addons_too) {
568
-                $this->initialize_addons();
569
-            }
570
-        } else {
571
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
572
-        }
573
-        if ($request_type === EE_System::req_type_new_activation
574
-            || $request_type === EE_System::req_type_reactivation
575
-            || (
576
-                $request_type === EE_System::req_type_upgrade
577
-                && $this->is_major_version_change()
578
-            )
579
-        ) {
580
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
581
-        }
582
-    }
583
-
584
-
585
-
586
-    /**
587
-     * Initializes the db for all registered addons
588
-     *
589
-     * @throws EE_Error
590
-     */
591
-    public function initialize_addons()
592
-    {
593
-        //foreach registered addon, make sure its db is up-to-date too
594
-        foreach ($this->registry->addons as $addon) {
595
-            if ($addon instanceof EE_Addon) {
596
-                $addon->initialize_db_if_no_migrations_required();
597
-            }
598
-        }
599
-    }
600
-
601
-
602
-
603
-    /**
604
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
605
-     *
606
-     * @param    array  $version_history
607
-     * @param    string $current_version_to_add version to be added to the version history
608
-     * @return    boolean success as to whether or not this option was changed
609
-     */
610
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
611
-    {
612
-        if (! $version_history) {
613
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
614
-        }
615
-        if ($current_version_to_add === null) {
616
-            $current_version_to_add = espresso_version();
617
-        }
618
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
619
-        // re-save
620
-        return update_option('espresso_db_update', $version_history);
621
-    }
622
-
623
-
624
-
625
-    /**
626
-     * Detects if the current version indicated in the has existed in the list of
627
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
628
-     *
629
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
630
-     *                                  If not supplied, fetches it from the options table.
631
-     *                                  Also, caches its result so later parts of the code can also know whether
632
-     *                                  there's been an update or not. This way we can add the current version to
633
-     *                                  espresso_db_update, but still know if this is a new install or not
634
-     * @return int one of the constants on EE_System::req_type_
635
-     */
636
-    public function detect_req_type($espresso_db_update = null)
637
-    {
638
-        if ($this->_req_type === null) {
639
-            $espresso_db_update          = ! empty($espresso_db_update)
640
-                ? $espresso_db_update
641
-                : $this->fix_espresso_db_upgrade_option();
642
-            $this->_req_type             = EE_System::detect_req_type_given_activation_history(
643
-                $espresso_db_update,
644
-                'ee_espresso_activation', espresso_version()
645
-            );
646
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
647
-            $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
648
-        }
649
-        return $this->_req_type;
650
-    }
651
-
652
-
653
-
654
-    /**
655
-     * Returns whether or not there was a non-micro version change (ie, change in either
656
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
657
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
658
-     *
659
-     * @param $activation_history
660
-     * @return bool
661
-     */
662
-    private function _detect_major_version_change($activation_history)
663
-    {
664
-        $previous_version       = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
665
-        $previous_version_parts = explode('.', $previous_version);
666
-        $current_version_parts  = explode('.', espresso_version());
667
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
668
-               && ($previous_version_parts[0] !== $current_version_parts[0]
669
-                   || $previous_version_parts[1] !== $current_version_parts[1]
670
-               );
671
-    }
672
-
673
-
674
-
675
-    /**
676
-     * Returns true if either the major or minor version of EE changed during this request.
677
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
678
-     *
679
-     * @return bool
680
-     */
681
-    public function is_major_version_change()
682
-    {
683
-        return $this->_major_version_change;
684
-    }
685
-
686
-
687
-
688
-    /**
689
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
690
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
691
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
692
-     * just activated to (for core that will always be espresso_version())
693
-     *
694
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
695
-     *                                                 ee plugin. for core that's 'espresso_db_update'
696
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
697
-     *                                                 indicate that this plugin was just activated
698
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
699
-     *                                                 espresso_version())
700
-     * @return int one of the constants on EE_System::req_type_*
701
-     */
702
-    public static function detect_req_type_given_activation_history(
703
-        $activation_history_for_addon,
704
-        $activation_indicator_option_name,
705
-        $version_to_upgrade_to
706
-    ) {
707
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
708
-        if ($activation_history_for_addon) {
709
-            //it exists, so this isn't a completely new install
710
-            //check if this version already in that list of previously installed versions
711
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
712
-                //it a version we haven't seen before
713
-                if ($version_is_higher === 1) {
714
-                    $req_type = EE_System::req_type_upgrade;
715
-                } else {
716
-                    $req_type = EE_System::req_type_downgrade;
717
-                }
718
-                delete_option($activation_indicator_option_name);
719
-            } else {
720
-                // its not an update. maybe a reactivation?
721
-                if (get_option($activation_indicator_option_name, false)) {
722
-                    if ($version_is_higher === -1) {
723
-                        $req_type = EE_System::req_type_downgrade;
724
-                    } elseif ($version_is_higher === 0) {
725
-                        //we've seen this version before, but it's an activation. must be a reactivation
726
-                        $req_type = EE_System::req_type_reactivation;
727
-                    } else {//$version_is_higher === 1
728
-                        $req_type = EE_System::req_type_upgrade;
729
-                    }
730
-                    delete_option($activation_indicator_option_name);
731
-                } else {
732
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
733
-                    if ($version_is_higher === -1) {
734
-                        $req_type = EE_System::req_type_downgrade;
735
-                    } elseif ($version_is_higher === 0) {
736
-                        //we've seen this version before and it's not an activation. its normal request
737
-                        $req_type = EE_System::req_type_normal;
738
-                    } else {//$version_is_higher === 1
739
-                        $req_type = EE_System::req_type_upgrade;
740
-                    }
741
-                }
742
-            }
743
-        } else {
744
-            //brand new install
745
-            $req_type = EE_System::req_type_new_activation;
746
-            delete_option($activation_indicator_option_name);
747
-        }
748
-        return $req_type;
749
-    }
750
-
751
-
752
-
753
-    /**
754
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
755
-     * the $activation_history_for_addon
756
-     *
757
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
758
-     *                                             sometimes containing 'unknown-date'
759
-     * @param string $version_to_upgrade_to        (current version)
760
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
761
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
762
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
763
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
764
-     */
765
-    private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
766
-    {
767
-        //find the most recently-activated version
768
-        $most_recently_active_version =
769
-            EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
770
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
771
-    }
772
-
773
-
774
-
775
-    /**
776
-     * Gets the most recently active version listed in the activation history,
777
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
778
-     *
779
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
780
-     *                                   sometimes containing 'unknown-date'
781
-     * @return string
782
-     */
783
-    private static function _get_most_recently_active_version_from_activation_history($activation_history)
784
-    {
785
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
786
-        $most_recently_active_version            = '0.0.0.dev.000';
787
-        if (is_array($activation_history)) {
788
-            foreach ($activation_history as $version => $times_activated) {
789
-                //check there is a record of when this version was activated. Otherwise,
790
-                //mark it as unknown
791
-                if (! $times_activated) {
792
-                    $times_activated = array('unknown-date');
793
-                }
794
-                if (is_string($times_activated)) {
795
-                    $times_activated = array($times_activated);
796
-                }
797
-                foreach ($times_activated as $an_activation) {
798
-                    if ($an_activation !== 'unknown-date'
799
-                        && $an_activation
800
-                           > $most_recently_active_version_activation) {
801
-                        $most_recently_active_version            = $version;
802
-                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
803
-                            ? '1970-01-01 00:00:00'
804
-                            : $an_activation;
805
-                    }
806
-                }
807
-            }
808
-        }
809
-        return $most_recently_active_version;
810
-    }
811
-
812
-
813
-
814
-    /**
815
-     * This redirects to the about EE page after activation
816
-     *
817
-     * @return void
818
-     */
819
-    public function redirect_to_about_ee()
820
-    {
821
-        $notices = EE_Error::get_notices(false);
822
-        //if current user is an admin and it's not an ajax or rest request
823
-        if (
824
-            ! isset($notices['errors'])
825
-            && $this->request->isAdmin()
826
-            && apply_filters(
827
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
828
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
829
-            )
830
-        ) {
831
-            $query_params = array('page' => 'espresso_about');
832
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
833
-                $query_params['new_activation'] = true;
834
-            }
835
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
836
-                $query_params['reactivation'] = true;
837
-            }
838
-            $url = add_query_arg($query_params, admin_url('admin.php'));
839
-            wp_safe_redirect($url);
840
-            exit();
841
-        }
842
-    }
843
-
844
-
845
-
846
-    /**
847
-     * load_core_configuration
848
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
849
-     * which runs during the WP 'plugins_loaded' action at priority 5
850
-     *
851
-     * @return void
852
-     * @throws ReflectionException
853
-     */
854
-    public function load_core_configuration()
855
-    {
856
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
857
-        $this->loader->getShared('EE_Load_Textdomain');
858
-        //load textdomain
859
-        EE_Load_Textdomain::load_textdomain();
860
-        // load and setup EE_Config and EE_Network_Config
861
-        $config = $this->loader->getShared('EE_Config');
862
-        $this->loader->getShared('EE_Network_Config');
863
-        // setup autoloaders
864
-        // enable logging?
865
-        if ($config->admin->use_full_logging) {
866
-            $this->loader->getShared('EE_Log');
867
-        }
868
-        // check for activation errors
869
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
870
-        if ($activation_errors) {
871
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
872
-            update_option('ee_plugin_activation_errors', false);
873
-        }
874
-        // get model names
875
-        $this->_parse_model_names();
876
-        //load caf stuff a chance to play during the activation process too.
877
-        $this->_maybe_brew_regular();
878
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
879
-    }
880
-
881
-
882
-
883
-    /**
884
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
885
-     *
886
-     * @return void
887
-     * @throws ReflectionException
888
-     */
889
-    private function _parse_model_names()
890
-    {
891
-        //get all the files in the EE_MODELS folder that end in .model.php
892
-        $models                 = glob(EE_MODELS . '*.model.php');
893
-        $model_names            = array();
894
-        $non_abstract_db_models = array();
895
-        foreach ($models as $model) {
896
-            // get model classname
897
-            $classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
898
-            $short_name      = str_replace('EEM_', '', $classname);
899
-            $reflectionClass = new ReflectionClass($classname);
900
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
901
-                $non_abstract_db_models[ $short_name ] = $classname;
902
-            }
903
-            $model_names[ $short_name ] = $classname;
904
-        }
905
-        $this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
906
-        $this->registry->non_abstract_db_models = apply_filters(
907
-            'FHEE__EE_System__parse_implemented_model_names',
908
-            $non_abstract_db_models
909
-        );
910
-    }
911
-
912
-
913
-
914
-    /**
915
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
916
-     * that need to be setup before our EE_System launches.
917
-     *
918
-     * @return void
919
-     */
920
-    private function _maybe_brew_regular()
921
-    {
922
-        if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
923
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
924
-        }
925
-    }
926
-
927
-
928
-
929
-    /**
930
-     * register_shortcodes_modules_and_widgets
931
-     * generate lists of shortcodes and modules, then verify paths and classes
932
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
933
-     * which runs during the WP 'plugins_loaded' action at priority 7
934
-     *
935
-     * @access public
936
-     * @return void
937
-     * @throws Exception
938
-     */
939
-    public function register_shortcodes_modules_and_widgets()
940
-    {
941
-        try {
942
-            // load, register, and add shortcodes the new way
943
-            if ($this->request->isFrontend() || $this->request->isIframe()) {
944
-                $this->loader->getShared(
945
-                    'EventEspresso\core\services\shortcodes\ShortcodesManager',
946
-                    array(
947
-                        // and the old way, but we'll put it under control of the new system
948
-                        EE_Config::getLegacyShortcodesManager(),
949
-                    )
950
-                );
951
-            }
952
-            if (function_exists('register_block_type')) {
953
-                $editor_block_collection = $this->loader->getShared(
954
-                    'EventEspresso\core\domain\entities\editor\EditorBlockCollection'
955
-                );
956
-                // or the even newer newer new way
957
-                if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAdmin()) {
958
-                    $this->loader->getShared(
959
-                        'EventEspresso\core\services\editor\EditorBlockRegistrationManager',
960
-                        array($editor_block_collection, $this->request)
961
-                    );
962
-                }
963
-                if ($this->request->isAdmin()) {
964
-                    $this->loader->getShared(
965
-                        'EventEspresso\core\services\editor\EspressoGutenbergEditor',
966
-                        array($editor_block_collection, $this->request)
967
-                    );
968
-                }
969
-            }
970
-        } catch (Exception $exception) {
971
-            new ExceptionStackTraceDisplay($exception);
972
-        }
973
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
974
-        // check for addons using old hook point
975
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
976
-            $this->_incompatible_addon_error();
977
-        }
978
-    }
979
-
980
-
981
-
982
-    /**
983
-     * _incompatible_addon_error
984
-     *
985
-     * @access public
986
-     * @return void
987
-     */
988
-    private function _incompatible_addon_error()
989
-    {
990
-        // get array of classes hooking into here
991
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
992
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
993
-        );
994
-        if (! empty($class_names)) {
995
-            $msg = __(
996
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
997
-                'event_espresso'
998
-            );
999
-            $msg .= '<ul>';
1000
-            foreach ($class_names as $class_name) {
1001
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
1002
-                        array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
1003
-                        $class_name
1004
-                    ) . '</b></li>';
1005
-            }
1006
-            $msg .= '</ul>';
1007
-            $msg .= __(
1008
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1009
-                'event_espresso'
1010
-            );
1011
-            // save list of incompatible addons to wp-options for later use
1012
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
1013
-            if (is_admin()) {
1014
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1015
-            }
1016
-        }
1017
-    }
1018
-
1019
-
1020
-
1021
-    /**
1022
-     * brew_espresso
1023
-     * begins the process of setting hooks for initializing EE in the correct order
1024
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1025
-     * which runs during the WP 'plugins_loaded' action at priority 9
1026
-     *
1027
-     * @return void
1028
-     */
1029
-    public function brew_espresso()
1030
-    {
1031
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
1032
-        // load some final core systems
1033
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
1034
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1035
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
1036
-        add_action('init', array($this, 'load_controllers'), 7);
1037
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
1038
-        add_action('init', array($this, 'initialize'), 10);
1039
-        add_action('init', array($this, 'initialize_last'), 100);
1040
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1041
-            // pew pew pew
1042
-            $this->loader->getShared('EE_PUE');
1043
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1044
-        }
1045
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
1046
-    }
1047
-
1048
-
1049
-
1050
-    /**
1051
-     *    set_hooks_for_core
1052
-     *
1053
-     * @access public
1054
-     * @return    void
1055
-     * @throws EE_Error
1056
-     */
1057
-    public function set_hooks_for_core()
1058
-    {
1059
-        $this->_deactivate_incompatible_addons();
1060
-        do_action('AHEE__EE_System__set_hooks_for_core');
1061
-        //caps need to be initialized on every request so that capability maps are set.
1062
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1063
-        $this->registry->CAP->init_caps();
1064
-    }
1065
-
1066
-
1067
-
1068
-    /**
1069
-     * Using the information gathered in EE_System::_incompatible_addon_error,
1070
-     * deactivates any addons considered incompatible with the current version of EE
1071
-     */
1072
-    private function _deactivate_incompatible_addons()
1073
-    {
1074
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
1075
-        if (! empty($incompatible_addons)) {
1076
-            $active_plugins = get_option('active_plugins', array());
1077
-            foreach ($active_plugins as $active_plugin) {
1078
-                foreach ($incompatible_addons as $incompatible_addon) {
1079
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
1080
-                        unset($_GET['activate']);
1081
-                        espresso_deactivate_plugin($active_plugin);
1082
-                    }
1083
-                }
1084
-            }
1085
-        }
1086
-    }
1087
-
1088
-
1089
-
1090
-    /**
1091
-     *    perform_activations_upgrades_and_migrations
1092
-     *
1093
-     * @access public
1094
-     * @return    void
1095
-     */
1096
-    public function perform_activations_upgrades_and_migrations()
1097
-    {
1098
-        //first check if we had previously attempted to setup EE's directories but failed
1099
-        if ($this->request->isActivation() && EEH_Activation::upload_directories_incomplete()) {
1100
-            EEH_Activation::create_upload_directories();
1101
-        }
1102
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1103
-    }
1104
-
1105
-
1106
-
1107
-    /**
1108
-     *    load_CPTs_and_session
1109
-     *
1110
-     * @access public
1111
-     * @return    void
1112
-     */
1113
-    public function load_CPTs_and_session()
1114
-    {
1115
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
1116
-        // register Custom Post Types
1117
-        $this->loader->getShared('EE_Register_CPTs');
1118
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1119
-    }
1120
-
1121
-
1122
-
1123
-    /**
1124
-     * load_controllers
1125
-     * this is the best place to load any additional controllers that needs access to EE core.
1126
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1127
-     * time
1128
-     *
1129
-     * @access public
1130
-     * @return void
1131
-     */
1132
-    public function load_controllers()
1133
-    {
1134
-        do_action('AHEE__EE_System__load_controllers__start');
1135
-        // let's get it started
1136
-        if (
1137
-            ! $this->maintenance_mode->level()
1138
-            && ($this->request->isFrontend() || $this->request->isFrontAjax())
1139
-        ) {
1140
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1141
-            $this->loader->getShared('EE_Front_Controller');
1142
-        } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1143
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1144
-            $this->loader->getShared('EE_Admin');
1145
-        }
1146
-        do_action('AHEE__EE_System__load_controllers__complete');
1147
-    }
1148
-
1149
-
1150
-
1151
-    /**
1152
-     * core_loaded_and_ready
1153
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1154
-     *
1155
-     * @access public
1156
-     * @return void
1157
-     */
1158
-    public function core_loaded_and_ready()
1159
-    {
1160
-        if (
1161
-            $this->request->isAdmin()
1162
-            || $this->request->isEeAjax()
1163
-            || $this->request->isFrontend()
1164
-        ) {
1165
-            $this->loader->getShared('EE_Session');
1166
-        }
1167
-        do_action('AHEE__EE_System__core_loaded_and_ready');
1168
-        // load_espresso_template_tags
1169
-        if (
1170
-            is_readable(EE_PUBLIC . 'template_tags.php')
1171
-            && (
1172
-                $this->request->isFrontend()
1173
-                || $this->request->isAdmin()
1174
-                || $this->request->isIframe()
1175
-                || $this->request->isFeed()
1176
-            )
1177
-        ) {
1178
-            require_once EE_PUBLIC . 'template_tags.php';
1179
-        }
1180
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1181
-        if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1182
-            $this->loader->getShared('EventEspresso\core\services\assets\Registry');
1183
-        }
1184
-    }
1185
-
1186
-
1187
-
1188
-    /**
1189
-     * initialize
1190
-     * this is the best place to begin initializing client code
1191
-     *
1192
-     * @access public
1193
-     * @return void
1194
-     */
1195
-    public function initialize()
1196
-    {
1197
-        do_action('AHEE__EE_System__initialize');
1198
-    }
1199
-
1200
-
1201
-
1202
-    /**
1203
-     * initialize_last
1204
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1205
-     * initialize has done so
1206
-     *
1207
-     * @access public
1208
-     * @return void
1209
-     */
1210
-    public function initialize_last()
1211
-    {
1212
-        do_action('AHEE__EE_System__initialize_last');
1213
-        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1214
-    }
1215
-
1216
-
1217
-
1218
-    /**
1219
-     * @return void
1220
-     * @throws EE_Error
1221
-     */
1222
-    public function addEspressoToolbar()
1223
-    {
1224
-        $this->loader->getShared(
1225
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1226
-            array($this->registry->CAP)
1227
-        );
1228
-    }
1229
-
1230
-
1231
-
1232
-    /**
1233
-     * do_not_cache
1234
-     * sets no cache headers and defines no cache constants for WP plugins
1235
-     *
1236
-     * @access public
1237
-     * @return void
1238
-     */
1239
-    public static function do_not_cache()
1240
-    {
1241
-        // set no cache constants
1242
-        if (! defined('DONOTCACHEPAGE')) {
1243
-            define('DONOTCACHEPAGE', true);
1244
-        }
1245
-        if (! defined('DONOTCACHCEOBJECT')) {
1246
-            define('DONOTCACHCEOBJECT', true);
1247
-        }
1248
-        if (! defined('DONOTCACHEDB')) {
1249
-            define('DONOTCACHEDB', true);
1250
-        }
1251
-        // add no cache headers
1252
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1253
-        // plus a little extra for nginx and Google Chrome
1254
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1255
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1256
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1257
-    }
1258
-
1259
-
1260
-
1261
-    /**
1262
-     *    extra_nocache_headers
1263
-     *
1264
-     * @access    public
1265
-     * @param $headers
1266
-     * @return    array
1267
-     */
1268
-    public static function extra_nocache_headers($headers)
1269
-    {
1270
-        // for NGINX
1271
-        $headers['X-Accel-Expires'] = 0;
1272
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1273
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1274
-        return $headers;
1275
-    }
1276
-
1277
-
1278
-
1279
-    /**
1280
-     *    nocache_headers
1281
-     *
1282
-     * @access    public
1283
-     * @return    void
1284
-     */
1285
-    public static function nocache_headers()
1286
-    {
1287
-        nocache_headers();
1288
-    }
1289
-
1290
-
1291
-
1292
-    /**
1293
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1294
-     * never returned with the function.
1295
-     *
1296
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1297
-     * @return array
1298
-     */
1299
-    public function remove_pages_from_wp_list_pages($exclude_array)
1300
-    {
1301
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1302
-    }
27
+	/**
28
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
29
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
30
+	 */
31
+	const req_type_normal = 0;
32
+
33
+	/**
34
+	 * Indicates this is a brand new installation of EE so we should install
35
+	 * tables and default data etc
36
+	 */
37
+	const req_type_new_activation = 1;
38
+
39
+	/**
40
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
41
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
42
+	 * and that default data is setup too
43
+	 */
44
+	const req_type_reactivation = 2;
45
+
46
+	/**
47
+	 * indicates that EE has been upgraded since its previous request.
48
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
49
+	 */
50
+	const req_type_upgrade = 3;
51
+
52
+	/**
53
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
54
+	 */
55
+	const req_type_downgrade = 4;
56
+
57
+	/**
58
+	 * @deprecated since version 4.6.0.dev.006
59
+	 * Now whenever a new_activation is detected the request type is still just
60
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
61
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
62
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
63
+	 * (Specifically, when the migration manager indicates migrations are finished
64
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
65
+	 */
66
+	const req_type_activation_but_not_installed = 5;
67
+
68
+	/**
69
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
70
+	 */
71
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
72
+
73
+
74
+	/**
75
+	 * @var EE_System $_instance
76
+	 */
77
+	private static $_instance;
78
+
79
+	/**
80
+	 * @var EE_Registry $registry
81
+	 */
82
+	private $registry;
83
+
84
+	/**
85
+	 * @var LoaderInterface $loader
86
+	 */
87
+	private $loader;
88
+
89
+	/**
90
+	 * @var EE_Capabilities $capabilities
91
+	 */
92
+	private $capabilities;
93
+
94
+	/**
95
+	 * @var RequestInterface $request
96
+	 */
97
+	private $request;
98
+
99
+	/**
100
+	 * @var EE_Maintenance_Mode $maintenance_mode
101
+	 */
102
+	private $maintenance_mode;
103
+
104
+	/**
105
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
106
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
107
+	 *
108
+	 * @var int $_req_type
109
+	 */
110
+	private $_req_type;
111
+
112
+	/**
113
+	 * Whether or not there was a non-micro version change in EE core version during this request
114
+	 *
115
+	 * @var boolean $_major_version_change
116
+	 */
117
+	private $_major_version_change = false;
118
+
119
+	/**
120
+	 * A Context DTO dedicated solely to identifying the current request type.
121
+	 *
122
+	 * @var RequestTypeContextCheckerInterface $request_type
123
+	 */
124
+	private $request_type;
125
+
126
+
127
+
128
+	/**
129
+	 * @singleton method used to instantiate class object
130
+	 * @param EE_Registry|null         $registry
131
+	 * @param LoaderInterface|null     $loader
132
+	 * @param RequestInterface|null          $request
133
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
134
+	 * @return EE_System
135
+	 */
136
+	public static function instance(
137
+		EE_Registry $registry = null,
138
+		LoaderInterface $loader = null,
139
+		RequestInterface $request = null,
140
+		EE_Maintenance_Mode $maintenance_mode = null
141
+	) {
142
+		// check if class object is instantiated
143
+		if (! self::$_instance instanceof EE_System) {
144
+			self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
145
+		}
146
+		return self::$_instance;
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * resets the instance and returns it
153
+	 *
154
+	 * @return EE_System
155
+	 */
156
+	public static function reset()
157
+	{
158
+		self::$_instance->_req_type = null;
159
+		//make sure none of the old hooks are left hanging around
160
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
161
+		//we need to reset the migration manager in order for it to detect DMSs properly
162
+		EE_Data_Migration_Manager::reset();
163
+		self::instance()->detect_activations_or_upgrades();
164
+		self::instance()->perform_activations_upgrades_and_migrations();
165
+		return self::instance();
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 * sets hooks for running rest of system
172
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
173
+	 * starting EE Addons from any other point may lead to problems
174
+	 *
175
+	 * @param EE_Registry         $registry
176
+	 * @param LoaderInterface     $loader
177
+	 * @param RequestInterface          $request
178
+	 * @param EE_Maintenance_Mode $maintenance_mode
179
+	 */
180
+	private function __construct(
181
+		EE_Registry $registry,
182
+		LoaderInterface $loader,
183
+		RequestInterface $request,
184
+		EE_Maintenance_Mode $maintenance_mode
185
+	) {
186
+		$this->registry         = $registry;
187
+		$this->loader           = $loader;
188
+		$this->request          = $request;
189
+		$this->maintenance_mode = $maintenance_mode;
190
+		do_action('AHEE__EE_System__construct__begin', $this);
191
+		add_action(
192
+			'AHEE__EE_Bootstrap__load_espresso_addons',
193
+			array($this, 'loadCapabilities'),
194
+			5
195
+		);
196
+		add_action(
197
+			'AHEE__EE_Bootstrap__load_espresso_addons',
198
+			array($this, 'loadCommandBus'),
199
+			7
200
+		);
201
+		add_action(
202
+			'AHEE__EE_Bootstrap__load_espresso_addons',
203
+			array($this, 'loadPluginApi'),
204
+			9
205
+		);
206
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
207
+		add_action(
208
+			'AHEE__EE_Bootstrap__load_espresso_addons',
209
+			array($this, 'load_espresso_addons')
210
+		);
211
+		// when an ee addon is activated, we want to call the core hook(s) again
212
+		// because the newly-activated addon didn't get a chance to run at all
213
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
214
+		// detect whether install or upgrade
215
+		add_action(
216
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
217
+			array($this, 'detect_activations_or_upgrades'),
218
+			3
219
+		);
220
+		// load EE_Config, EE_Textdomain, etc
221
+		add_action(
222
+			'AHEE__EE_Bootstrap__load_core_configuration',
223
+			array($this, 'load_core_configuration'),
224
+			5
225
+		);
226
+		// load EE_Config, EE_Textdomain, etc
227
+		add_action(
228
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
229
+			array($this, 'register_shortcodes_modules_and_widgets'),
230
+			7
231
+		);
232
+		// you wanna get going? I wanna get going... let's get going!
233
+		add_action(
234
+			'AHEE__EE_Bootstrap__brew_espresso',
235
+			array($this, 'brew_espresso'),
236
+			9
237
+		);
238
+		//other housekeeping
239
+		//exclude EE critical pages from wp_list_pages
240
+		add_filter(
241
+			'wp_list_pages_excludes',
242
+			array($this, 'remove_pages_from_wp_list_pages'),
243
+			10
244
+		);
245
+		// ALL EE Addons should use the following hook point to attach their initial setup too
246
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
247
+		do_action('AHEE__EE_System__construct__complete', $this);
248
+	}
249
+
250
+
251
+	/**
252
+	 * load and setup EE_Capabilities
253
+	 *
254
+	 * @return void
255
+	 * @throws EE_Error
256
+	 */
257
+	public function loadCapabilities()
258
+	{
259
+		$this->capabilities = $this->loader->getShared('EE_Capabilities');
260
+		add_action(
261
+			'AHEE__EE_Capabilities__init_caps__before_initialization',
262
+			function ()
263
+			{
264
+				LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
265
+			}
266
+		);
267
+	}
268
+
269
+
270
+
271
+	/**
272
+	 * create and cache the CommandBus, and also add middleware
273
+	 * The CapChecker middleware requires the use of EE_Capabilities
274
+	 * which is why we need to load the CommandBus after Caps are set up
275
+	 *
276
+	 * @return void
277
+	 * @throws EE_Error
278
+	 */
279
+	public function loadCommandBus()
280
+	{
281
+		$this->loader->getShared(
282
+			'CommandBusInterface',
283
+			array(
284
+				null,
285
+				apply_filters(
286
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
287
+					array(
288
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
289
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
290
+					)
291
+				),
292
+			)
293
+		);
294
+	}
295
+
296
+
297
+
298
+	/**
299
+	 * @return void
300
+	 * @throws EE_Error
301
+	 */
302
+	public function loadPluginApi()
303
+	{
304
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
305
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
306
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
307
+		$this->loader->getShared('EE_Request_Handler');
308
+	}
309
+
310
+
311
+	/**
312
+	 * @param string $addon_name
313
+	 * @param string $version_constant
314
+	 * @param string $min_version_required
315
+	 * @param string $load_callback
316
+	 * @param string $plugin_file_constant
317
+	 * @return void
318
+	 */
319
+	private function deactivateIncompatibleAddon(
320
+		$addon_name,
321
+		$version_constant,
322
+		$min_version_required,
323
+		$load_callback,
324
+		$plugin_file_constant
325
+	) {
326
+		if (! defined($version_constant)) {
327
+			return;
328
+		}
329
+		$addon_version = constant($version_constant);
330
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
331
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
332
+			if (! function_exists('deactivate_plugins')) {
333
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
334
+			}
335
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
336
+			unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
337
+			EE_Error::add_error(
338
+				sprintf(
339
+					esc_html__(
340
+						'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
341
+						'event_espresso'
342
+					),
343
+					$addon_name,
344
+					$min_version_required
345
+				),
346
+				__FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
347
+			);
348
+			EE_Error::get_notices(false, true);
349
+		}
350
+	}
351
+
352
+
353
+	/**
354
+	 * load_espresso_addons
355
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
356
+	 * this is hooked into both:
357
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
358
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
359
+	 *    and the WP 'activate_plugin' hook point
360
+	 *
361
+	 * @access public
362
+	 * @return void
363
+	 */
364
+	public function load_espresso_addons()
365
+	{
366
+		$this->deactivateIncompatibleAddon(
367
+			'Wait Lists',
368
+			'EE_WAIT_LISTS_VERSION',
369
+			'1.0.0.beta.074',
370
+			'load_espresso_wait_lists',
371
+			'EE_WAIT_LISTS_PLUGIN_FILE'
372
+		);
373
+		$this->deactivateIncompatibleAddon(
374
+			'Automated Upcoming Event Notifications',
375
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
376
+			'1.0.0.beta.091',
377
+			'load_espresso_automated_upcoming_event_notification',
378
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
379
+		);
380
+		do_action('AHEE__EE_System__load_espresso_addons');
381
+		//if the WP API basic auth plugin isn't already loaded, load it now.
382
+		//We want it for mobile apps. Just include the entire plugin
383
+		//also, don't load the basic auth when a plugin is getting activated, because
384
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
385
+		//and causes a fatal error
386
+		if (
387
+			$this->request->getRequestParam('activate') !== 'true'
388
+			&& ! function_exists('json_basic_auth_handler')
389
+			&& ! function_exists('json_basic_auth_error')
390
+			&& ! in_array(
391
+				$this->request->getRequestParam('action'),
392
+				array('activate', 'activate-selected'),
393
+				true
394
+			)
395
+		) {
396
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
397
+		}
398
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
399
+	}
400
+
401
+
402
+
403
+	/**
404
+	 * detect_activations_or_upgrades
405
+	 * Checks for activation or upgrade of core first;
406
+	 * then also checks if any registered addons have been activated or upgraded
407
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
408
+	 * which runs during the WP 'plugins_loaded' action at priority 3
409
+	 *
410
+	 * @access public
411
+	 * @return void
412
+	 */
413
+	public function detect_activations_or_upgrades()
414
+	{
415
+		//first off: let's make sure to handle core
416
+		$this->detect_if_activation_or_upgrade();
417
+		foreach ($this->registry->addons as $addon) {
418
+			if ($addon instanceof EE_Addon) {
419
+				//detect teh request type for that addon
420
+				$addon->detect_activation_or_upgrade();
421
+			}
422
+		}
423
+	}
424
+
425
+
426
+
427
+	/**
428
+	 * detect_if_activation_or_upgrade
429
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
430
+	 * and either setting up the DB or setting up maintenance mode etc.
431
+	 *
432
+	 * @access public
433
+	 * @return void
434
+	 */
435
+	public function detect_if_activation_or_upgrade()
436
+	{
437
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
438
+		// check if db has been updated, or if its a brand-new installation
439
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
440
+		$request_type       = $this->detect_req_type($espresso_db_update);
441
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
442
+		switch ($request_type) {
443
+			case EE_System::req_type_new_activation:
444
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
445
+				$this->_handle_core_version_change($espresso_db_update);
446
+				break;
447
+			case EE_System::req_type_reactivation:
448
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
449
+				$this->_handle_core_version_change($espresso_db_update);
450
+				break;
451
+			case EE_System::req_type_upgrade:
452
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
453
+				//migrations may be required now that we've upgraded
454
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
455
+				$this->_handle_core_version_change($espresso_db_update);
456
+				//				echo "done upgrade";die;
457
+				break;
458
+			case EE_System::req_type_downgrade:
459
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
460
+				//its possible migrations are no longer required
461
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
462
+				$this->_handle_core_version_change($espresso_db_update);
463
+				break;
464
+			case EE_System::req_type_normal:
465
+			default:
466
+				break;
467
+		}
468
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
469
+	}
470
+
471
+
472
+
473
+	/**
474
+	 * Updates the list of installed versions and sets hooks for
475
+	 * initializing the database later during the request
476
+	 *
477
+	 * @param array $espresso_db_update
478
+	 */
479
+	private function _handle_core_version_change($espresso_db_update)
480
+	{
481
+		$this->update_list_of_installed_versions($espresso_db_update);
482
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
483
+		add_action(
484
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
485
+			array($this, 'initialize_db_if_no_migrations_required')
486
+		);
487
+	}
488
+
489
+
490
+
491
+	/**
492
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
493
+	 * information about what versions of EE have been installed and activated,
494
+	 * NOT necessarily the state of the database
495
+	 *
496
+	 * @param mixed $espresso_db_update           the value of the WordPress option.
497
+	 *                                            If not supplied, fetches it from the options table
498
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
499
+	 */
500
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
501
+	{
502
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
503
+		if (! $espresso_db_update) {
504
+			$espresso_db_update = get_option('espresso_db_update');
505
+		}
506
+		// check that option is an array
507
+		if (! is_array($espresso_db_update)) {
508
+			// if option is FALSE, then it never existed
509
+			if ($espresso_db_update === false) {
510
+				// make $espresso_db_update an array and save option with autoload OFF
511
+				$espresso_db_update = array();
512
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
513
+			} else {
514
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
515
+				$espresso_db_update = array($espresso_db_update => array());
516
+				update_option('espresso_db_update', $espresso_db_update);
517
+			}
518
+		} else {
519
+			$corrected_db_update = array();
520
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
521
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
522
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
523
+					//the key is an int, and the value IS NOT an array
524
+					//so it must be numerically-indexed, where values are versions installed...
525
+					//fix it!
526
+					$version_string                         = $should_be_array;
527
+					$corrected_db_update[ $version_string ] = array('unknown-date');
528
+				} else {
529
+					//ok it checks out
530
+					$corrected_db_update[ $should_be_version_string ] = $should_be_array;
531
+				}
532
+			}
533
+			$espresso_db_update = $corrected_db_update;
534
+			update_option('espresso_db_update', $espresso_db_update);
535
+		}
536
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
537
+		return $espresso_db_update;
538
+	}
539
+
540
+
541
+
542
+	/**
543
+	 * Does the traditional work of setting up the plugin's database and adding default data.
544
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
545
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
546
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
547
+	 * so that it will be done when migrations are finished
548
+	 *
549
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
550
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
551
+	 *                                       This is a resource-intensive job
552
+	 *                                       so we prefer to only do it when necessary
553
+	 * @return void
554
+	 * @throws EE_Error
555
+	 */
556
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
557
+	{
558
+		$request_type = $this->detect_req_type();
559
+		//only initialize system if we're not in maintenance mode.
560
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
561
+			update_option('ee_flush_rewrite_rules', true);
562
+			if ($verify_schema) {
563
+				EEH_Activation::initialize_db_and_folders();
564
+			}
565
+			EEH_Activation::initialize_db_content();
566
+			EEH_Activation::system_initialization();
567
+			if ($initialize_addons_too) {
568
+				$this->initialize_addons();
569
+			}
570
+		} else {
571
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
572
+		}
573
+		if ($request_type === EE_System::req_type_new_activation
574
+			|| $request_type === EE_System::req_type_reactivation
575
+			|| (
576
+				$request_type === EE_System::req_type_upgrade
577
+				&& $this->is_major_version_change()
578
+			)
579
+		) {
580
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
581
+		}
582
+	}
583
+
584
+
585
+
586
+	/**
587
+	 * Initializes the db for all registered addons
588
+	 *
589
+	 * @throws EE_Error
590
+	 */
591
+	public function initialize_addons()
592
+	{
593
+		//foreach registered addon, make sure its db is up-to-date too
594
+		foreach ($this->registry->addons as $addon) {
595
+			if ($addon instanceof EE_Addon) {
596
+				$addon->initialize_db_if_no_migrations_required();
597
+			}
598
+		}
599
+	}
600
+
601
+
602
+
603
+	/**
604
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
605
+	 *
606
+	 * @param    array  $version_history
607
+	 * @param    string $current_version_to_add version to be added to the version history
608
+	 * @return    boolean success as to whether or not this option was changed
609
+	 */
610
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
611
+	{
612
+		if (! $version_history) {
613
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
614
+		}
615
+		if ($current_version_to_add === null) {
616
+			$current_version_to_add = espresso_version();
617
+		}
618
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
619
+		// re-save
620
+		return update_option('espresso_db_update', $version_history);
621
+	}
622
+
623
+
624
+
625
+	/**
626
+	 * Detects if the current version indicated in the has existed in the list of
627
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
628
+	 *
629
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
630
+	 *                                  If not supplied, fetches it from the options table.
631
+	 *                                  Also, caches its result so later parts of the code can also know whether
632
+	 *                                  there's been an update or not. This way we can add the current version to
633
+	 *                                  espresso_db_update, but still know if this is a new install or not
634
+	 * @return int one of the constants on EE_System::req_type_
635
+	 */
636
+	public function detect_req_type($espresso_db_update = null)
637
+	{
638
+		if ($this->_req_type === null) {
639
+			$espresso_db_update          = ! empty($espresso_db_update)
640
+				? $espresso_db_update
641
+				: $this->fix_espresso_db_upgrade_option();
642
+			$this->_req_type             = EE_System::detect_req_type_given_activation_history(
643
+				$espresso_db_update,
644
+				'ee_espresso_activation', espresso_version()
645
+			);
646
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
647
+			$this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
648
+		}
649
+		return $this->_req_type;
650
+	}
651
+
652
+
653
+
654
+	/**
655
+	 * Returns whether or not there was a non-micro version change (ie, change in either
656
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
657
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
658
+	 *
659
+	 * @param $activation_history
660
+	 * @return bool
661
+	 */
662
+	private function _detect_major_version_change($activation_history)
663
+	{
664
+		$previous_version       = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
665
+		$previous_version_parts = explode('.', $previous_version);
666
+		$current_version_parts  = explode('.', espresso_version());
667
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
668
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
669
+				   || $previous_version_parts[1] !== $current_version_parts[1]
670
+			   );
671
+	}
672
+
673
+
674
+
675
+	/**
676
+	 * Returns true if either the major or minor version of EE changed during this request.
677
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
678
+	 *
679
+	 * @return bool
680
+	 */
681
+	public function is_major_version_change()
682
+	{
683
+		return $this->_major_version_change;
684
+	}
685
+
686
+
687
+
688
+	/**
689
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
690
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
691
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
692
+	 * just activated to (for core that will always be espresso_version())
693
+	 *
694
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
695
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
696
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
697
+	 *                                                 indicate that this plugin was just activated
698
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
699
+	 *                                                 espresso_version())
700
+	 * @return int one of the constants on EE_System::req_type_*
701
+	 */
702
+	public static function detect_req_type_given_activation_history(
703
+		$activation_history_for_addon,
704
+		$activation_indicator_option_name,
705
+		$version_to_upgrade_to
706
+	) {
707
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
708
+		if ($activation_history_for_addon) {
709
+			//it exists, so this isn't a completely new install
710
+			//check if this version already in that list of previously installed versions
711
+			if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
712
+				//it a version we haven't seen before
713
+				if ($version_is_higher === 1) {
714
+					$req_type = EE_System::req_type_upgrade;
715
+				} else {
716
+					$req_type = EE_System::req_type_downgrade;
717
+				}
718
+				delete_option($activation_indicator_option_name);
719
+			} else {
720
+				// its not an update. maybe a reactivation?
721
+				if (get_option($activation_indicator_option_name, false)) {
722
+					if ($version_is_higher === -1) {
723
+						$req_type = EE_System::req_type_downgrade;
724
+					} elseif ($version_is_higher === 0) {
725
+						//we've seen this version before, but it's an activation. must be a reactivation
726
+						$req_type = EE_System::req_type_reactivation;
727
+					} else {//$version_is_higher === 1
728
+						$req_type = EE_System::req_type_upgrade;
729
+					}
730
+					delete_option($activation_indicator_option_name);
731
+				} else {
732
+					//we've seen this version before and the activation indicate doesn't show it was just activated
733
+					if ($version_is_higher === -1) {
734
+						$req_type = EE_System::req_type_downgrade;
735
+					} elseif ($version_is_higher === 0) {
736
+						//we've seen this version before and it's not an activation. its normal request
737
+						$req_type = EE_System::req_type_normal;
738
+					} else {//$version_is_higher === 1
739
+						$req_type = EE_System::req_type_upgrade;
740
+					}
741
+				}
742
+			}
743
+		} else {
744
+			//brand new install
745
+			$req_type = EE_System::req_type_new_activation;
746
+			delete_option($activation_indicator_option_name);
747
+		}
748
+		return $req_type;
749
+	}
750
+
751
+
752
+
753
+	/**
754
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
755
+	 * the $activation_history_for_addon
756
+	 *
757
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
758
+	 *                                             sometimes containing 'unknown-date'
759
+	 * @param string $version_to_upgrade_to        (current version)
760
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
761
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
762
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
763
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
764
+	 */
765
+	private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
766
+	{
767
+		//find the most recently-activated version
768
+		$most_recently_active_version =
769
+			EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
770
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
771
+	}
772
+
773
+
774
+
775
+	/**
776
+	 * Gets the most recently active version listed in the activation history,
777
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
778
+	 *
779
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
780
+	 *                                   sometimes containing 'unknown-date'
781
+	 * @return string
782
+	 */
783
+	private static function _get_most_recently_active_version_from_activation_history($activation_history)
784
+	{
785
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
786
+		$most_recently_active_version            = '0.0.0.dev.000';
787
+		if (is_array($activation_history)) {
788
+			foreach ($activation_history as $version => $times_activated) {
789
+				//check there is a record of when this version was activated. Otherwise,
790
+				//mark it as unknown
791
+				if (! $times_activated) {
792
+					$times_activated = array('unknown-date');
793
+				}
794
+				if (is_string($times_activated)) {
795
+					$times_activated = array($times_activated);
796
+				}
797
+				foreach ($times_activated as $an_activation) {
798
+					if ($an_activation !== 'unknown-date'
799
+						&& $an_activation
800
+						   > $most_recently_active_version_activation) {
801
+						$most_recently_active_version            = $version;
802
+						$most_recently_active_version_activation = $an_activation === 'unknown-date'
803
+							? '1970-01-01 00:00:00'
804
+							: $an_activation;
805
+					}
806
+				}
807
+			}
808
+		}
809
+		return $most_recently_active_version;
810
+	}
811
+
812
+
813
+
814
+	/**
815
+	 * This redirects to the about EE page after activation
816
+	 *
817
+	 * @return void
818
+	 */
819
+	public function redirect_to_about_ee()
820
+	{
821
+		$notices = EE_Error::get_notices(false);
822
+		//if current user is an admin and it's not an ajax or rest request
823
+		if (
824
+			! isset($notices['errors'])
825
+			&& $this->request->isAdmin()
826
+			&& apply_filters(
827
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
828
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
829
+			)
830
+		) {
831
+			$query_params = array('page' => 'espresso_about');
832
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
833
+				$query_params['new_activation'] = true;
834
+			}
835
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
836
+				$query_params['reactivation'] = true;
837
+			}
838
+			$url = add_query_arg($query_params, admin_url('admin.php'));
839
+			wp_safe_redirect($url);
840
+			exit();
841
+		}
842
+	}
843
+
844
+
845
+
846
+	/**
847
+	 * load_core_configuration
848
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
849
+	 * which runs during the WP 'plugins_loaded' action at priority 5
850
+	 *
851
+	 * @return void
852
+	 * @throws ReflectionException
853
+	 */
854
+	public function load_core_configuration()
855
+	{
856
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
857
+		$this->loader->getShared('EE_Load_Textdomain');
858
+		//load textdomain
859
+		EE_Load_Textdomain::load_textdomain();
860
+		// load and setup EE_Config and EE_Network_Config
861
+		$config = $this->loader->getShared('EE_Config');
862
+		$this->loader->getShared('EE_Network_Config');
863
+		// setup autoloaders
864
+		// enable logging?
865
+		if ($config->admin->use_full_logging) {
866
+			$this->loader->getShared('EE_Log');
867
+		}
868
+		// check for activation errors
869
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
870
+		if ($activation_errors) {
871
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
872
+			update_option('ee_plugin_activation_errors', false);
873
+		}
874
+		// get model names
875
+		$this->_parse_model_names();
876
+		//load caf stuff a chance to play during the activation process too.
877
+		$this->_maybe_brew_regular();
878
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
879
+	}
880
+
881
+
882
+
883
+	/**
884
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
885
+	 *
886
+	 * @return void
887
+	 * @throws ReflectionException
888
+	 */
889
+	private function _parse_model_names()
890
+	{
891
+		//get all the files in the EE_MODELS folder that end in .model.php
892
+		$models                 = glob(EE_MODELS . '*.model.php');
893
+		$model_names            = array();
894
+		$non_abstract_db_models = array();
895
+		foreach ($models as $model) {
896
+			// get model classname
897
+			$classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
898
+			$short_name      = str_replace('EEM_', '', $classname);
899
+			$reflectionClass = new ReflectionClass($classname);
900
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
901
+				$non_abstract_db_models[ $short_name ] = $classname;
902
+			}
903
+			$model_names[ $short_name ] = $classname;
904
+		}
905
+		$this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
906
+		$this->registry->non_abstract_db_models = apply_filters(
907
+			'FHEE__EE_System__parse_implemented_model_names',
908
+			$non_abstract_db_models
909
+		);
910
+	}
911
+
912
+
913
+
914
+	/**
915
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
916
+	 * that need to be setup before our EE_System launches.
917
+	 *
918
+	 * @return void
919
+	 */
920
+	private function _maybe_brew_regular()
921
+	{
922
+		if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
923
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
924
+		}
925
+	}
926
+
927
+
928
+
929
+	/**
930
+	 * register_shortcodes_modules_and_widgets
931
+	 * generate lists of shortcodes and modules, then verify paths and classes
932
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
933
+	 * which runs during the WP 'plugins_loaded' action at priority 7
934
+	 *
935
+	 * @access public
936
+	 * @return void
937
+	 * @throws Exception
938
+	 */
939
+	public function register_shortcodes_modules_and_widgets()
940
+	{
941
+		try {
942
+			// load, register, and add shortcodes the new way
943
+			if ($this->request->isFrontend() || $this->request->isIframe()) {
944
+				$this->loader->getShared(
945
+					'EventEspresso\core\services\shortcodes\ShortcodesManager',
946
+					array(
947
+						// and the old way, but we'll put it under control of the new system
948
+						EE_Config::getLegacyShortcodesManager(),
949
+					)
950
+				);
951
+			}
952
+			if (function_exists('register_block_type')) {
953
+				$editor_block_collection = $this->loader->getShared(
954
+					'EventEspresso\core\domain\entities\editor\EditorBlockCollection'
955
+				);
956
+				// or the even newer newer new way
957
+				if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAdmin()) {
958
+					$this->loader->getShared(
959
+						'EventEspresso\core\services\editor\EditorBlockRegistrationManager',
960
+						array($editor_block_collection, $this->request)
961
+					);
962
+				}
963
+				if ($this->request->isAdmin()) {
964
+					$this->loader->getShared(
965
+						'EventEspresso\core\services\editor\EspressoGutenbergEditor',
966
+						array($editor_block_collection, $this->request)
967
+					);
968
+				}
969
+			}
970
+		} catch (Exception $exception) {
971
+			new ExceptionStackTraceDisplay($exception);
972
+		}
973
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
974
+		// check for addons using old hook point
975
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
976
+			$this->_incompatible_addon_error();
977
+		}
978
+	}
979
+
980
+
981
+
982
+	/**
983
+	 * _incompatible_addon_error
984
+	 *
985
+	 * @access public
986
+	 * @return void
987
+	 */
988
+	private function _incompatible_addon_error()
989
+	{
990
+		// get array of classes hooking into here
991
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
992
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
993
+		);
994
+		if (! empty($class_names)) {
995
+			$msg = __(
996
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
997
+				'event_espresso'
998
+			);
999
+			$msg .= '<ul>';
1000
+			foreach ($class_names as $class_name) {
1001
+				$msg .= '<li><b>Event Espresso - ' . str_replace(
1002
+						array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
1003
+						$class_name
1004
+					) . '</b></li>';
1005
+			}
1006
+			$msg .= '</ul>';
1007
+			$msg .= __(
1008
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1009
+				'event_espresso'
1010
+			);
1011
+			// save list of incompatible addons to wp-options for later use
1012
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
1013
+			if (is_admin()) {
1014
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1015
+			}
1016
+		}
1017
+	}
1018
+
1019
+
1020
+
1021
+	/**
1022
+	 * brew_espresso
1023
+	 * begins the process of setting hooks for initializing EE in the correct order
1024
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1025
+	 * which runs during the WP 'plugins_loaded' action at priority 9
1026
+	 *
1027
+	 * @return void
1028
+	 */
1029
+	public function brew_espresso()
1030
+	{
1031
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
1032
+		// load some final core systems
1033
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
1034
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1035
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
1036
+		add_action('init', array($this, 'load_controllers'), 7);
1037
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
1038
+		add_action('init', array($this, 'initialize'), 10);
1039
+		add_action('init', array($this, 'initialize_last'), 100);
1040
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1041
+			// pew pew pew
1042
+			$this->loader->getShared('EE_PUE');
1043
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1044
+		}
1045
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
1046
+	}
1047
+
1048
+
1049
+
1050
+	/**
1051
+	 *    set_hooks_for_core
1052
+	 *
1053
+	 * @access public
1054
+	 * @return    void
1055
+	 * @throws EE_Error
1056
+	 */
1057
+	public function set_hooks_for_core()
1058
+	{
1059
+		$this->_deactivate_incompatible_addons();
1060
+		do_action('AHEE__EE_System__set_hooks_for_core');
1061
+		//caps need to be initialized on every request so that capability maps are set.
1062
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1063
+		$this->registry->CAP->init_caps();
1064
+	}
1065
+
1066
+
1067
+
1068
+	/**
1069
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
1070
+	 * deactivates any addons considered incompatible with the current version of EE
1071
+	 */
1072
+	private function _deactivate_incompatible_addons()
1073
+	{
1074
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
1075
+		if (! empty($incompatible_addons)) {
1076
+			$active_plugins = get_option('active_plugins', array());
1077
+			foreach ($active_plugins as $active_plugin) {
1078
+				foreach ($incompatible_addons as $incompatible_addon) {
1079
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
1080
+						unset($_GET['activate']);
1081
+						espresso_deactivate_plugin($active_plugin);
1082
+					}
1083
+				}
1084
+			}
1085
+		}
1086
+	}
1087
+
1088
+
1089
+
1090
+	/**
1091
+	 *    perform_activations_upgrades_and_migrations
1092
+	 *
1093
+	 * @access public
1094
+	 * @return    void
1095
+	 */
1096
+	public function perform_activations_upgrades_and_migrations()
1097
+	{
1098
+		//first check if we had previously attempted to setup EE's directories but failed
1099
+		if ($this->request->isActivation() && EEH_Activation::upload_directories_incomplete()) {
1100
+			EEH_Activation::create_upload_directories();
1101
+		}
1102
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1103
+	}
1104
+
1105
+
1106
+
1107
+	/**
1108
+	 *    load_CPTs_and_session
1109
+	 *
1110
+	 * @access public
1111
+	 * @return    void
1112
+	 */
1113
+	public function load_CPTs_and_session()
1114
+	{
1115
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
1116
+		// register Custom Post Types
1117
+		$this->loader->getShared('EE_Register_CPTs');
1118
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1119
+	}
1120
+
1121
+
1122
+
1123
+	/**
1124
+	 * load_controllers
1125
+	 * this is the best place to load any additional controllers that needs access to EE core.
1126
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1127
+	 * time
1128
+	 *
1129
+	 * @access public
1130
+	 * @return void
1131
+	 */
1132
+	public function load_controllers()
1133
+	{
1134
+		do_action('AHEE__EE_System__load_controllers__start');
1135
+		// let's get it started
1136
+		if (
1137
+			! $this->maintenance_mode->level()
1138
+			&& ($this->request->isFrontend() || $this->request->isFrontAjax())
1139
+		) {
1140
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1141
+			$this->loader->getShared('EE_Front_Controller');
1142
+		} elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1143
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1144
+			$this->loader->getShared('EE_Admin');
1145
+		}
1146
+		do_action('AHEE__EE_System__load_controllers__complete');
1147
+	}
1148
+
1149
+
1150
+
1151
+	/**
1152
+	 * core_loaded_and_ready
1153
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1154
+	 *
1155
+	 * @access public
1156
+	 * @return void
1157
+	 */
1158
+	public function core_loaded_and_ready()
1159
+	{
1160
+		if (
1161
+			$this->request->isAdmin()
1162
+			|| $this->request->isEeAjax()
1163
+			|| $this->request->isFrontend()
1164
+		) {
1165
+			$this->loader->getShared('EE_Session');
1166
+		}
1167
+		do_action('AHEE__EE_System__core_loaded_and_ready');
1168
+		// load_espresso_template_tags
1169
+		if (
1170
+			is_readable(EE_PUBLIC . 'template_tags.php')
1171
+			&& (
1172
+				$this->request->isFrontend()
1173
+				|| $this->request->isAdmin()
1174
+				|| $this->request->isIframe()
1175
+				|| $this->request->isFeed()
1176
+			)
1177
+		) {
1178
+			require_once EE_PUBLIC . 'template_tags.php';
1179
+		}
1180
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1181
+		if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1182
+			$this->loader->getShared('EventEspresso\core\services\assets\Registry');
1183
+		}
1184
+	}
1185
+
1186
+
1187
+
1188
+	/**
1189
+	 * initialize
1190
+	 * this is the best place to begin initializing client code
1191
+	 *
1192
+	 * @access public
1193
+	 * @return void
1194
+	 */
1195
+	public function initialize()
1196
+	{
1197
+		do_action('AHEE__EE_System__initialize');
1198
+	}
1199
+
1200
+
1201
+
1202
+	/**
1203
+	 * initialize_last
1204
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1205
+	 * initialize has done so
1206
+	 *
1207
+	 * @access public
1208
+	 * @return void
1209
+	 */
1210
+	public function initialize_last()
1211
+	{
1212
+		do_action('AHEE__EE_System__initialize_last');
1213
+		add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1214
+	}
1215
+
1216
+
1217
+
1218
+	/**
1219
+	 * @return void
1220
+	 * @throws EE_Error
1221
+	 */
1222
+	public function addEspressoToolbar()
1223
+	{
1224
+		$this->loader->getShared(
1225
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1226
+			array($this->registry->CAP)
1227
+		);
1228
+	}
1229
+
1230
+
1231
+
1232
+	/**
1233
+	 * do_not_cache
1234
+	 * sets no cache headers and defines no cache constants for WP plugins
1235
+	 *
1236
+	 * @access public
1237
+	 * @return void
1238
+	 */
1239
+	public static function do_not_cache()
1240
+	{
1241
+		// set no cache constants
1242
+		if (! defined('DONOTCACHEPAGE')) {
1243
+			define('DONOTCACHEPAGE', true);
1244
+		}
1245
+		if (! defined('DONOTCACHCEOBJECT')) {
1246
+			define('DONOTCACHCEOBJECT', true);
1247
+		}
1248
+		if (! defined('DONOTCACHEDB')) {
1249
+			define('DONOTCACHEDB', true);
1250
+		}
1251
+		// add no cache headers
1252
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1253
+		// plus a little extra for nginx and Google Chrome
1254
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1255
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1256
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1257
+	}
1258
+
1259
+
1260
+
1261
+	/**
1262
+	 *    extra_nocache_headers
1263
+	 *
1264
+	 * @access    public
1265
+	 * @param $headers
1266
+	 * @return    array
1267
+	 */
1268
+	public static function extra_nocache_headers($headers)
1269
+	{
1270
+		// for NGINX
1271
+		$headers['X-Accel-Expires'] = 0;
1272
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1273
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1274
+		return $headers;
1275
+	}
1276
+
1277
+
1278
+
1279
+	/**
1280
+	 *    nocache_headers
1281
+	 *
1282
+	 * @access    public
1283
+	 * @return    void
1284
+	 */
1285
+	public static function nocache_headers()
1286
+	{
1287
+		nocache_headers();
1288
+	}
1289
+
1290
+
1291
+
1292
+	/**
1293
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1294
+	 * never returned with the function.
1295
+	 *
1296
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1297
+	 * @return array
1298
+	 */
1299
+	public function remove_pages_from_wp_list_pages($exclude_array)
1300
+	{
1301
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1302
+	}
1303 1303
 
1304 1304
 
1305 1305
 
Please login to merge, or discard this patch.