Completed
Branch FET-3467-waitlists (871a70)
by
unknown
96:23 queued 82:42
created
core/EE_Load_Espresso_Core.core.php 1 patch
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\loaders\LoaderInterface;
5 5
 
6 6
 if (! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -24,228 +24,228 @@  discard block
 block discarded – undo
24 24
 class EE_Load_Espresso_Core implements EEI_Request_Decorator, EEI_Request_Stack_Core_App
25 25
 {
26 26
 
27
-    /**
28
-     * @type LoaderInterface $loader
29
-     */
30
-    protected $loader;
31
-
32
-    /**
33
-     * @var EE_Request $request
34
-     */
35
-    protected $request;
36
-
37
-    /**
38
-     * @var EE_Response $response
39
-     */
40
-    protected $response;
41
-
42
-    /**
43
-     * @var EE_Dependency_Map $dependency_map
44
-     */
45
-    protected $dependency_map;
46
-
47
-    /**
48
-     * @var EE_Registry $registry
49
-     */
50
-    protected $registry;
51
-
52
-
53
-
54
-    /**
55
-     * EE_Load_Espresso_Core constructor
56
-     */
57
-    public function __construct()
58
-    {
59
-        espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php');
60
-    }
61
-
62
-
63
-
64
-    /**
65
-     * handle
66
-     * sets hooks for running rest of system
67
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
68
-     * starting EE Addons from any other point may lead to problems
69
-     *
70
-     * @param EE_Request  $request
71
-     * @param EE_Response $response
72
-     * @return EE_Response
73
-     * @throws EE_Error
74
-     * @throws InvalidDataTypeException
75
-     * @throws InvalidInterfaceException
76
-     * @throws InvalidArgumentException
77
-     */
78
-    public function handle_request(EE_Request $request, EE_Response $response)
79
-    {
80
-        $this->request = $request;
81
-        $this->response = $response;
82
-        // info about how to load classes required by other classes
83
-        $this->dependency_map = $this->_load_dependency_map();
84
-        // central repository for classes
85
-        $this->registry = $this->_load_registry();
86
-        // PSR4 Autoloaders
87
-        $this->registry->load_core('EE_Psr4AutoloaderInit');
88
-        do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading');
89
-        $this->loader = $this->registry->create('EventEspresso\core\services\loaders\Loader');
90
-        $this->dependency_map->setLoader($this->loader);
91
-        // build DI container
92
-        $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop();
93
-        $OpenCoffeeShop->addRecipes();
94
-        // $CoffeeShop = $OpenCoffeeShop->CoffeeShop();
95
-        // create and cache the CommandBus, and also add middleware
96
-        $this->registry->create(
97
-            'CommandBusInterface',
98
-            array(
99
-                null,
100
-                apply_filters(
101
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
102
-                    array(
103
-                        $this->registry->create('CapChecker'),
104
-                        $this->registry->create('AddActionHook'),
105
-                    )
106
-                ),
107
-            ),
108
-            true
109
-        );
110
-        // workarounds for PHP < 5.3
111
-        $this->_load_class_tools();
112
-        // load interfaces
113
-        espresso_load_required('EEI_Payment_Method_Interfaces',
114
-            EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php');
115
-        // deprecated functions
116
-        espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
117
-        // WP cron jobs
118
-        $this->registry->load_core('Cron_Tasks');
119
-        $this->registry->load_core('EE_Request_Handler');
120
-        $this->registry->load_core('EE_System');
121
-        return $this->response;
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * @return EE_Request
128
-     */
129
-    public function request()
130
-    {
131
-        return $this->request;
132
-    }
133
-
134
-
135
-
136
-    /**
137
-     * @return EE_Response
138
-     */
139
-    public function response()
140
-    {
141
-        return $this->response;
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     * @return EE_Dependency_Map
148
-     * @throws EE_Error
149
-     */
150
-    public function dependency_map()
151
-    {
152
-        if (! $this->dependency_map instanceof EE_Dependency_Map) {
153
-            throw new EE_Error(
154
-                sprintf(
155
-                    __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
156
-                    print_r($this->dependency_map, true)
157
-                )
158
-            );
159
-        }
160
-        return $this->dependency_map;
161
-    }
162
-
163
-
164
-
165
-    /**
166
-     * @return EE_Registry
167
-     * @throws EE_Error
168
-     */
169
-    public function registry()
170
-    {
171
-        if (! $this->registry instanceof EE_Registry) {
172
-            throw new EE_Error(
173
-                sprintf(
174
-                    __('Invalid EE_Registry: "%1$s"', 'event_espresso'),
175
-                    print_r($this->registry, true)
176
-                )
177
-            );
178
-        }
179
-        return $this->registry;
180
-    }
181
-
182
-
183
-
184
-    /**
185
-     * @return EE_Dependency_Map
186
-     */
187
-    private function _load_dependency_map()
188
-    {
189
-        if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
190
-            EE_Error::add_error(
191
-                __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
192
-                __FILE__, __FUNCTION__, __LINE__
193
-            );
194
-            wp_die(EE_Error::get_notices());
195
-        }
196
-        require_once(EE_CORE . 'EE_Dependency_Map.core.php');
197
-        return EE_Dependency_Map::instance($this->request, $this->response);
198
-    }
199
-
200
-
201
-
202
-    /**
203
-     * @return EE_Registry
204
-     */
205
-    private function _load_registry()
206
-    {
207
-        if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
208
-            EE_Error::add_error(
209
-                __('The EE_Registry core class could not be loaded.', 'event_espresso'),
210
-                __FILE__, __FUNCTION__, __LINE__
211
-            );
212
-            wp_die(EE_Error::get_notices());
213
-        }
214
-        require_once(EE_CORE . 'EE_Registry.core.php');
215
-        return EE_Registry::instance($this->dependency_map);
216
-    }
217
-
218
-
219
-
220
-    /**
221
-     * @return void
222
-     */
223
-    private function _load_class_tools()
224
-    {
225
-        if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
226
-            EE_Error::add_error(
227
-                __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
228
-                __FILE__, __FUNCTION__, __LINE__
229
-            );
230
-        }
231
-        require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
232
-    }
233
-
234
-
235
-
236
-    /**
237
-     * called after the request stack has been fully processed
238
-     * if any of the middleware apps has requested the plugin be deactivated, then we do that now
239
-     *
240
-     * @param EE_Request  $request
241
-     * @param EE_Response $response
242
-     */
243
-    public function handle_response(EE_Request $request, EE_Response $response)
244
-    {
245
-        if ($response->plugin_deactivated()) {
246
-            espresso_deactivate_plugin(EE_PLUGIN_BASENAME);
247
-        }
248
-    }
27
+	/**
28
+	 * @type LoaderInterface $loader
29
+	 */
30
+	protected $loader;
31
+
32
+	/**
33
+	 * @var EE_Request $request
34
+	 */
35
+	protected $request;
36
+
37
+	/**
38
+	 * @var EE_Response $response
39
+	 */
40
+	protected $response;
41
+
42
+	/**
43
+	 * @var EE_Dependency_Map $dependency_map
44
+	 */
45
+	protected $dependency_map;
46
+
47
+	/**
48
+	 * @var EE_Registry $registry
49
+	 */
50
+	protected $registry;
51
+
52
+
53
+
54
+	/**
55
+	 * EE_Load_Espresso_Core constructor
56
+	 */
57
+	public function __construct()
58
+	{
59
+		espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php');
60
+	}
61
+
62
+
63
+
64
+	/**
65
+	 * handle
66
+	 * sets hooks for running rest of system
67
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
68
+	 * starting EE Addons from any other point may lead to problems
69
+	 *
70
+	 * @param EE_Request  $request
71
+	 * @param EE_Response $response
72
+	 * @return EE_Response
73
+	 * @throws EE_Error
74
+	 * @throws InvalidDataTypeException
75
+	 * @throws InvalidInterfaceException
76
+	 * @throws InvalidArgumentException
77
+	 */
78
+	public function handle_request(EE_Request $request, EE_Response $response)
79
+	{
80
+		$this->request = $request;
81
+		$this->response = $response;
82
+		// info about how to load classes required by other classes
83
+		$this->dependency_map = $this->_load_dependency_map();
84
+		// central repository for classes
85
+		$this->registry = $this->_load_registry();
86
+		// PSR4 Autoloaders
87
+		$this->registry->load_core('EE_Psr4AutoloaderInit');
88
+		do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading');
89
+		$this->loader = $this->registry->create('EventEspresso\core\services\loaders\Loader');
90
+		$this->dependency_map->setLoader($this->loader);
91
+		// build DI container
92
+		$OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop();
93
+		$OpenCoffeeShop->addRecipes();
94
+		// $CoffeeShop = $OpenCoffeeShop->CoffeeShop();
95
+		// create and cache the CommandBus, and also add middleware
96
+		$this->registry->create(
97
+			'CommandBusInterface',
98
+			array(
99
+				null,
100
+				apply_filters(
101
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
102
+					array(
103
+						$this->registry->create('CapChecker'),
104
+						$this->registry->create('AddActionHook'),
105
+					)
106
+				),
107
+			),
108
+			true
109
+		);
110
+		// workarounds for PHP < 5.3
111
+		$this->_load_class_tools();
112
+		// load interfaces
113
+		espresso_load_required('EEI_Payment_Method_Interfaces',
114
+			EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php');
115
+		// deprecated functions
116
+		espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
117
+		// WP cron jobs
118
+		$this->registry->load_core('Cron_Tasks');
119
+		$this->registry->load_core('EE_Request_Handler');
120
+		$this->registry->load_core('EE_System');
121
+		return $this->response;
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * @return EE_Request
128
+	 */
129
+	public function request()
130
+	{
131
+		return $this->request;
132
+	}
133
+
134
+
135
+
136
+	/**
137
+	 * @return EE_Response
138
+	 */
139
+	public function response()
140
+	{
141
+		return $this->response;
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 * @return EE_Dependency_Map
148
+	 * @throws EE_Error
149
+	 */
150
+	public function dependency_map()
151
+	{
152
+		if (! $this->dependency_map instanceof EE_Dependency_Map) {
153
+			throw new EE_Error(
154
+				sprintf(
155
+					__('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
156
+					print_r($this->dependency_map, true)
157
+				)
158
+			);
159
+		}
160
+		return $this->dependency_map;
161
+	}
162
+
163
+
164
+
165
+	/**
166
+	 * @return EE_Registry
167
+	 * @throws EE_Error
168
+	 */
169
+	public function registry()
170
+	{
171
+		if (! $this->registry instanceof EE_Registry) {
172
+			throw new EE_Error(
173
+				sprintf(
174
+					__('Invalid EE_Registry: "%1$s"', 'event_espresso'),
175
+					print_r($this->registry, true)
176
+				)
177
+			);
178
+		}
179
+		return $this->registry;
180
+	}
181
+
182
+
183
+
184
+	/**
185
+	 * @return EE_Dependency_Map
186
+	 */
187
+	private function _load_dependency_map()
188
+	{
189
+		if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
190
+			EE_Error::add_error(
191
+				__('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
192
+				__FILE__, __FUNCTION__, __LINE__
193
+			);
194
+			wp_die(EE_Error::get_notices());
195
+		}
196
+		require_once(EE_CORE . 'EE_Dependency_Map.core.php');
197
+		return EE_Dependency_Map::instance($this->request, $this->response);
198
+	}
199
+
200
+
201
+
202
+	/**
203
+	 * @return EE_Registry
204
+	 */
205
+	private function _load_registry()
206
+	{
207
+		if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
208
+			EE_Error::add_error(
209
+				__('The EE_Registry core class could not be loaded.', 'event_espresso'),
210
+				__FILE__, __FUNCTION__, __LINE__
211
+			);
212
+			wp_die(EE_Error::get_notices());
213
+		}
214
+		require_once(EE_CORE . 'EE_Registry.core.php');
215
+		return EE_Registry::instance($this->dependency_map);
216
+	}
217
+
218
+
219
+
220
+	/**
221
+	 * @return void
222
+	 */
223
+	private function _load_class_tools()
224
+	{
225
+		if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
226
+			EE_Error::add_error(
227
+				__('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
228
+				__FILE__, __FUNCTION__, __LINE__
229
+			);
230
+		}
231
+		require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
232
+	}
233
+
234
+
235
+
236
+	/**
237
+	 * called after the request stack has been fully processed
238
+	 * if any of the middleware apps has requested the plugin be deactivated, then we do that now
239
+	 *
240
+	 * @param EE_Request  $request
241
+	 * @param EE_Response $response
242
+	 */
243
+	public function handle_response(EE_Request $request, EE_Response $response)
244
+	{
245
+		if ($response->plugin_deactivated()) {
246
+			espresso_deactivate_plugin(EE_PLUGIN_BASENAME);
247
+		}
248
+	}
249 249
 
250 250
 
251 251
 
Please login to merge, or discard this patch.
core/EE_Registry.core.php 2 patches
Indentation   +1390 added lines, -1390 removed lines patch added patch discarded remove patch
@@ -16,1426 +16,1426 @@
 block discarded – undo
16 16
 class EE_Registry
17 17
 {
18 18
 
19
-    /**
20
-     *    EE_Registry Object
21
-     *
22
-     * @var EE_Registry $_instance
23
-     * @access    private
24
-     */
25
-    private static $_instance = null;
26
-
27
-    /**
28
-     * @var EE_Dependency_Map $_dependency_map
29
-     * @access    protected
30
-     */
31
-    protected $_dependency_map = null;
32
-
33
-    /**
34
-     * @var array $_class_abbreviations
35
-     * @access    protected
36
-     */
37
-    protected $_class_abbreviations = array();
38
-
39
-    /**
40
-     * @access public
41
-     * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS
42
-     */
43
-    public $BUS;
44
-
45
-    /**
46
-     *    EE_Cart Object
47
-     *
48
-     * @access    public
49
-     * @var    EE_Cart $CART
50
-     */
51
-    public $CART = null;
52
-
53
-    /**
54
-     *    EE_Config Object
55
-     *
56
-     * @access    public
57
-     * @var    EE_Config $CFG
58
-     */
59
-    public $CFG = null;
60
-
61
-    /**
62
-     * EE_Network_Config Object
63
-     *
64
-     * @access public
65
-     * @var EE_Network_Config $NET_CFG
66
-     */
67
-    public $NET_CFG = null;
68
-
69
-    /**
70
-     *    StdClass object for storing library classes in
71
-     *
72
-     * @public LIB
73
-     * @var StdClass $LIB
74
-     */
75
-    public $LIB = null;
76
-
77
-    /**
78
-     *    EE_Request_Handler Object
79
-     *
80
-     * @access    public
81
-     * @var    EE_Request_Handler $REQ
82
-     */
83
-    public $REQ = null;
84
-
85
-    /**
86
-     *    EE_Session Object
87
-     *
88
-     * @access    public
89
-     * @var    EE_Session $SSN
90
-     */
91
-    public $SSN = null;
92
-
93
-    /**
94
-     * holds the ee capabilities object.
95
-     *
96
-     * @since 4.5.0
97
-     * @var EE_Capabilities
98
-     */
99
-    public $CAP = null;
100
-
101
-    /**
102
-     * holds the EE_Message_Resource_Manager object.
103
-     *
104
-     * @since 4.9.0
105
-     * @var EE_Message_Resource_Manager
106
-     */
107
-    public $MRM = null;
108
-
109
-
110
-    /**
111
-     * Holds the Assets Registry instance
112
-     * @var Registry
113
-     */
114
-    public $AssetsRegistry = null;
115
-
116
-    /**
117
-     *    $addons - StdClass object for holding addons which have registered themselves to work with EE core
118
-     *
119
-     * @access    public
120
-     * @var    EE_Addon[]
121
-     */
122
-    public $addons = null;
123
-
124
-    /**
125
-     *    $models
126
-     * @access    public
127
-     * @var    EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
128
-     */
129
-    public $models = array();
130
-
131
-    /**
132
-     *    $modules
133
-     * @access    public
134
-     * @var    EED_Module[] $modules
135
-     */
136
-    public $modules = null;
137
-
138
-    /**
139
-     *    $shortcodes
140
-     * @access    public
141
-     * @var    EES_Shortcode[] $shortcodes
142
-     */
143
-    public $shortcodes = null;
144
-
145
-    /**
146
-     *    $widgets
147
-     * @access    public
148
-     * @var    WP_Widget[] $widgets
149
-     */
150
-    public $widgets = null;
151
-
152
-    /**
153
-     * $non_abstract_db_models
154
-     * @access public
155
-     * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models
156
-     * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
157
-     * Keys are model "short names" (eg "Event") as used in model relations, and values are
158
-     * classnames (eg "EEM_Event")
159
-     */
160
-    public $non_abstract_db_models = array();
161
-
162
-
163
-    /**
164
-     *    $i18n_js_strings - internationalization for JS strings
165
-     *    usage:   EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' );
166
-     *    in js file:  var translatedString = eei18n.string_key;
167
-     *
168
-     * @access    public
169
-     * @var    array
170
-     */
171
-    public static $i18n_js_strings = array();
172
-
173
-
174
-    /**
175
-     *    $main_file - path to espresso.php
176
-     *
177
-     * @access    public
178
-     * @var    array
179
-     */
180
-    public $main_file;
181
-
182
-    /**
183
-     * array of ReflectionClass objects where the key is the class name
184
-     *
185
-     * @access    public
186
-     * @var ReflectionClass[]
187
-     */
188
-    public $_reflectors;
189
-
190
-    /**
191
-     * boolean flag to indicate whether or not to load/save dependencies from/to the cache
192
-     *
193
-     * @access    protected
194
-     * @var boolean $_cache_on
195
-     */
196
-    protected $_cache_on = true;
197
-
198
-
199
-
200
-    /**
201
-     * @singleton method used to instantiate class object
202
-     * @access    public
203
-     * @param  \EE_Dependency_Map $dependency_map
204
-     * @return \EE_Registry instance
205
-     */
206
-    public static function instance(\EE_Dependency_Map $dependency_map = null)
207
-    {
208
-        // check if class object is instantiated
209
-        if ( ! self::$_instance instanceof EE_Registry) {
210
-            self::$_instance = new EE_Registry($dependency_map);
211
-        }
212
-        return self::$_instance;
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     *protected constructor to prevent direct creation
219
-     *
220
-     * @Constructor
221
-     * @access protected
222
-     * @param  \EE_Dependency_Map $dependency_map
223
-     */
224
-    protected function __construct(\EE_Dependency_Map $dependency_map)
225
-    {
226
-        $this->_dependency_map = $dependency_map;
227
-        $this->LIB = new stdClass();
228
-        $this->addons = new stdClass();
229
-        $this->modules = new stdClass();
230
-        $this->shortcodes = new stdClass();
231
-        $this->widgets = new stdClass();
232
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
233
-    }
234
-
235
-
236
-
237
-    /**
238
-     * initialize
239
-     */
240
-    public function initialize()
241
-    {
242
-        $this->_class_abbreviations = apply_filters(
243
-            'FHEE__EE_Registry____construct___class_abbreviations',
244
-            array(
245
-                'EE_Config'                                       => 'CFG',
246
-                'EE_Session'                                      => 'SSN',
247
-                'EE_Capabilities'                                 => 'CAP',
248
-                'EE_Cart'                                         => 'CART',
249
-                'EE_Network_Config'                               => 'NET_CFG',
250
-                'EE_Request_Handler'                              => 'REQ',
251
-                'EE_Message_Resource_Manager'                     => 'MRM',
252
-                'EventEspresso\core\services\commands\CommandBus' => 'BUS',
253
-                'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
254
-            )
255
-        );
256
-        $this->load_core('Base', array(), true);
257
-        // add our request and response objects to the cache
258
-        $request_loader = $this->_dependency_map->class_loader('EE_Request');
259
-        $this->_set_cached_class(
260
-            $request_loader(),
261
-            'EE_Request'
262
-        );
263
-        $response_loader = $this->_dependency_map->class_loader('EE_Response');
264
-        $this->_set_cached_class(
265
-            $response_loader(),
266
-            'EE_Response'
267
-        );
268
-        add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
269
-    }
270
-
271
-
272
-
273
-    /**
274
-     *    init
275
-     *
276
-     * @access    public
277
-     * @return    void
278
-     */
279
-    public function init()
280
-    {
281
-        // Get current page protocol
282
-        $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
283
-        // Output admin-ajax.php URL with same protocol as current page
284
-        self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
285
-        self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
286
-    }
287
-
288
-
289
-
290
-    /**
291
-     * localize_i18n_js_strings
292
-     *
293
-     * @return string
294
-     */
295
-    public static function localize_i18n_js_strings()
296
-    {
297
-        $i18n_js_strings = (array)EE_Registry::$i18n_js_strings;
298
-        foreach ($i18n_js_strings as $key => $value) {
299
-            if (is_scalar($value)) {
300
-                $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
301
-            }
302
-        }
303
-        return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
304
-    }
305
-
306
-
307
-
308
-    /**
309
-     * @param mixed string | EED_Module $module
310
-     */
311
-    public function add_module($module)
312
-    {
313
-        if ($module instanceof EED_Module) {
314
-            $module_class = get_class($module);
315
-            $this->modules->{$module_class} = $module;
316
-        } else {
317
-            if ( ! class_exists('EE_Module_Request_Router')) {
318
-                $this->load_core('Module_Request_Router');
319
-            }
320
-            $this->modules->{$module} = EE_Module_Request_Router::module_factory($module);
321
-        }
322
-    }
323
-
324
-
325
-
326
-    /**
327
-     * @param string $module_name
328
-     * @return mixed EED_Module | NULL
329
-     */
330
-    public function get_module($module_name = '')
331
-    {
332
-        return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null;
333
-    }
334
-
335
-
336
-
337
-    /**
338
-     *    loads core classes - must be singletons
339
-     *
340
-     * @access    public
341
-     * @param string $class_name - simple class name ie: session
342
-     * @param mixed  $arguments
343
-     * @param bool   $load_only
344
-     * @return mixed
345
-     */
346
-    public function load_core($class_name, $arguments = array(), $load_only = false)
347
-    {
348
-        $core_paths = apply_filters(
349
-            'FHEE__EE_Registry__load_core__core_paths',
350
-            array(
351
-                EE_CORE,
352
-                EE_ADMIN,
353
-                EE_CPTS,
354
-                EE_CORE . 'data_migration_scripts' . DS,
355
-                EE_CORE . 'request_stack' . DS,
356
-                EE_CORE . 'middleware' . DS,
357
-            )
358
-        );
359
-        // retrieve instantiated class
360
-        return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only);
361
-    }
362
-
363
-
364
-
365
-    /**
366
-     *    loads service classes
367
-     *
368
-     * @access    public
369
-     * @param string $class_name - simple class name ie: session
370
-     * @param mixed  $arguments
371
-     * @param bool   $load_only
372
-     * @return mixed
373
-     */
374
-    public function load_service($class_name, $arguments = array(), $load_only = false)
375
-    {
376
-        $service_paths = apply_filters(
377
-            'FHEE__EE_Registry__load_service__service_paths',
378
-            array(
379
-                EE_CORE . 'services' . DS,
380
-            )
381
-        );
382
-        // retrieve instantiated class
383
-        return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only);
384
-    }
385
-
386
-
387
-
388
-    /**
389
-     *    loads data_migration_scripts
390
-     *
391
-     * @access    public
392
-     * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
393
-     * @param mixed  $arguments
394
-     * @return EE_Data_Migration_Script_Base|mixed
395
-     */
396
-    public function load_dms($class_name, $arguments = array())
397
-    {
398
-        // retrieve instantiated class
399
-        return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false);
400
-    }
401
-
402
-
403
-
404
-    /**
405
-     *    loads object creating classes - must be singletons
406
-     *
407
-     * @param string $class_name - simple class name ie: attendee
408
-     * @param mixed  $arguments  - an array of arguments to pass to the class
409
-     * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to instantiate
410
-     * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop)
411
-     * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate (default)
412
-     * @return EE_Base_Class | bool
413
-     */
414
-    public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
415
-    {
416
-        $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array(
417
-            EE_CORE,
418
-            EE_CLASSES,
419
-            EE_BUSINESS,
420
-        ));
421
-        // retrieve instantiated class
422
-        return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only);
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     *    loads helper classes - must be singletons
429
-     *
430
-     * @param string $class_name - simple class name ie: price
431
-     * @param mixed  $arguments
432
-     * @param bool   $load_only
433
-     * @return EEH_Base | bool
434
-     */
435
-    public function load_helper($class_name, $arguments = array(), $load_only = true)
436
-    {
437
-        // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
438
-        $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
439
-        // retrieve instantiated class
440
-        return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only);
441
-    }
442
-
443
-
444
-
445
-    /**
446
-     *    loads core classes - must be singletons
447
-     *
448
-     * @access    public
449
-     * @param string $class_name - simple class name ie: session
450
-     * @param mixed  $arguments
451
-     * @param bool   $load_only
452
-     * @param bool   $cache      whether to cache the object or not.
453
-     * @return mixed
454
-     */
455
-    public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
456
-    {
457
-        $paths = array(
458
-            EE_LIBRARIES,
459
-            EE_LIBRARIES . 'messages' . DS,
460
-            EE_LIBRARIES . 'shortcodes' . DS,
461
-            EE_LIBRARIES . 'qtips' . DS,
462
-            EE_LIBRARIES . 'payment_methods' . DS,
463
-        );
464
-        // retrieve instantiated class
465
-        return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only);
466
-    }
467
-
468
-
469
-
470
-    /**
471
-     *    loads model classes - must be singletons
472
-     *
473
-     * @param string $class_name - simple class name ie: price
474
-     * @param mixed  $arguments
475
-     * @param bool   $load_only
476
-     * @return EEM_Base | bool
477
-     */
478
-    public function load_model($class_name, $arguments = array(), $load_only = false)
479
-    {
480
-        $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array(
481
-            EE_MODELS,
482
-            EE_CORE,
483
-        ));
484
-        // retrieve instantiated class
485
-        return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only);
486
-    }
487
-
488
-
489
-
490
-    /**
491
-     *    loads model classes - must be singletons
492
-     *
493
-     * @param string $class_name - simple class name ie: price
494
-     * @param mixed  $arguments
495
-     * @param bool   $load_only
496
-     * @return mixed | bool
497
-     */
498
-    public function load_model_class($class_name, $arguments = array(), $load_only = true)
499
-    {
500
-        $paths = array(
501
-            EE_MODELS . 'fields' . DS,
502
-            EE_MODELS . 'helpers' . DS,
503
-            EE_MODELS . 'relations' . DS,
504
-            EE_MODELS . 'strategies' . DS,
505
-        );
506
-        // retrieve instantiated class
507
-        return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only);
508
-    }
509
-
510
-
511
-
512
-    /**
513
-     * Determines if $model_name is the name of an actual EE model.
514
-     *
515
-     * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
516
-     * @return boolean
517
-     */
518
-    public function is_model_name($model_name)
519
-    {
520
-        return isset($this->models[$model_name]) ? true : false;
521
-    }
522
-
523
-
524
-
525
-    /**
526
-     *    generic class loader
527
-     *
528
-     * @param string $path_to_file - directory path to file location, not including filename
529
-     * @param string $file_name    - file name  ie:  my_file.php, including extension
530
-     * @param string $type         - file type - core? class? helper? model?
531
-     * @param mixed  $arguments
532
-     * @param bool   $load_only
533
-     * @return mixed
534
-     */
535
-    public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
536
-    {
537
-        // retrieve instantiated class
538
-        return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only);
539
-    }
540
-
541
-
542
-
543
-    /**
544
-     *    load_addon
545
-     *
546
-     * @param string $path_to_file - directory path to file location, not including filename
547
-     * @param string $class_name   - full class name  ie:  My_Class
548
-     * @param string $type         - file type - core? class? helper? model?
549
-     * @param mixed  $arguments
550
-     * @param bool   $load_only
551
-     * @return EE_Addon
552
-     */
553
-    public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
554
-    {
555
-        // retrieve instantiated class
556
-        return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only);
557
-    }
558
-
559
-
560
-
561
-    /**
562
-     * instantiates, caches, and automatically resolves dependencies
563
-     * for classes that use a Fully Qualified Class Name.
564
-     * if the class is not capable of being loaded using PSR-4 autoloading,
565
-     * then you need to use one of the existing load_*() methods
566
-     * which can resolve the classname and filepath from the passed arguments
567
-     *
568
-     * @param bool|string $class_name   Fully Qualified Class Name
569
-     * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
570
-     * @param bool        $cache        whether to cache the instantiated object for reuse
571
-     * @param bool        $from_db      some classes are instantiated from the db
572
-     *                                  and thus call a different method to instantiate
573
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
574
-     * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
575
-     * @return mixed                    null = failure to load or instantiate class object.
576
-     *                                  object = class loaded and instantiated successfully.
577
-     *                                  bool = fail or success when $load_only is true
578
-     */
579
-    public function create(
580
-        $class_name = false,
581
-        $arguments = array(),
582
-        $cache = false,
583
-        $from_db = false,
584
-        $load_only = false,
585
-        $addon = false
586
-    ) {
587
-        $class_name = ltrim($class_name, '\\');
588
-        $class_name = $this->_dependency_map->get_alias($class_name);
589
-        if ( ! class_exists($class_name)) {
590
-            // maybe the class is registered with a preceding \
591
-            $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name;
592
-            // still doesn't exist ?
593
-            if ( ! class_exists($class_name)) {
594
-                return null;
595
-            }
596
-        }
597
-        // if we're only loading the class and it already exists, then let's just return true immediately
598
-        if ($load_only) {
599
-            return true;
600
-        }
601
-        $addon = $addon ? 'addon' : '';
602
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
603
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
604
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
605
-        if ($this->_cache_on && $cache && ! $load_only) {
606
-            // return object if it's already cached
607
-            $cached_class = $this->_get_cached_class($class_name, $addon);
608
-            if ($cached_class !== null) {
609
-                return $cached_class;
610
-            }
611
-        }
612
-        // instantiate the requested object
613
-        $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
614
-        if ($this->_cache_on && $cache) {
615
-            // save it for later... kinda like gum  { : $
616
-            $this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
617
-        }
618
-        $this->_cache_on = true;
619
-        return $class_obj;
620
-    }
621
-
622
-
623
-
624
-    /**
625
-     * instantiates, caches, and injects dependencies for classes
626
-     *
627
-     * @param array       $file_paths   an array of paths to folders to look in
628
-     * @param string      $class_prefix EE  or EEM or... ???
629
-     * @param bool|string $class_name   $class name
630
-     * @param string      $type         file type - core? class? helper? model?
631
-     * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
632
-     * @param bool        $from_db      some classes are instantiated from the db
633
-     *                                  and thus call a different method to instantiate
634
-     * @param bool        $cache        whether to cache the instantiated object for reuse
635
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
636
-     * @return null|object|bool         null = failure to load or instantiate class object.
637
-     *                                  object = class loaded and instantiated successfully.
638
-     *                                  bool = fail or success when $load_only is true
639
-     */
640
-    protected function _load(
641
-        $file_paths = array(),
642
-        $class_prefix = 'EE_',
643
-        $class_name = false,
644
-        $type = 'class',
645
-        $arguments = array(),
646
-        $from_db = false,
647
-        $cache = true,
648
-        $load_only = false
649
-    ) {
650
-        $class_name = ltrim($class_name, '\\');
651
-        // strip php file extension
652
-        $class_name = str_replace('.php', '', trim($class_name));
653
-        // does the class have a prefix ?
654
-        if ( ! empty($class_prefix) && $class_prefix != 'addon') {
655
-            // make sure $class_prefix is uppercase
656
-            $class_prefix = strtoupper(trim($class_prefix));
657
-            // add class prefix ONCE!!!
658
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
659
-        }
660
-        $class_name = $this->_dependency_map->get_alias($class_name);
661
-        $class_exists = class_exists($class_name);
662
-        // if we're only loading the class and it already exists, then let's just return true immediately
663
-        if ($load_only && $class_exists) {
664
-            return true;
665
-        }
666
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
667
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
668
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
669
-        if ($this->_cache_on && $cache && ! $load_only) {
670
-            // return object if it's already cached
671
-            $cached_class = $this->_get_cached_class($class_name, $class_prefix);
672
-            if ($cached_class !== null) {
673
-                return $cached_class;
674
-            }
675
-        }
676
-        // if the class doesn't already exist.. then we need to try and find the file and load it
677
-        if ( ! $class_exists) {
678
-            // get full path to file
679
-            $path = $this->_resolve_path($class_name, $type, $file_paths);
680
-            // load the file
681
-            $loaded = $this->_require_file($path, $class_name, $type, $file_paths);
682
-            // if loading failed, or we are only loading a file but NOT instantiating an object
683
-            if ( ! $loaded || $load_only) {
684
-                // return boolean if only loading, or null if an object was expected
685
-                return $load_only ? $loaded : null;
686
-            }
687
-        }
688
-        // instantiate the requested object
689
-        $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
690
-        if ($this->_cache_on && $cache) {
691
-            // save it for later... kinda like gum  { : $
692
-            $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
693
-        }
694
-        $this->_cache_on = true;
695
-        return $class_obj;
696
-    }
697
-
698
-
699
-
700
-
701
-    /**
702
-     * _get_cached_class
703
-     * attempts to find a cached version of the requested class
704
-     * by looking in the following places:
705
-     *        $this->{$class_abbreviation}            ie:    $this->CART
706
-     *        $this->{$class_name}                        ie:    $this->Some_Class
707
-     *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
708
-     *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
709
-     *
710
-     * @access protected
711
-     * @param string $class_name
712
-     * @param string $class_prefix
713
-     * @return mixed
714
-     */
715
-    protected function _get_cached_class($class_name, $class_prefix = '')
716
-    {
717
-        // have to specify something, but not anything that will conflict
718
-        $class_abbreviation = isset($this->_class_abbreviations[ $class_name ])
719
-            ? $this->_class_abbreviations[ $class_name ]
720
-            : 'FANCY_BATMAN_PANTS';
721
-        $class_name = str_replace('\\', '_', $class_name);
722
-        // check if class has already been loaded, and return it if it has been
723
-        if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) {
724
-            return $this->{$class_abbreviation};
725
-        }
726
-        if (isset ($this->{$class_name})) {
727
-            return $this->{$class_name};
728
-        }
729
-        if (isset ($this->LIB->{$class_name})) {
730
-            return $this->LIB->{$class_name};
731
-        }
732
-        if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
733
-            return $this->addons->{$class_name};
734
-        }
735
-        return null;
736
-    }
737
-
738
-
739
-
740
-    /**
741
-     * removes a cached version of the requested class
742
-     *
743
-     * @param string $class_name
744
-     * @param boolean $addon
745
-     * @return boolean
746
-     */
747
-    public function clear_cached_class($class_name, $addon = false)
748
-    {
749
-        // have to specify something, but not anything that will conflict
750
-        $class_abbreviation = isset($this->_class_abbreviations[ $class_name ])
751
-            ? $this->_class_abbreviations[ $class_name ]
752
-            : 'FANCY_BATMAN_PANTS';
753
-        $class_name = str_replace('\\', '_', $class_name);
754
-        // check if class has already been loaded, and return it if it has been
755
-        if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) {
756
-            $this->{$class_abbreviation} = null;
757
-            return true;
758
-        }
759
-        if (isset($this->{$class_name})) {
760
-            $this->{$class_name} = null;
761
-            return true;
762
-        }
763
-        if (isset($this->LIB->{$class_name})) {
764
-            unset($this->LIB->{$class_name});
765
-            return true;
766
-        }
767
-        if ($addon && isset($this->addons->{$class_name})) {
768
-            unset($this->addons->{$class_name});
769
-            return true;
770
-        }
771
-        return false;
772
-    }
773
-
774
-
775
-    /**
776
-     * _resolve_path
777
-     * attempts to find a full valid filepath for the requested class.
778
-     * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
779
-     * then returns that path if the target file has been found and is readable
780
-     *
781
-     * @access protected
782
-     * @param string $class_name
783
-     * @param string $type
784
-     * @param array  $file_paths
785
-     * @return string | bool
786
-     */
787
-    protected function _resolve_path($class_name, $type = '', $file_paths = array())
788
-    {
789
-        // make sure $file_paths is an array
790
-        $file_paths = is_array($file_paths) ? $file_paths : array($file_paths);
791
-        // cycle thru paths
792
-        foreach ($file_paths as $key => $file_path) {
793
-            // convert all separators to proper DS, if no filepath, then use EE_CLASSES
794
-            $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES;
795
-            // prep file type
796
-            $type = ! empty($type) ? trim($type, '.') . '.' : '';
797
-            // build full file path
798
-            $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
799
-            //does the file exist and can be read ?
800
-            if (is_readable($file_paths[$key])) {
801
-                return $file_paths[$key];
802
-            }
803
-        }
804
-        return false;
805
-    }
806
-
807
-
808
-
809
-    /**
810
-     * _require_file
811
-     * basically just performs a require_once()
812
-     * but with some error handling
813
-     *
814
-     * @access protected
815
-     * @param  string $path
816
-     * @param  string $class_name
817
-     * @param  string $type
818
-     * @param  array  $file_paths
819
-     * @return boolean
820
-     * @throws \EE_Error
821
-     */
822
-    protected function _require_file($path, $class_name, $type = '', $file_paths = array())
823
-    {
824
-        // don't give up! you gotta...
825
-        try {
826
-            //does the file exist and can it be read ?
827
-            if ( ! $path) {
828
-                // so sorry, can't find the file
829
-                throw new EE_Error (
830
-                    sprintf(
831
-                        __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'),
832
-                        trim($type, '.'),
833
-                        $class_name,
834
-                        '<br />' . implode(',<br />', $file_paths)
835
-                    )
836
-                );
837
-            }
838
-            // get the file
839
-            require_once($path);
840
-            // if the class isn't already declared somewhere
841
-            if (class_exists($class_name, false) === false) {
842
-                // so sorry, not a class
843
-                throw new EE_Error(
844
-                    sprintf(
845
-                        __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
846
-                        $type,
847
-                        $path,
848
-                        $class_name
849
-                    )
850
-                );
851
-            }
852
-        } catch (EE_Error $e) {
853
-            $e->get_error();
854
-            return false;
855
-        }
856
-        return true;
857
-    }
858
-
859
-
860
-
861
-    /**
862
-     * _create_object
863
-     * Attempts to instantiate the requested class via any of the
864
-     * commonly used instantiation methods employed throughout EE.
865
-     * The priority for instantiation is as follows:
866
-     *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
867
-     *        - model objects via their 'new_instance_from_db' method
868
-     *        - model objects via their 'new_instance' method
869
-     *        - "singleton" classes" via their 'instance' method
870
-     *    - standard instantiable classes via their __constructor
871
-     * Prior to instantiation, if the classname exists in the dependency_map,
872
-     * then the constructor for the requested class will be examined to determine
873
-     * if any dependencies exist, and if they can be injected.
874
-     * If so, then those classes will be added to the array of arguments passed to the constructor
875
-     *
876
-     * @access protected
877
-     * @param string $class_name
878
-     * @param array  $arguments
879
-     * @param string $type
880
-     * @param bool   $from_db
881
-     * @return null | object
882
-     * @throws \EE_Error
883
-     */
884
-    protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
885
-    {
886
-        $class_obj = null;
887
-        $instantiation_mode = '0) none';
888
-        // don't give up! you gotta...
889
-        try {
890
-            // create reflection
891
-            $reflector = $this->get_ReflectionClass($class_name);
892
-            // make sure arguments are an array
893
-            $arguments = is_array($arguments) ? $arguments : array($arguments);
894
-            // and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
895
-            // else wrap it in an additional array so that it doesn't get split into multiple parameters
896
-            $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
897
-                ? $arguments
898
-                : array($arguments);
899
-            // attempt to inject dependencies ?
900
-            if ($this->_dependency_map->has($class_name)) {
901
-                $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
902
-            }
903
-            // instantiate the class if possible
904
-            if ($reflector->isAbstract()) {
905
-                // nothing to instantiate, loading file was enough
906
-                // does not throw an exception so $instantiation_mode is unused
907
-                // $instantiation_mode = "1) no constructor abstract class";
908
-                $class_obj = true;
909
-            } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) {
910
-                // no constructor = static methods only... nothing to instantiate, loading file was enough
911
-                $instantiation_mode = "2) no constructor but instantiable";
912
-                $class_obj = $reflector->newInstance();
913
-            } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
914
-                $instantiation_mode = "3) new_instance_from_db()";
915
-                $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
916
-            } else if (method_exists($class_name, 'new_instance')) {
917
-                $instantiation_mode = "4) new_instance()";
918
-                $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments);
919
-            } else if (method_exists($class_name, 'instance')) {
920
-                $instantiation_mode = "5) instance()";
921
-                $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments);
922
-            } else if ($reflector->isInstantiable()) {
923
-                $instantiation_mode = "6) constructor";
924
-                $class_obj = $reflector->newInstanceArgs($arguments);
925
-            } else {
926
-                // heh ? something's not right !
927
-                throw new EE_Error(
928
-                    sprintf(
929
-                        __('The %s file %s could not be instantiated.', 'event_espresso'),
930
-                        $type,
931
-                        $class_name
932
-                    )
933
-                );
934
-            }
935
-        } catch (Exception $e) {
936
-            if ( ! $e instanceof EE_Error) {
937
-                $e = new EE_Error(
938
-                    sprintf(
939
-                        __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'),
940
-                        $class_name,
941
-                        '<br />',
942
-                        $e->getMessage(),
943
-                        $instantiation_mode
944
-                    )
945
-                );
946
-            }
947
-            $e->get_error();
948
-        }
949
-        return $class_obj;
950
-    }
951
-
952
-
953
-
954
-    /**
955
-     * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
956
-     * @param array $array
957
-     * @return bool
958
-     */
959
-    protected function _array_is_numerically_and_sequentially_indexed(array $array)
960
-    {
961
-        return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true;
962
-    }
963
-
964
-
965
-
966
-    /**
967
-     * getReflectionClass
968
-     * checks if a ReflectionClass object has already been generated for a class
969
-     * and returns that instead of creating a new one
970
-     *
971
-     * @access public
972
-     * @param string $class_name
973
-     * @return ReflectionClass
974
-     */
975
-    public function get_ReflectionClass($class_name)
976
-    {
977
-        if (
978
-            ! isset($this->_reflectors[$class_name])
979
-            || ! $this->_reflectors[$class_name] instanceof ReflectionClass
980
-        ) {
981
-            $this->_reflectors[$class_name] = new ReflectionClass($class_name);
982
-        }
983
-        return $this->_reflectors[$class_name];
984
-    }
985
-
986
-
987
-
988
-    /**
989
-     * _resolve_dependencies
990
-     * examines the constructor for the requested class to determine
991
-     * if any dependencies exist, and if they can be injected.
992
-     * If so, then those classes will be added to the array of arguments passed to the constructor
993
-     * PLZ NOTE: this is achieved by type hinting the constructor params
994
-     * For example:
995
-     *        if attempting to load a class "Foo" with the following constructor:
996
-     *        __construct( Bar $bar_class, Fighter $grohl_class )
997
-     *        then $bar_class and $grohl_class will be added to the $arguments array,
998
-     *        but only IF they are NOT already present in the incoming arguments array,
999
-     *        and the correct classes can be loaded
1000
-     *
1001
-     * @access protected
1002
-     * @param ReflectionClass $reflector
1003
-     * @param string          $class_name
1004
-     * @param array           $arguments
1005
-     * @return array
1006
-     * @throws \ReflectionException
1007
-     */
1008
-    protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
1009
-    {
1010
-        // let's examine the constructor
1011
-        $constructor = $reflector->getConstructor();
1012
-        // whu? huh? nothing?
1013
-        if ( ! $constructor) {
1014
-            return $arguments;
1015
-        }
1016
-        // get constructor parameters
1017
-        $params = $constructor->getParameters();
1018
-        // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1019
-        $argument_keys = array_keys($arguments);
1020
-        // now loop thru all of the constructors expected parameters
1021
-        foreach ($params as $index => $param) {
1022
-            // is this a dependency for a specific class ?
1023
-            $param_class = $param->getClass() ? $param->getClass()->name : null;
1024
-            // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1025
-            $param_class = $this->_dependency_map->has_alias($param_class, $class_name)
1026
-                ? $this->_dependency_map->get_alias($param_class, $class_name)
1027
-                : $param_class;
1028
-            if (
1029
-                // param is not even a class
1030
-                empty($param_class)
1031
-                // and something already exists in the incoming arguments for this param
1032
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1033
-            ) {
1034
-                // so let's skip this argument and move on to the next
1035
-                continue;
1036
-            }
1037
-            if (
1038
-                // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1039
-                ! empty($param_class)
1040
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1041
-                && $arguments[$argument_keys[$index]] instanceof $param_class
1042
-            ) {
1043
-                // skip this argument and move on to the next
1044
-                continue;
1045
-            }
1046
-            if (
1047
-                // parameter is type hinted as a class, and should be injected
1048
-                ! empty($param_class)
1049
-                && $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1050
-            ) {
1051
-                $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index);
1052
-            } else {
1053
-                try {
1054
-                    $arguments[$index] = $param->getDefaultValue();
1055
-                } catch (ReflectionException $e) {
1056
-                    throw new ReflectionException(
1057
-                        sprintf(
1058
-                            __('%1$s for parameter "$%2$s"', 'event_espresso'),
1059
-                            $e->getMessage(),
1060
-                            $param->getName()
1061
-                        )
1062
-                    );
1063
-                }
1064
-            }
1065
-        }
1066
-        return $arguments;
1067
-    }
1068
-
1069
-
1070
-
1071
-    /**
1072
-     * @access protected
1073
-     * @param string $class_name
1074
-     * @param string $param_class
1075
-     * @param array  $arguments
1076
-     * @param mixed  $index
1077
-     * @return array
1078
-     */
1079
-    protected function _resolve_dependency($class_name, $param_class, $arguments, $index)
1080
-    {
1081
-        $dependency = null;
1082
-        // should dependency be loaded from cache ?
1083
-        $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class)
1084
-                    !== EE_Dependency_Map::load_new_object
1085
-            ? true
1086
-            : false;
1087
-        // we might have a dependency...
1088
-        // let's MAYBE try and find it in our cache if that's what's been requested
1089
-        $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null;
1090
-        // and grab it if it exists
1091
-        if ($cached_class instanceof $param_class) {
1092
-            $dependency = $cached_class;
1093
-        } else if ($param_class !== $class_name) {
1094
-            // obtain the loader method from the dependency map
1095
-            $loader = $this->_dependency_map->class_loader($param_class);
1096
-            // is loader a custom closure ?
1097
-            if ($loader instanceof Closure) {
1098
-                $dependency = $loader();
1099
-            } else {
1100
-                // set the cache on property for the recursive loading call
1101
-                $this->_cache_on = $cache_on;
1102
-                // if not, then let's try and load it via the registry
1103
-                if ($loader && method_exists($this, $loader)) {
1104
-                    $dependency = $this->{$loader}($param_class);
1105
-                } else {
1106
-                    $dependency = $this->create($param_class, array(), $cache_on);
1107
-                }
1108
-            }
1109
-        }
1110
-        // did we successfully find the correct dependency ?
1111
-        if ($dependency instanceof $param_class) {
1112
-            // then let's inject it into the incoming array of arguments at the correct location
1113
-            if (isset($argument_keys[$index])) {
1114
-                $arguments[$argument_keys[$index]] = $dependency;
1115
-            } else {
1116
-                $arguments[$index] = $dependency;
1117
-            }
1118
-        }
1119
-        return $arguments;
1120
-    }
1121
-
1122
-
1123
-
1124
-    /**
1125
-     * _set_cached_class
1126
-     * attempts to cache the instantiated class locally
1127
-     * in one of the following places, in the following order:
1128
-     *        $this->{class_abbreviation}   ie:    $this->CART
1129
-     *        $this->{$class_name}          ie:    $this->Some_Class
1130
-     *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1131
-     *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1132
-     *
1133
-     * @access protected
1134
-     * @param object $class_obj
1135
-     * @param string $class_name
1136
-     * @param string $class_prefix
1137
-     * @param bool   $from_db
1138
-     * @return void
1139
-     */
1140
-    protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1141
-    {
1142
-        if (empty($class_obj)) {
1143
-            return;
1144
-        }
1145
-        // return newly instantiated class
1146
-        if (isset($this->_class_abbreviations[$class_name])) {
1147
-            $class_abbreviation = $this->_class_abbreviations[$class_name];
1148
-            $this->{$class_abbreviation} = $class_obj;
1149
-            return;
1150
-        }
1151
-        $class_name = str_replace('\\', '_', $class_name);
1152
-        if (property_exists($this, $class_name)) {
1153
-            $this->{$class_name} = $class_obj;
1154
-            return;
1155
-        }
1156
-        if ($class_prefix === 'addon') {
1157
-            $this->addons->{$class_name} = $class_obj;
1158
-            return;
1159
-        }
1160
-        if ( ! $from_db) {
1161
-            $this->LIB->{$class_name} = $class_obj;
1162
-        }
1163
-    }
1164
-
1165
-
1166
-
1167
-    /**
1168
-     * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1169
-     *
1170
-     * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1171
-     *                          in the EE_Dependency_Map::$_class_loaders array,
1172
-     *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1173
-     * @param array  $arguments
1174
-     * @return object
1175
-     */
1176
-    public static function factory($classname, $arguments = array())
1177
-    {
1178
-        $loader = self::instance()->_dependency_map->class_loader($classname);
1179
-        if ($loader instanceof Closure) {
1180
-            return $loader($arguments);
1181
-        }
1182
-        if (method_exists(EE_Registry::instance(), $loader)) {
1183
-            return EE_Registry::instance()->{$loader}($classname, $arguments);
1184
-        }
1185
-        return null;
1186
-    }
1187
-
1188
-
1189
-
1190
-    /**
1191
-     * Gets the addon by its name/slug (not classname. For that, just
1192
-     * use the classname as the property name on EE_Config::instance()->addons)
1193
-     *
1194
-     * @param string $name
1195
-     * @return EE_Addon
1196
-     */
1197
-    public function get_addon_by_name($name)
1198
-    {
1199
-        foreach ($this->addons as $addon) {
1200
-            if ($addon->name() == $name) {
1201
-                return $addon;
1202
-            }
1203
-        }
1204
-        return null;
1205
-    }
1206
-
1207
-
1208
-
1209
-    /**
1210
-     * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is
1211
-     * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname}
1212
-     *
1213
-     * @return EE_Addon[] where the KEYS are the addon's name()
1214
-     */
1215
-    public function get_addons_by_name()
1216
-    {
1217
-        $addons = array();
1218
-        foreach ($this->addons as $addon) {
1219
-            $addons[$addon->name()] = $addon;
1220
-        }
1221
-        return $addons;
1222
-    }
1223
-
1224
-
1225
-
1226
-    /**
1227
-     * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1228
-     * a stale copy of it around
1229
-     *
1230
-     * @param string $model_name
1231
-     * @return \EEM_Base
1232
-     * @throws \EE_Error
1233
-     */
1234
-    public function reset_model($model_name)
1235
-    {
1236
-        $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name;
1237
-        if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1238
-            return null;
1239
-        }
1240
-        //get that model reset it and make sure we nuke the old reference to it
1241
-        if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) {
1242
-            $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1243
-        } else {
1244
-            throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1245
-        }
1246
-        return $this->LIB->{$model_class_name};
1247
-    }
1248
-
1249
-
1250
-
1251
-    /**
1252
-     * Resets the registry.
1253
-     * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog
1254
-     * is used in a multisite install.  Here is a list of things that are NOT reset.
1255
-     * - $_dependency_map
1256
-     * - $_class_abbreviations
1257
-     * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1258
-     * - $REQ:  Still on the same request so no need to change.
1259
-     * - $CAP: There is no site specific state in the EE_Capability class.
1260
-     * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session
1261
-     *         can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1262
-     * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1263
-     *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1264
-     *             switch or on the restore.
1265
-     * - $modules
1266
-     * - $shortcodes
1267
-     * - $widgets
1268
-     *
1269
-     * @param boolean $hard             whether to reset data in the database too, or just refresh
1270
-     *                                  the Registry to its state at the beginning of the request
1271
-     * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1272
-     *                                  or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN
1273
-     *                                  currently reinstantiate the singletons at the moment)
1274
-     * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so client
1275
-     *                                  code instead can just change the model context to a different blog id if necessary
1276
-     * @return EE_Registry
1277
-     */
1278
-    public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1279
-    {
1280
-        $instance = self::instance();
1281
-        EEH_Activation::reset();
1282
-        //properties that get reset
1283
-        $instance->_cache_on = true;
1284
-        $instance->CFG = EE_Config::reset($hard, $reinstantiate);
1285
-        $instance->CART = null;
1286
-        $instance->MRM = null;
1287
-        $instance->AssetsRegistry = null;
1288
-        $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1289
-        //messages reset
1290
-        EED_Messages::reset();
1291
-        if ($reset_models) {
1292
-            foreach (array_keys($instance->non_abstract_db_models) as $model_name) {
1293
-                $instance->reset_model($model_name);
1294
-            }
1295
-        }
1296
-        $instance->LIB = new stdClass();
1297
-        return $instance;
1298
-    }
1299
-
1300
-
1301
-
1302
-    /**
1303
-     * @override magic methods
1304
-     * @return void
1305
-     */
1306
-    public final function __destruct()
1307
-    {
1308
-    }
1309
-
1310
-
1311
-
1312
-    /**
1313
-     * @param $a
1314
-     * @param $b
1315
-     */
1316
-    public final function __call($a, $b)
1317
-    {
1318
-    }
1319
-
1320
-
1321
-
1322
-    /**
1323
-     * @param $a
1324
-     */
1325
-    public final function __get($a)
1326
-    {
1327
-    }
1328
-
1329
-
1330
-
1331
-    /**
1332
-     * @param $a
1333
-     * @param $b
1334
-     */
1335
-    public final function __set($a, $b)
1336
-    {
1337
-    }
1338
-
1339
-
1340
-
1341
-    /**
1342
-     * @param $a
1343
-     */
1344
-    public final function __isset($a)
1345
-    {
1346
-    }
19
+	/**
20
+	 *    EE_Registry Object
21
+	 *
22
+	 * @var EE_Registry $_instance
23
+	 * @access    private
24
+	 */
25
+	private static $_instance = null;
26
+
27
+	/**
28
+	 * @var EE_Dependency_Map $_dependency_map
29
+	 * @access    protected
30
+	 */
31
+	protected $_dependency_map = null;
32
+
33
+	/**
34
+	 * @var array $_class_abbreviations
35
+	 * @access    protected
36
+	 */
37
+	protected $_class_abbreviations = array();
38
+
39
+	/**
40
+	 * @access public
41
+	 * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS
42
+	 */
43
+	public $BUS;
44
+
45
+	/**
46
+	 *    EE_Cart Object
47
+	 *
48
+	 * @access    public
49
+	 * @var    EE_Cart $CART
50
+	 */
51
+	public $CART = null;
52
+
53
+	/**
54
+	 *    EE_Config Object
55
+	 *
56
+	 * @access    public
57
+	 * @var    EE_Config $CFG
58
+	 */
59
+	public $CFG = null;
60
+
61
+	/**
62
+	 * EE_Network_Config Object
63
+	 *
64
+	 * @access public
65
+	 * @var EE_Network_Config $NET_CFG
66
+	 */
67
+	public $NET_CFG = null;
68
+
69
+	/**
70
+	 *    StdClass object for storing library classes in
71
+	 *
72
+	 * @public LIB
73
+	 * @var StdClass $LIB
74
+	 */
75
+	public $LIB = null;
76
+
77
+	/**
78
+	 *    EE_Request_Handler Object
79
+	 *
80
+	 * @access    public
81
+	 * @var    EE_Request_Handler $REQ
82
+	 */
83
+	public $REQ = null;
84
+
85
+	/**
86
+	 *    EE_Session Object
87
+	 *
88
+	 * @access    public
89
+	 * @var    EE_Session $SSN
90
+	 */
91
+	public $SSN = null;
92
+
93
+	/**
94
+	 * holds the ee capabilities object.
95
+	 *
96
+	 * @since 4.5.0
97
+	 * @var EE_Capabilities
98
+	 */
99
+	public $CAP = null;
100
+
101
+	/**
102
+	 * holds the EE_Message_Resource_Manager object.
103
+	 *
104
+	 * @since 4.9.0
105
+	 * @var EE_Message_Resource_Manager
106
+	 */
107
+	public $MRM = null;
108
+
109
+
110
+	/**
111
+	 * Holds the Assets Registry instance
112
+	 * @var Registry
113
+	 */
114
+	public $AssetsRegistry = null;
115
+
116
+	/**
117
+	 *    $addons - StdClass object for holding addons which have registered themselves to work with EE core
118
+	 *
119
+	 * @access    public
120
+	 * @var    EE_Addon[]
121
+	 */
122
+	public $addons = null;
123
+
124
+	/**
125
+	 *    $models
126
+	 * @access    public
127
+	 * @var    EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
128
+	 */
129
+	public $models = array();
130
+
131
+	/**
132
+	 *    $modules
133
+	 * @access    public
134
+	 * @var    EED_Module[] $modules
135
+	 */
136
+	public $modules = null;
137
+
138
+	/**
139
+	 *    $shortcodes
140
+	 * @access    public
141
+	 * @var    EES_Shortcode[] $shortcodes
142
+	 */
143
+	public $shortcodes = null;
144
+
145
+	/**
146
+	 *    $widgets
147
+	 * @access    public
148
+	 * @var    WP_Widget[] $widgets
149
+	 */
150
+	public $widgets = null;
151
+
152
+	/**
153
+	 * $non_abstract_db_models
154
+	 * @access public
155
+	 * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models
156
+	 * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
157
+	 * Keys are model "short names" (eg "Event") as used in model relations, and values are
158
+	 * classnames (eg "EEM_Event")
159
+	 */
160
+	public $non_abstract_db_models = array();
161
+
162
+
163
+	/**
164
+	 *    $i18n_js_strings - internationalization for JS strings
165
+	 *    usage:   EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' );
166
+	 *    in js file:  var translatedString = eei18n.string_key;
167
+	 *
168
+	 * @access    public
169
+	 * @var    array
170
+	 */
171
+	public static $i18n_js_strings = array();
172
+
173
+
174
+	/**
175
+	 *    $main_file - path to espresso.php
176
+	 *
177
+	 * @access    public
178
+	 * @var    array
179
+	 */
180
+	public $main_file;
181
+
182
+	/**
183
+	 * array of ReflectionClass objects where the key is the class name
184
+	 *
185
+	 * @access    public
186
+	 * @var ReflectionClass[]
187
+	 */
188
+	public $_reflectors;
189
+
190
+	/**
191
+	 * boolean flag to indicate whether or not to load/save dependencies from/to the cache
192
+	 *
193
+	 * @access    protected
194
+	 * @var boolean $_cache_on
195
+	 */
196
+	protected $_cache_on = true;
197
+
198
+
199
+
200
+	/**
201
+	 * @singleton method used to instantiate class object
202
+	 * @access    public
203
+	 * @param  \EE_Dependency_Map $dependency_map
204
+	 * @return \EE_Registry instance
205
+	 */
206
+	public static function instance(\EE_Dependency_Map $dependency_map = null)
207
+	{
208
+		// check if class object is instantiated
209
+		if ( ! self::$_instance instanceof EE_Registry) {
210
+			self::$_instance = new EE_Registry($dependency_map);
211
+		}
212
+		return self::$_instance;
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 *protected constructor to prevent direct creation
219
+	 *
220
+	 * @Constructor
221
+	 * @access protected
222
+	 * @param  \EE_Dependency_Map $dependency_map
223
+	 */
224
+	protected function __construct(\EE_Dependency_Map $dependency_map)
225
+	{
226
+		$this->_dependency_map = $dependency_map;
227
+		$this->LIB = new stdClass();
228
+		$this->addons = new stdClass();
229
+		$this->modules = new stdClass();
230
+		$this->shortcodes = new stdClass();
231
+		$this->widgets = new stdClass();
232
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
233
+	}
234
+
235
+
236
+
237
+	/**
238
+	 * initialize
239
+	 */
240
+	public function initialize()
241
+	{
242
+		$this->_class_abbreviations = apply_filters(
243
+			'FHEE__EE_Registry____construct___class_abbreviations',
244
+			array(
245
+				'EE_Config'                                       => 'CFG',
246
+				'EE_Session'                                      => 'SSN',
247
+				'EE_Capabilities'                                 => 'CAP',
248
+				'EE_Cart'                                         => 'CART',
249
+				'EE_Network_Config'                               => 'NET_CFG',
250
+				'EE_Request_Handler'                              => 'REQ',
251
+				'EE_Message_Resource_Manager'                     => 'MRM',
252
+				'EventEspresso\core\services\commands\CommandBus' => 'BUS',
253
+				'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
254
+			)
255
+		);
256
+		$this->load_core('Base', array(), true);
257
+		// add our request and response objects to the cache
258
+		$request_loader = $this->_dependency_map->class_loader('EE_Request');
259
+		$this->_set_cached_class(
260
+			$request_loader(),
261
+			'EE_Request'
262
+		);
263
+		$response_loader = $this->_dependency_map->class_loader('EE_Response');
264
+		$this->_set_cached_class(
265
+			$response_loader(),
266
+			'EE_Response'
267
+		);
268
+		add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
269
+	}
270
+
271
+
272
+
273
+	/**
274
+	 *    init
275
+	 *
276
+	 * @access    public
277
+	 * @return    void
278
+	 */
279
+	public function init()
280
+	{
281
+		// Get current page protocol
282
+		$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
283
+		// Output admin-ajax.php URL with same protocol as current page
284
+		self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
285
+		self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
286
+	}
287
+
288
+
289
+
290
+	/**
291
+	 * localize_i18n_js_strings
292
+	 *
293
+	 * @return string
294
+	 */
295
+	public static function localize_i18n_js_strings()
296
+	{
297
+		$i18n_js_strings = (array)EE_Registry::$i18n_js_strings;
298
+		foreach ($i18n_js_strings as $key => $value) {
299
+			if (is_scalar($value)) {
300
+				$i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
301
+			}
302
+		}
303
+		return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
304
+	}
305
+
306
+
307
+
308
+	/**
309
+	 * @param mixed string | EED_Module $module
310
+	 */
311
+	public function add_module($module)
312
+	{
313
+		if ($module instanceof EED_Module) {
314
+			$module_class = get_class($module);
315
+			$this->modules->{$module_class} = $module;
316
+		} else {
317
+			if ( ! class_exists('EE_Module_Request_Router')) {
318
+				$this->load_core('Module_Request_Router');
319
+			}
320
+			$this->modules->{$module} = EE_Module_Request_Router::module_factory($module);
321
+		}
322
+	}
323
+
324
+
325
+
326
+	/**
327
+	 * @param string $module_name
328
+	 * @return mixed EED_Module | NULL
329
+	 */
330
+	public function get_module($module_name = '')
331
+	{
332
+		return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null;
333
+	}
334
+
335
+
336
+
337
+	/**
338
+	 *    loads core classes - must be singletons
339
+	 *
340
+	 * @access    public
341
+	 * @param string $class_name - simple class name ie: session
342
+	 * @param mixed  $arguments
343
+	 * @param bool   $load_only
344
+	 * @return mixed
345
+	 */
346
+	public function load_core($class_name, $arguments = array(), $load_only = false)
347
+	{
348
+		$core_paths = apply_filters(
349
+			'FHEE__EE_Registry__load_core__core_paths',
350
+			array(
351
+				EE_CORE,
352
+				EE_ADMIN,
353
+				EE_CPTS,
354
+				EE_CORE . 'data_migration_scripts' . DS,
355
+				EE_CORE . 'request_stack' . DS,
356
+				EE_CORE . 'middleware' . DS,
357
+			)
358
+		);
359
+		// retrieve instantiated class
360
+		return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only);
361
+	}
362
+
363
+
364
+
365
+	/**
366
+	 *    loads service classes
367
+	 *
368
+	 * @access    public
369
+	 * @param string $class_name - simple class name ie: session
370
+	 * @param mixed  $arguments
371
+	 * @param bool   $load_only
372
+	 * @return mixed
373
+	 */
374
+	public function load_service($class_name, $arguments = array(), $load_only = false)
375
+	{
376
+		$service_paths = apply_filters(
377
+			'FHEE__EE_Registry__load_service__service_paths',
378
+			array(
379
+				EE_CORE . 'services' . DS,
380
+			)
381
+		);
382
+		// retrieve instantiated class
383
+		return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only);
384
+	}
385
+
386
+
387
+
388
+	/**
389
+	 *    loads data_migration_scripts
390
+	 *
391
+	 * @access    public
392
+	 * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
393
+	 * @param mixed  $arguments
394
+	 * @return EE_Data_Migration_Script_Base|mixed
395
+	 */
396
+	public function load_dms($class_name, $arguments = array())
397
+	{
398
+		// retrieve instantiated class
399
+		return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false);
400
+	}
401
+
402
+
403
+
404
+	/**
405
+	 *    loads object creating classes - must be singletons
406
+	 *
407
+	 * @param string $class_name - simple class name ie: attendee
408
+	 * @param mixed  $arguments  - an array of arguments to pass to the class
409
+	 * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to instantiate
410
+	 * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop)
411
+	 * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate (default)
412
+	 * @return EE_Base_Class | bool
413
+	 */
414
+	public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
415
+	{
416
+		$paths = apply_filters('FHEE__EE_Registry__load_class__paths', array(
417
+			EE_CORE,
418
+			EE_CLASSES,
419
+			EE_BUSINESS,
420
+		));
421
+		// retrieve instantiated class
422
+		return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only);
423
+	}
424
+
425
+
426
+
427
+	/**
428
+	 *    loads helper classes - must be singletons
429
+	 *
430
+	 * @param string $class_name - simple class name ie: price
431
+	 * @param mixed  $arguments
432
+	 * @param bool   $load_only
433
+	 * @return EEH_Base | bool
434
+	 */
435
+	public function load_helper($class_name, $arguments = array(), $load_only = true)
436
+	{
437
+		// todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
438
+		$helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
439
+		// retrieve instantiated class
440
+		return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only);
441
+	}
442
+
443
+
444
+
445
+	/**
446
+	 *    loads core classes - must be singletons
447
+	 *
448
+	 * @access    public
449
+	 * @param string $class_name - simple class name ie: session
450
+	 * @param mixed  $arguments
451
+	 * @param bool   $load_only
452
+	 * @param bool   $cache      whether to cache the object or not.
453
+	 * @return mixed
454
+	 */
455
+	public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
456
+	{
457
+		$paths = array(
458
+			EE_LIBRARIES,
459
+			EE_LIBRARIES . 'messages' . DS,
460
+			EE_LIBRARIES . 'shortcodes' . DS,
461
+			EE_LIBRARIES . 'qtips' . DS,
462
+			EE_LIBRARIES . 'payment_methods' . DS,
463
+		);
464
+		// retrieve instantiated class
465
+		return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only);
466
+	}
467
+
468
+
469
+
470
+	/**
471
+	 *    loads model classes - must be singletons
472
+	 *
473
+	 * @param string $class_name - simple class name ie: price
474
+	 * @param mixed  $arguments
475
+	 * @param bool   $load_only
476
+	 * @return EEM_Base | bool
477
+	 */
478
+	public function load_model($class_name, $arguments = array(), $load_only = false)
479
+	{
480
+		$paths = apply_filters('FHEE__EE_Registry__load_model__paths', array(
481
+			EE_MODELS,
482
+			EE_CORE,
483
+		));
484
+		// retrieve instantiated class
485
+		return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only);
486
+	}
487
+
488
+
489
+
490
+	/**
491
+	 *    loads model classes - must be singletons
492
+	 *
493
+	 * @param string $class_name - simple class name ie: price
494
+	 * @param mixed  $arguments
495
+	 * @param bool   $load_only
496
+	 * @return mixed | bool
497
+	 */
498
+	public function load_model_class($class_name, $arguments = array(), $load_only = true)
499
+	{
500
+		$paths = array(
501
+			EE_MODELS . 'fields' . DS,
502
+			EE_MODELS . 'helpers' . DS,
503
+			EE_MODELS . 'relations' . DS,
504
+			EE_MODELS . 'strategies' . DS,
505
+		);
506
+		// retrieve instantiated class
507
+		return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only);
508
+	}
509
+
510
+
511
+
512
+	/**
513
+	 * Determines if $model_name is the name of an actual EE model.
514
+	 *
515
+	 * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
516
+	 * @return boolean
517
+	 */
518
+	public function is_model_name($model_name)
519
+	{
520
+		return isset($this->models[$model_name]) ? true : false;
521
+	}
522
+
523
+
524
+
525
+	/**
526
+	 *    generic class loader
527
+	 *
528
+	 * @param string $path_to_file - directory path to file location, not including filename
529
+	 * @param string $file_name    - file name  ie:  my_file.php, including extension
530
+	 * @param string $type         - file type - core? class? helper? model?
531
+	 * @param mixed  $arguments
532
+	 * @param bool   $load_only
533
+	 * @return mixed
534
+	 */
535
+	public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
536
+	{
537
+		// retrieve instantiated class
538
+		return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only);
539
+	}
540
+
541
+
542
+
543
+	/**
544
+	 *    load_addon
545
+	 *
546
+	 * @param string $path_to_file - directory path to file location, not including filename
547
+	 * @param string $class_name   - full class name  ie:  My_Class
548
+	 * @param string $type         - file type - core? class? helper? model?
549
+	 * @param mixed  $arguments
550
+	 * @param bool   $load_only
551
+	 * @return EE_Addon
552
+	 */
553
+	public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
554
+	{
555
+		// retrieve instantiated class
556
+		return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only);
557
+	}
558
+
559
+
560
+
561
+	/**
562
+	 * instantiates, caches, and automatically resolves dependencies
563
+	 * for classes that use a Fully Qualified Class Name.
564
+	 * if the class is not capable of being loaded using PSR-4 autoloading,
565
+	 * then you need to use one of the existing load_*() methods
566
+	 * which can resolve the classname and filepath from the passed arguments
567
+	 *
568
+	 * @param bool|string $class_name   Fully Qualified Class Name
569
+	 * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
570
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
571
+	 * @param bool        $from_db      some classes are instantiated from the db
572
+	 *                                  and thus call a different method to instantiate
573
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
574
+	 * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
575
+	 * @return mixed                    null = failure to load or instantiate class object.
576
+	 *                                  object = class loaded and instantiated successfully.
577
+	 *                                  bool = fail or success when $load_only is true
578
+	 */
579
+	public function create(
580
+		$class_name = false,
581
+		$arguments = array(),
582
+		$cache = false,
583
+		$from_db = false,
584
+		$load_only = false,
585
+		$addon = false
586
+	) {
587
+		$class_name = ltrim($class_name, '\\');
588
+		$class_name = $this->_dependency_map->get_alias($class_name);
589
+		if ( ! class_exists($class_name)) {
590
+			// maybe the class is registered with a preceding \
591
+			$class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name;
592
+			// still doesn't exist ?
593
+			if ( ! class_exists($class_name)) {
594
+				return null;
595
+			}
596
+		}
597
+		// if we're only loading the class and it already exists, then let's just return true immediately
598
+		if ($load_only) {
599
+			return true;
600
+		}
601
+		$addon = $addon ? 'addon' : '';
602
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
603
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
604
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
605
+		if ($this->_cache_on && $cache && ! $load_only) {
606
+			// return object if it's already cached
607
+			$cached_class = $this->_get_cached_class($class_name, $addon);
608
+			if ($cached_class !== null) {
609
+				return $cached_class;
610
+			}
611
+		}
612
+		// instantiate the requested object
613
+		$class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
614
+		if ($this->_cache_on && $cache) {
615
+			// save it for later... kinda like gum  { : $
616
+			$this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
617
+		}
618
+		$this->_cache_on = true;
619
+		return $class_obj;
620
+	}
621
+
622
+
623
+
624
+	/**
625
+	 * instantiates, caches, and injects dependencies for classes
626
+	 *
627
+	 * @param array       $file_paths   an array of paths to folders to look in
628
+	 * @param string      $class_prefix EE  or EEM or... ???
629
+	 * @param bool|string $class_name   $class name
630
+	 * @param string      $type         file type - core? class? helper? model?
631
+	 * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
632
+	 * @param bool        $from_db      some classes are instantiated from the db
633
+	 *                                  and thus call a different method to instantiate
634
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
635
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
636
+	 * @return null|object|bool         null = failure to load or instantiate class object.
637
+	 *                                  object = class loaded and instantiated successfully.
638
+	 *                                  bool = fail or success when $load_only is true
639
+	 */
640
+	protected function _load(
641
+		$file_paths = array(),
642
+		$class_prefix = 'EE_',
643
+		$class_name = false,
644
+		$type = 'class',
645
+		$arguments = array(),
646
+		$from_db = false,
647
+		$cache = true,
648
+		$load_only = false
649
+	) {
650
+		$class_name = ltrim($class_name, '\\');
651
+		// strip php file extension
652
+		$class_name = str_replace('.php', '', trim($class_name));
653
+		// does the class have a prefix ?
654
+		if ( ! empty($class_prefix) && $class_prefix != 'addon') {
655
+			// make sure $class_prefix is uppercase
656
+			$class_prefix = strtoupper(trim($class_prefix));
657
+			// add class prefix ONCE!!!
658
+			$class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
659
+		}
660
+		$class_name = $this->_dependency_map->get_alias($class_name);
661
+		$class_exists = class_exists($class_name);
662
+		// if we're only loading the class and it already exists, then let's just return true immediately
663
+		if ($load_only && $class_exists) {
664
+			return true;
665
+		}
666
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
667
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
668
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
669
+		if ($this->_cache_on && $cache && ! $load_only) {
670
+			// return object if it's already cached
671
+			$cached_class = $this->_get_cached_class($class_name, $class_prefix);
672
+			if ($cached_class !== null) {
673
+				return $cached_class;
674
+			}
675
+		}
676
+		// if the class doesn't already exist.. then we need to try and find the file and load it
677
+		if ( ! $class_exists) {
678
+			// get full path to file
679
+			$path = $this->_resolve_path($class_name, $type, $file_paths);
680
+			// load the file
681
+			$loaded = $this->_require_file($path, $class_name, $type, $file_paths);
682
+			// if loading failed, or we are only loading a file but NOT instantiating an object
683
+			if ( ! $loaded || $load_only) {
684
+				// return boolean if only loading, or null if an object was expected
685
+				return $load_only ? $loaded : null;
686
+			}
687
+		}
688
+		// instantiate the requested object
689
+		$class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
690
+		if ($this->_cache_on && $cache) {
691
+			// save it for later... kinda like gum  { : $
692
+			$this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
693
+		}
694
+		$this->_cache_on = true;
695
+		return $class_obj;
696
+	}
697
+
698
+
699
+
700
+
701
+	/**
702
+	 * _get_cached_class
703
+	 * attempts to find a cached version of the requested class
704
+	 * by looking in the following places:
705
+	 *        $this->{$class_abbreviation}            ie:    $this->CART
706
+	 *        $this->{$class_name}                        ie:    $this->Some_Class
707
+	 *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
708
+	 *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
709
+	 *
710
+	 * @access protected
711
+	 * @param string $class_name
712
+	 * @param string $class_prefix
713
+	 * @return mixed
714
+	 */
715
+	protected function _get_cached_class($class_name, $class_prefix = '')
716
+	{
717
+		// have to specify something, but not anything that will conflict
718
+		$class_abbreviation = isset($this->_class_abbreviations[ $class_name ])
719
+			? $this->_class_abbreviations[ $class_name ]
720
+			: 'FANCY_BATMAN_PANTS';
721
+		$class_name = str_replace('\\', '_', $class_name);
722
+		// check if class has already been loaded, and return it if it has been
723
+		if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) {
724
+			return $this->{$class_abbreviation};
725
+		}
726
+		if (isset ($this->{$class_name})) {
727
+			return $this->{$class_name};
728
+		}
729
+		if (isset ($this->LIB->{$class_name})) {
730
+			return $this->LIB->{$class_name};
731
+		}
732
+		if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
733
+			return $this->addons->{$class_name};
734
+		}
735
+		return null;
736
+	}
737
+
738
+
739
+
740
+	/**
741
+	 * removes a cached version of the requested class
742
+	 *
743
+	 * @param string $class_name
744
+	 * @param boolean $addon
745
+	 * @return boolean
746
+	 */
747
+	public function clear_cached_class($class_name, $addon = false)
748
+	{
749
+		// have to specify something, but not anything that will conflict
750
+		$class_abbreviation = isset($this->_class_abbreviations[ $class_name ])
751
+			? $this->_class_abbreviations[ $class_name ]
752
+			: 'FANCY_BATMAN_PANTS';
753
+		$class_name = str_replace('\\', '_', $class_name);
754
+		// check if class has already been loaded, and return it if it has been
755
+		if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) {
756
+			$this->{$class_abbreviation} = null;
757
+			return true;
758
+		}
759
+		if (isset($this->{$class_name})) {
760
+			$this->{$class_name} = null;
761
+			return true;
762
+		}
763
+		if (isset($this->LIB->{$class_name})) {
764
+			unset($this->LIB->{$class_name});
765
+			return true;
766
+		}
767
+		if ($addon && isset($this->addons->{$class_name})) {
768
+			unset($this->addons->{$class_name});
769
+			return true;
770
+		}
771
+		return false;
772
+	}
773
+
774
+
775
+	/**
776
+	 * _resolve_path
777
+	 * attempts to find a full valid filepath for the requested class.
778
+	 * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
779
+	 * then returns that path if the target file has been found and is readable
780
+	 *
781
+	 * @access protected
782
+	 * @param string $class_name
783
+	 * @param string $type
784
+	 * @param array  $file_paths
785
+	 * @return string | bool
786
+	 */
787
+	protected function _resolve_path($class_name, $type = '', $file_paths = array())
788
+	{
789
+		// make sure $file_paths is an array
790
+		$file_paths = is_array($file_paths) ? $file_paths : array($file_paths);
791
+		// cycle thru paths
792
+		foreach ($file_paths as $key => $file_path) {
793
+			// convert all separators to proper DS, if no filepath, then use EE_CLASSES
794
+			$file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES;
795
+			// prep file type
796
+			$type = ! empty($type) ? trim($type, '.') . '.' : '';
797
+			// build full file path
798
+			$file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
799
+			//does the file exist and can be read ?
800
+			if (is_readable($file_paths[$key])) {
801
+				return $file_paths[$key];
802
+			}
803
+		}
804
+		return false;
805
+	}
806
+
807
+
808
+
809
+	/**
810
+	 * _require_file
811
+	 * basically just performs a require_once()
812
+	 * but with some error handling
813
+	 *
814
+	 * @access protected
815
+	 * @param  string $path
816
+	 * @param  string $class_name
817
+	 * @param  string $type
818
+	 * @param  array  $file_paths
819
+	 * @return boolean
820
+	 * @throws \EE_Error
821
+	 */
822
+	protected function _require_file($path, $class_name, $type = '', $file_paths = array())
823
+	{
824
+		// don't give up! you gotta...
825
+		try {
826
+			//does the file exist and can it be read ?
827
+			if ( ! $path) {
828
+				// so sorry, can't find the file
829
+				throw new EE_Error (
830
+					sprintf(
831
+						__('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'),
832
+						trim($type, '.'),
833
+						$class_name,
834
+						'<br />' . implode(',<br />', $file_paths)
835
+					)
836
+				);
837
+			}
838
+			// get the file
839
+			require_once($path);
840
+			// if the class isn't already declared somewhere
841
+			if (class_exists($class_name, false) === false) {
842
+				// so sorry, not a class
843
+				throw new EE_Error(
844
+					sprintf(
845
+						__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
846
+						$type,
847
+						$path,
848
+						$class_name
849
+					)
850
+				);
851
+			}
852
+		} catch (EE_Error $e) {
853
+			$e->get_error();
854
+			return false;
855
+		}
856
+		return true;
857
+	}
858
+
859
+
860
+
861
+	/**
862
+	 * _create_object
863
+	 * Attempts to instantiate the requested class via any of the
864
+	 * commonly used instantiation methods employed throughout EE.
865
+	 * The priority for instantiation is as follows:
866
+	 *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
867
+	 *        - model objects via their 'new_instance_from_db' method
868
+	 *        - model objects via their 'new_instance' method
869
+	 *        - "singleton" classes" via their 'instance' method
870
+	 *    - standard instantiable classes via their __constructor
871
+	 * Prior to instantiation, if the classname exists in the dependency_map,
872
+	 * then the constructor for the requested class will be examined to determine
873
+	 * if any dependencies exist, and if they can be injected.
874
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
875
+	 *
876
+	 * @access protected
877
+	 * @param string $class_name
878
+	 * @param array  $arguments
879
+	 * @param string $type
880
+	 * @param bool   $from_db
881
+	 * @return null | object
882
+	 * @throws \EE_Error
883
+	 */
884
+	protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
885
+	{
886
+		$class_obj = null;
887
+		$instantiation_mode = '0) none';
888
+		// don't give up! you gotta...
889
+		try {
890
+			// create reflection
891
+			$reflector = $this->get_ReflectionClass($class_name);
892
+			// make sure arguments are an array
893
+			$arguments = is_array($arguments) ? $arguments : array($arguments);
894
+			// and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
895
+			// else wrap it in an additional array so that it doesn't get split into multiple parameters
896
+			$arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
897
+				? $arguments
898
+				: array($arguments);
899
+			// attempt to inject dependencies ?
900
+			if ($this->_dependency_map->has($class_name)) {
901
+				$arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
902
+			}
903
+			// instantiate the class if possible
904
+			if ($reflector->isAbstract()) {
905
+				// nothing to instantiate, loading file was enough
906
+				// does not throw an exception so $instantiation_mode is unused
907
+				// $instantiation_mode = "1) no constructor abstract class";
908
+				$class_obj = true;
909
+			} else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) {
910
+				// no constructor = static methods only... nothing to instantiate, loading file was enough
911
+				$instantiation_mode = "2) no constructor but instantiable";
912
+				$class_obj = $reflector->newInstance();
913
+			} else if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
914
+				$instantiation_mode = "3) new_instance_from_db()";
915
+				$class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
916
+			} else if (method_exists($class_name, 'new_instance')) {
917
+				$instantiation_mode = "4) new_instance()";
918
+				$class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments);
919
+			} else if (method_exists($class_name, 'instance')) {
920
+				$instantiation_mode = "5) instance()";
921
+				$class_obj = call_user_func_array(array($class_name, 'instance'), $arguments);
922
+			} else if ($reflector->isInstantiable()) {
923
+				$instantiation_mode = "6) constructor";
924
+				$class_obj = $reflector->newInstanceArgs($arguments);
925
+			} else {
926
+				// heh ? something's not right !
927
+				throw new EE_Error(
928
+					sprintf(
929
+						__('The %s file %s could not be instantiated.', 'event_espresso'),
930
+						$type,
931
+						$class_name
932
+					)
933
+				);
934
+			}
935
+		} catch (Exception $e) {
936
+			if ( ! $e instanceof EE_Error) {
937
+				$e = new EE_Error(
938
+					sprintf(
939
+						__('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'),
940
+						$class_name,
941
+						'<br />',
942
+						$e->getMessage(),
943
+						$instantiation_mode
944
+					)
945
+				);
946
+			}
947
+			$e->get_error();
948
+		}
949
+		return $class_obj;
950
+	}
951
+
952
+
953
+
954
+	/**
955
+	 * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
956
+	 * @param array $array
957
+	 * @return bool
958
+	 */
959
+	protected function _array_is_numerically_and_sequentially_indexed(array $array)
960
+	{
961
+		return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true;
962
+	}
963
+
964
+
965
+
966
+	/**
967
+	 * getReflectionClass
968
+	 * checks if a ReflectionClass object has already been generated for a class
969
+	 * and returns that instead of creating a new one
970
+	 *
971
+	 * @access public
972
+	 * @param string $class_name
973
+	 * @return ReflectionClass
974
+	 */
975
+	public function get_ReflectionClass($class_name)
976
+	{
977
+		if (
978
+			! isset($this->_reflectors[$class_name])
979
+			|| ! $this->_reflectors[$class_name] instanceof ReflectionClass
980
+		) {
981
+			$this->_reflectors[$class_name] = new ReflectionClass($class_name);
982
+		}
983
+		return $this->_reflectors[$class_name];
984
+	}
985
+
986
+
987
+
988
+	/**
989
+	 * _resolve_dependencies
990
+	 * examines the constructor for the requested class to determine
991
+	 * if any dependencies exist, and if they can be injected.
992
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
993
+	 * PLZ NOTE: this is achieved by type hinting the constructor params
994
+	 * For example:
995
+	 *        if attempting to load a class "Foo" with the following constructor:
996
+	 *        __construct( Bar $bar_class, Fighter $grohl_class )
997
+	 *        then $bar_class and $grohl_class will be added to the $arguments array,
998
+	 *        but only IF they are NOT already present in the incoming arguments array,
999
+	 *        and the correct classes can be loaded
1000
+	 *
1001
+	 * @access protected
1002
+	 * @param ReflectionClass $reflector
1003
+	 * @param string          $class_name
1004
+	 * @param array           $arguments
1005
+	 * @return array
1006
+	 * @throws \ReflectionException
1007
+	 */
1008
+	protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
1009
+	{
1010
+		// let's examine the constructor
1011
+		$constructor = $reflector->getConstructor();
1012
+		// whu? huh? nothing?
1013
+		if ( ! $constructor) {
1014
+			return $arguments;
1015
+		}
1016
+		// get constructor parameters
1017
+		$params = $constructor->getParameters();
1018
+		// and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1019
+		$argument_keys = array_keys($arguments);
1020
+		// now loop thru all of the constructors expected parameters
1021
+		foreach ($params as $index => $param) {
1022
+			// is this a dependency for a specific class ?
1023
+			$param_class = $param->getClass() ? $param->getClass()->name : null;
1024
+			// BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1025
+			$param_class = $this->_dependency_map->has_alias($param_class, $class_name)
1026
+				? $this->_dependency_map->get_alias($param_class, $class_name)
1027
+				: $param_class;
1028
+			if (
1029
+				// param is not even a class
1030
+				empty($param_class)
1031
+				// and something already exists in the incoming arguments for this param
1032
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1033
+			) {
1034
+				// so let's skip this argument and move on to the next
1035
+				continue;
1036
+			}
1037
+			if (
1038
+				// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1039
+				! empty($param_class)
1040
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1041
+				&& $arguments[$argument_keys[$index]] instanceof $param_class
1042
+			) {
1043
+				// skip this argument and move on to the next
1044
+				continue;
1045
+			}
1046
+			if (
1047
+				// parameter is type hinted as a class, and should be injected
1048
+				! empty($param_class)
1049
+				&& $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1050
+			) {
1051
+				$arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index);
1052
+			} else {
1053
+				try {
1054
+					$arguments[$index] = $param->getDefaultValue();
1055
+				} catch (ReflectionException $e) {
1056
+					throw new ReflectionException(
1057
+						sprintf(
1058
+							__('%1$s for parameter "$%2$s"', 'event_espresso'),
1059
+							$e->getMessage(),
1060
+							$param->getName()
1061
+						)
1062
+					);
1063
+				}
1064
+			}
1065
+		}
1066
+		return $arguments;
1067
+	}
1068
+
1069
+
1070
+
1071
+	/**
1072
+	 * @access protected
1073
+	 * @param string $class_name
1074
+	 * @param string $param_class
1075
+	 * @param array  $arguments
1076
+	 * @param mixed  $index
1077
+	 * @return array
1078
+	 */
1079
+	protected function _resolve_dependency($class_name, $param_class, $arguments, $index)
1080
+	{
1081
+		$dependency = null;
1082
+		// should dependency be loaded from cache ?
1083
+		$cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class)
1084
+					!== EE_Dependency_Map::load_new_object
1085
+			? true
1086
+			: false;
1087
+		// we might have a dependency...
1088
+		// let's MAYBE try and find it in our cache if that's what's been requested
1089
+		$cached_class = $cache_on ? $this->_get_cached_class($param_class) : null;
1090
+		// and grab it if it exists
1091
+		if ($cached_class instanceof $param_class) {
1092
+			$dependency = $cached_class;
1093
+		} else if ($param_class !== $class_name) {
1094
+			// obtain the loader method from the dependency map
1095
+			$loader = $this->_dependency_map->class_loader($param_class);
1096
+			// is loader a custom closure ?
1097
+			if ($loader instanceof Closure) {
1098
+				$dependency = $loader();
1099
+			} else {
1100
+				// set the cache on property for the recursive loading call
1101
+				$this->_cache_on = $cache_on;
1102
+				// if not, then let's try and load it via the registry
1103
+				if ($loader && method_exists($this, $loader)) {
1104
+					$dependency = $this->{$loader}($param_class);
1105
+				} else {
1106
+					$dependency = $this->create($param_class, array(), $cache_on);
1107
+				}
1108
+			}
1109
+		}
1110
+		// did we successfully find the correct dependency ?
1111
+		if ($dependency instanceof $param_class) {
1112
+			// then let's inject it into the incoming array of arguments at the correct location
1113
+			if (isset($argument_keys[$index])) {
1114
+				$arguments[$argument_keys[$index]] = $dependency;
1115
+			} else {
1116
+				$arguments[$index] = $dependency;
1117
+			}
1118
+		}
1119
+		return $arguments;
1120
+	}
1121
+
1122
+
1123
+
1124
+	/**
1125
+	 * _set_cached_class
1126
+	 * attempts to cache the instantiated class locally
1127
+	 * in one of the following places, in the following order:
1128
+	 *        $this->{class_abbreviation}   ie:    $this->CART
1129
+	 *        $this->{$class_name}          ie:    $this->Some_Class
1130
+	 *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1131
+	 *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1132
+	 *
1133
+	 * @access protected
1134
+	 * @param object $class_obj
1135
+	 * @param string $class_name
1136
+	 * @param string $class_prefix
1137
+	 * @param bool   $from_db
1138
+	 * @return void
1139
+	 */
1140
+	protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1141
+	{
1142
+		if (empty($class_obj)) {
1143
+			return;
1144
+		}
1145
+		// return newly instantiated class
1146
+		if (isset($this->_class_abbreviations[$class_name])) {
1147
+			$class_abbreviation = $this->_class_abbreviations[$class_name];
1148
+			$this->{$class_abbreviation} = $class_obj;
1149
+			return;
1150
+		}
1151
+		$class_name = str_replace('\\', '_', $class_name);
1152
+		if (property_exists($this, $class_name)) {
1153
+			$this->{$class_name} = $class_obj;
1154
+			return;
1155
+		}
1156
+		if ($class_prefix === 'addon') {
1157
+			$this->addons->{$class_name} = $class_obj;
1158
+			return;
1159
+		}
1160
+		if ( ! $from_db) {
1161
+			$this->LIB->{$class_name} = $class_obj;
1162
+		}
1163
+	}
1164
+
1165
+
1166
+
1167
+	/**
1168
+	 * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1169
+	 *
1170
+	 * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1171
+	 *                          in the EE_Dependency_Map::$_class_loaders array,
1172
+	 *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1173
+	 * @param array  $arguments
1174
+	 * @return object
1175
+	 */
1176
+	public static function factory($classname, $arguments = array())
1177
+	{
1178
+		$loader = self::instance()->_dependency_map->class_loader($classname);
1179
+		if ($loader instanceof Closure) {
1180
+			return $loader($arguments);
1181
+		}
1182
+		if (method_exists(EE_Registry::instance(), $loader)) {
1183
+			return EE_Registry::instance()->{$loader}($classname, $arguments);
1184
+		}
1185
+		return null;
1186
+	}
1187
+
1188
+
1189
+
1190
+	/**
1191
+	 * Gets the addon by its name/slug (not classname. For that, just
1192
+	 * use the classname as the property name on EE_Config::instance()->addons)
1193
+	 *
1194
+	 * @param string $name
1195
+	 * @return EE_Addon
1196
+	 */
1197
+	public function get_addon_by_name($name)
1198
+	{
1199
+		foreach ($this->addons as $addon) {
1200
+			if ($addon->name() == $name) {
1201
+				return $addon;
1202
+			}
1203
+		}
1204
+		return null;
1205
+	}
1206
+
1207
+
1208
+
1209
+	/**
1210
+	 * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is
1211
+	 * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname}
1212
+	 *
1213
+	 * @return EE_Addon[] where the KEYS are the addon's name()
1214
+	 */
1215
+	public function get_addons_by_name()
1216
+	{
1217
+		$addons = array();
1218
+		foreach ($this->addons as $addon) {
1219
+			$addons[$addon->name()] = $addon;
1220
+		}
1221
+		return $addons;
1222
+	}
1223
+
1224
+
1225
+
1226
+	/**
1227
+	 * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1228
+	 * a stale copy of it around
1229
+	 *
1230
+	 * @param string $model_name
1231
+	 * @return \EEM_Base
1232
+	 * @throws \EE_Error
1233
+	 */
1234
+	public function reset_model($model_name)
1235
+	{
1236
+		$model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name;
1237
+		if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1238
+			return null;
1239
+		}
1240
+		//get that model reset it and make sure we nuke the old reference to it
1241
+		if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) {
1242
+			$this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1243
+		} else {
1244
+			throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1245
+		}
1246
+		return $this->LIB->{$model_class_name};
1247
+	}
1248
+
1249
+
1250
+
1251
+	/**
1252
+	 * Resets the registry.
1253
+	 * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog
1254
+	 * is used in a multisite install.  Here is a list of things that are NOT reset.
1255
+	 * - $_dependency_map
1256
+	 * - $_class_abbreviations
1257
+	 * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1258
+	 * - $REQ:  Still on the same request so no need to change.
1259
+	 * - $CAP: There is no site specific state in the EE_Capability class.
1260
+	 * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session
1261
+	 *         can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1262
+	 * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1263
+	 *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1264
+	 *             switch or on the restore.
1265
+	 * - $modules
1266
+	 * - $shortcodes
1267
+	 * - $widgets
1268
+	 *
1269
+	 * @param boolean $hard             whether to reset data in the database too, or just refresh
1270
+	 *                                  the Registry to its state at the beginning of the request
1271
+	 * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1272
+	 *                                  or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN
1273
+	 *                                  currently reinstantiate the singletons at the moment)
1274
+	 * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so client
1275
+	 *                                  code instead can just change the model context to a different blog id if necessary
1276
+	 * @return EE_Registry
1277
+	 */
1278
+	public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1279
+	{
1280
+		$instance = self::instance();
1281
+		EEH_Activation::reset();
1282
+		//properties that get reset
1283
+		$instance->_cache_on = true;
1284
+		$instance->CFG = EE_Config::reset($hard, $reinstantiate);
1285
+		$instance->CART = null;
1286
+		$instance->MRM = null;
1287
+		$instance->AssetsRegistry = null;
1288
+		$instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1289
+		//messages reset
1290
+		EED_Messages::reset();
1291
+		if ($reset_models) {
1292
+			foreach (array_keys($instance->non_abstract_db_models) as $model_name) {
1293
+				$instance->reset_model($model_name);
1294
+			}
1295
+		}
1296
+		$instance->LIB = new stdClass();
1297
+		return $instance;
1298
+	}
1299
+
1300
+
1301
+
1302
+	/**
1303
+	 * @override magic methods
1304
+	 * @return void
1305
+	 */
1306
+	public final function __destruct()
1307
+	{
1308
+	}
1309
+
1310
+
1311
+
1312
+	/**
1313
+	 * @param $a
1314
+	 * @param $b
1315
+	 */
1316
+	public final function __call($a, $b)
1317
+	{
1318
+	}
1319
+
1320
+
1321
+
1322
+	/**
1323
+	 * @param $a
1324
+	 */
1325
+	public final function __get($a)
1326
+	{
1327
+	}
1328
+
1329
+
1330
+
1331
+	/**
1332
+	 * @param $a
1333
+	 * @param $b
1334
+	 */
1335
+	public final function __set($a, $b)
1336
+	{
1337
+	}
1338
+
1339
+
1340
+
1341
+	/**
1342
+	 * @param $a
1343
+	 */
1344
+	public final function __isset($a)
1345
+	{
1346
+	}
1347 1347
 
1348 1348
 
1349 1349
 
1350
-    /**
1351
-     * @param $a
1352
-     */
1353
-    public final function __unset($a)
1354
-    {
1355
-    }
1350
+	/**
1351
+	 * @param $a
1352
+	 */
1353
+	public final function __unset($a)
1354
+	{
1355
+	}
1356 1356
 
1357 1357
 
1358 1358
 
1359
-    /**
1360
-     * @return array
1361
-     */
1362
-    public final function __sleep()
1363
-    {
1364
-        return array();
1365
-    }
1359
+	/**
1360
+	 * @return array
1361
+	 */
1362
+	public final function __sleep()
1363
+	{
1364
+		return array();
1365
+	}
1366 1366
 
1367 1367
 
1368 1368
 
1369
-    public final function __wakeup()
1370
-    {
1371
-    }
1369
+	public final function __wakeup()
1370
+	{
1371
+	}
1372 1372
 
1373 1373
 
1374 1374
 
1375
-    /**
1376
-     * @return string
1377
-     */
1378
-    public final function __toString()
1379
-    {
1380
-        return '';
1381
-    }
1375
+	/**
1376
+	 * @return string
1377
+	 */
1378
+	public final function __toString()
1379
+	{
1380
+		return '';
1381
+	}
1382 1382
 
1383 1383
 
1384 1384
 
1385
-    public final function __invoke()
1386
-    {
1387
-    }
1385
+	public final function __invoke()
1386
+	{
1387
+	}
1388 1388
 
1389 1389
 
1390 1390
 
1391
-    public final static function __set_state($array = array())
1392
-    {
1393
-        return EE_Registry::instance();
1394
-    }
1391
+	public final static function __set_state($array = array())
1392
+	{
1393
+		return EE_Registry::instance();
1394
+	}
1395 1395
 
1396 1396
 
1397 1397
 
1398
-    public final function __clone()
1399
-    {
1400
-    }
1398
+	public final function __clone()
1399
+	{
1400
+	}
1401 1401
 
1402 1402
 
1403 1403
 
1404
-    /**
1405
-     * @param $a
1406
-     * @param $b
1407
-     */
1408
-    public final static function __callStatic($a, $b)
1409
-    {
1410
-    }
1404
+	/**
1405
+	 * @param $a
1406
+	 * @param $b
1407
+	 */
1408
+	public final static function __callStatic($a, $b)
1409
+	{
1410
+	}
1411 1411
 
1412 1412
 
1413 1413
 
1414
-    /**
1415
-     * Gets all the custom post type models defined
1416
-     *
1417
-     * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1418
-     */
1419
-    public function cpt_models()
1420
-    {
1421
-        $cpt_models = array();
1422
-        foreach ($this->non_abstract_db_models as $short_name => $classname) {
1423
-            if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1424
-                $cpt_models[$short_name] = $classname;
1425
-            }
1426
-        }
1427
-        return $cpt_models;
1428
-    }
1414
+	/**
1415
+	 * Gets all the custom post type models defined
1416
+	 *
1417
+	 * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1418
+	 */
1419
+	public function cpt_models()
1420
+	{
1421
+		$cpt_models = array();
1422
+		foreach ($this->non_abstract_db_models as $short_name => $classname) {
1423
+			if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1424
+				$cpt_models[$short_name] = $classname;
1425
+			}
1426
+		}
1427
+		return $cpt_models;
1428
+	}
1429 1429
 
1430 1430
 
1431 1431
 
1432
-    /**
1433
-     * @return \EE_Config
1434
-     */
1435
-    public static function CFG()
1436
-    {
1437
-        return self::instance()->CFG;
1438
-    }
1432
+	/**
1433
+	 * @return \EE_Config
1434
+	 */
1435
+	public static function CFG()
1436
+	{
1437
+		return self::instance()->CFG;
1438
+	}
1439 1439
 
1440 1440
 
1441 1441
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -294,13 +294,13 @@  discard block
 block discarded – undo
294 294
      */
295 295
     public static function localize_i18n_js_strings()
296 296
     {
297
-        $i18n_js_strings = (array)EE_Registry::$i18n_js_strings;
297
+        $i18n_js_strings = (array) EE_Registry::$i18n_js_strings;
298 298
         foreach ($i18n_js_strings as $key => $value) {
299 299
             if (is_scalar($value)) {
300
-                $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
300
+                $i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
301 301
             }
302 302
         }
303
-        return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
303
+        return "/* <![CDATA[ */ var eei18n = ".wp_json_encode($i18n_js_strings).'; /* ]]> */';
304 304
     }
305 305
 
306 306
 
@@ -351,9 +351,9 @@  discard block
 block discarded – undo
351 351
                 EE_CORE,
352 352
                 EE_ADMIN,
353 353
                 EE_CPTS,
354
-                EE_CORE . 'data_migration_scripts' . DS,
355
-                EE_CORE . 'request_stack' . DS,
356
-                EE_CORE . 'middleware' . DS,
354
+                EE_CORE.'data_migration_scripts'.DS,
355
+                EE_CORE.'request_stack'.DS,
356
+                EE_CORE.'middleware'.DS,
357 357
             )
358 358
         );
359 359
         // retrieve instantiated class
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
         $service_paths = apply_filters(
377 377
             'FHEE__EE_Registry__load_service__service_paths',
378 378
             array(
379
-                EE_CORE . 'services' . DS,
379
+                EE_CORE.'services'.DS,
380 380
             )
381 381
         );
382 382
         // retrieve instantiated class
@@ -456,10 +456,10 @@  discard block
 block discarded – undo
456 456
     {
457 457
         $paths = array(
458 458
             EE_LIBRARIES,
459
-            EE_LIBRARIES . 'messages' . DS,
460
-            EE_LIBRARIES . 'shortcodes' . DS,
461
-            EE_LIBRARIES . 'qtips' . DS,
462
-            EE_LIBRARIES . 'payment_methods' . DS,
459
+            EE_LIBRARIES.'messages'.DS,
460
+            EE_LIBRARIES.'shortcodes'.DS,
461
+            EE_LIBRARIES.'qtips'.DS,
462
+            EE_LIBRARIES.'payment_methods'.DS,
463 463
         );
464 464
         // retrieve instantiated class
465 465
         return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only);
@@ -498,10 +498,10 @@  discard block
 block discarded – undo
498 498
     public function load_model_class($class_name, $arguments = array(), $load_only = true)
499 499
     {
500 500
         $paths = array(
501
-            EE_MODELS . 'fields' . DS,
502
-            EE_MODELS . 'helpers' . DS,
503
-            EE_MODELS . 'relations' . DS,
504
-            EE_MODELS . 'strategies' . DS,
501
+            EE_MODELS.'fields'.DS,
502
+            EE_MODELS.'helpers'.DS,
503
+            EE_MODELS.'relations'.DS,
504
+            EE_MODELS.'strategies'.DS,
505 505
         );
506 506
         // retrieve instantiated class
507 507
         return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only);
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
         $class_name = $this->_dependency_map->get_alias($class_name);
589 589
         if ( ! class_exists($class_name)) {
590 590
             // maybe the class is registered with a preceding \
591
-            $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name;
591
+            $class_name = strpos($class_name, '\\') !== 0 ? '\\'.$class_name : $class_name;
592 592
             // still doesn't exist ?
593 593
             if ( ! class_exists($class_name)) {
594 594
                 return null;
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
             // make sure $class_prefix is uppercase
656 656
             $class_prefix = strtoupper(trim($class_prefix));
657 657
             // add class prefix ONCE!!!
658
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
658
+            $class_name = $class_prefix.str_replace($class_prefix, '', $class_name);
659 659
         }
660 660
         $class_name = $this->_dependency_map->get_alias($class_name);
661 661
         $class_exists = class_exists($class_name);
@@ -715,8 +715,8 @@  discard block
 block discarded – undo
715 715
     protected function _get_cached_class($class_name, $class_prefix = '')
716 716
     {
717 717
         // have to specify something, but not anything that will conflict
718
-        $class_abbreviation = isset($this->_class_abbreviations[ $class_name ])
719
-            ? $this->_class_abbreviations[ $class_name ]
718
+        $class_abbreviation = isset($this->_class_abbreviations[$class_name])
719
+            ? $this->_class_abbreviations[$class_name]
720 720
             : 'FANCY_BATMAN_PANTS';
721 721
         $class_name = str_replace('\\', '_', $class_name);
722 722
         // check if class has already been loaded, and return it if it has been
@@ -747,8 +747,8 @@  discard block
 block discarded – undo
747 747
     public function clear_cached_class($class_name, $addon = false)
748 748
     {
749 749
         // have to specify something, but not anything that will conflict
750
-        $class_abbreviation = isset($this->_class_abbreviations[ $class_name ])
751
-            ? $this->_class_abbreviations[ $class_name ]
750
+        $class_abbreviation = isset($this->_class_abbreviations[$class_name])
751
+            ? $this->_class_abbreviations[$class_name]
752 752
             : 'FANCY_BATMAN_PANTS';
753 753
         $class_name = str_replace('\\', '_', $class_name);
754 754
         // check if class has already been loaded, and return it if it has been
@@ -793,9 +793,9 @@  discard block
 block discarded – undo
793 793
             // convert all separators to proper DS, if no filepath, then use EE_CLASSES
794 794
             $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES;
795 795
             // prep file type
796
-            $type = ! empty($type) ? trim($type, '.') . '.' : '';
796
+            $type = ! empty($type) ? trim($type, '.').'.' : '';
797 797
             // build full file path
798
-            $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
798
+            $file_paths[$key] = rtrim($file_path, DS).DS.$class_name.'.'.$type.'php';
799 799
             //does the file exist and can be read ?
800 800
             if (is_readable($file_paths[$key])) {
801 801
                 return $file_paths[$key];
@@ -826,12 +826,12 @@  discard block
 block discarded – undo
826 826
             //does the file exist and can it be read ?
827 827
             if ( ! $path) {
828 828
                 // so sorry, can't find the file
829
-                throw new EE_Error (
829
+                throw new EE_Error(
830 830
                     sprintf(
831 831
                         __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'),
832 832
                         trim($type, '.'),
833 833
                         $class_name,
834
-                        '<br />' . implode(',<br />', $file_paths)
834
+                        '<br />'.implode(',<br />', $file_paths)
835 835
                     )
836 836
                 );
837 837
             }
Please login to merge, or discard this patch.
admin/new/pricing/templates/event_tickets_datetime_ticket_row.template.php 1 patch
Braces   +40 added lines, -16 removed lines patch added patch discarded remove patch
@@ -6,24 +6,33 @@  discard block
 block discarded – undo
6 6
 		<?php if ( $disabled ) : ?>
7 7
 			<input type="hidden" id="edit-ticket-TKT_start_date-<?php echo $tkt_row; ?>"  name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_start_date]" class="edit-ticket-TKT_start_date ee-text-inp" value="<?php echo $TKT_start_date; ?>" >
8 8
 			<input type="text" name="archived_ticket[TKT_start_date]" class="edit-ticket-TKT_start_date ee-text-inp" value="<?php echo $TKT_start_date; ?>" disabled>
9
-		<?php else : ?>
10
-			<input id="edit-ticket-TKT_start_date-<?php echo $tkt_row; ?>" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_start_date]" class="edit-ticket-TKT_start_date ee-text-inp ee-datepicker" value="<?php echo $TKT_start_date; ?>" data-context="start-ticket" data-date-field-context="#display-ticketrow-<?php echo $tkt_row; ?>" data-related-field=".edit-ticket-TKT_end_date" data-next-field=".edit-ticket-TKT_end_date">
9
+		<?php else {
10
+	: ?>
11
+			<input id="edit-ticket-TKT_start_date-<?php echo $tkt_row;
12
+}
13
+?>" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_start_date]" class="edit-ticket-TKT_start_date ee-text-inp ee-datepicker" value="<?php echo $TKT_start_date; ?>" data-context="start-ticket" data-date-field-context="#display-ticketrow-<?php echo $tkt_row; ?>" data-related-field=".edit-ticket-TKT_end_date" data-next-field=".edit-ticket-TKT_end_date">
11 14
 		<?php endif; ?>
12 15
 	</td>
13 16
 	<td>
14 17
 		<?php if ( $disabled ) : ?>
15 18
 			<input type="hidden" id="edit-ticket-TKT_end_date-<?php echo $tkt_row; ?>"  name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_end_date]" class="edit-ticket-TKT_end_date ee-text-inp" value="<?php echo $TKT_end_date; ?>" >
16 19
 			<input type="text" name="archived_ticket[TKT_end_date]" class="edit-ticket-TKT_end_date ee-text-inp" value="<?php echo $TKT_end_date; ?>" disabled>
17
-		<?php else : ?>
18
-			<input id="edit-ticket-TKT_end_date-<?php echo $tkt_row; ?>" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_end_date]" class="edit-ticket-TKT_end_date ee-text-inp ee-datepicker" value="<?php echo $TKT_end_date; ?>" data-context="end-ticket" data-date-field-context="#display-ticketrow-<?php echo $tkt_row; ?>" data-related-field=".edit-ticket-TKT_start_date" data-next-field=".edit-ticket-TKT_qty">
20
+		<?php else {
21
+	: ?>
22
+			<input id="edit-ticket-TKT_end_date-<?php echo $tkt_row;
23
+}
24
+?>" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_end_date]" class="edit-ticket-TKT_end_date ee-text-inp ee-datepicker" value="<?php echo $TKT_end_date; ?>" data-context="end-ticket" data-date-field-context="#display-ticketrow-<?php echo $tkt_row; ?>" data-related-field=".edit-ticket-TKT_start_date" data-next-field=".edit-ticket-TKT_qty">
19 25
 		<?php endif; ?>
20 26
 	</td>
21 27
 	<td>
22 28
 		<?php if ( $disabled ) : ?>
23 29
 			<input id="edit-ticket-TKT_base_price-<?php echo $tkt_row; ?>" type="hidden" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_base_price]" class="edit-ticket-TKT_base_price ee-small-text-inp edit-price-PRC_amount ee-numeric" value="<?php echo $TKT_base_price; ?>">
24 30
 			<input type="text" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_base_price]" class="edit-ticket-TKT_base_price ee-small-text-inp edit-price-PRC_amount ee-numeric" value="<?php echo $TKT_base_price; ?>" disabled>
25
-		<?php else : ?>
26
-			<input id="edit-ticket-TKT_base_price-<?php echo $tkt_row; ?>" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_base_price]" class="edit-ticket-TKT_base_price ee-small-text-inp edit-price-PRC_amount ee-numeric" value="<?php echo $TKT_base_price; ?>">
31
+		<?php else {
32
+	: ?>
33
+			<input id="edit-ticket-TKT_base_price-<?php echo $tkt_row;
34
+}
35
+?>" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_base_price]" class="edit-ticket-TKT_base_price ee-small-text-inp edit-price-PRC_amount ee-numeric" value="<?php echo $TKT_base_price; ?>">
27 36
 		<?php endif; ?>
28 37
 		<input type="hidden" id="edit-ticket-TKT_base_price_ID-<?php echo $tkt_row; ?>" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_base_price_ID]" value="<?php echo $TKT_base_price_ID; ?>">
29 38
 	</td>
@@ -31,8 +40,11 @@  discard block
 block discarded – undo
31 40
 		<?php if ( $disabled ) : ?>
32 41
 			<input type="hidden" class="edit-ticket-TKT_qty ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_qty]" value="<?php echo $TKT_qty_for_input; ?>">
33 42
 			<input type="text" class="edit-ticket-TKT_qty ee-small-text-inp ee-numeric" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_qty]" value="<?php echo $TKT_qty_for_input; ?>" disabled>
34
-		<?php else : ?>
35
-			<input type="text" id="edit-ticket-TKT_qty-<?php echo $tkt_row; ?>" class="edit-ticket-TKT_qty ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_qty]" value="<?php echo $TKT_qty_for_input; ?>">
43
+		<?php else {
44
+	: ?>
45
+			<input type="text" id="edit-ticket-TKT_qty-<?php echo $tkt_row;
46
+}
47
+?>" class="edit-ticket-TKT_qty ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_qty]" value="<?php echo $TKT_qty_for_input; ?>">
36 48
 		<?php endif; ?>
37 49
 	</td>
38 50
 	<!--<td><span class="ticket-display-row-TKT_price"><?php //echo $TKT_price; ?></span></td>-->
@@ -78,24 +90,33 @@  discard block
 block discarded – undo
78 90
 								<?php if ( $disabled ) : ?>
79 91
 									<input type="hidden" class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_uses]" value="<?php echo $TKT_uses; ?>">
80 92
 									<input type="text" class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_uses]" value="<?php echo $TKT_uses; ?>" disabled>
81
-								<?php else : ?>
82
-									<input type="text" class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_uses]" value="<?php echo $TKT_uses; ?>">
93
+								<?php else {
94
+	: ?>
95
+									<input type="text" class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name;
96
+}
97
+?>[<?php echo $tkt_row; ?>][TKT_uses]" value="<?php echo $TKT_uses; ?>">
83 98
 								<?php endif; ?>
84 99
 							</td>
85 100
 							<td>
86 101
 								<?php if ( $disabled ) : ?>
87 102
 									<input type="hidden" class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_min]" value="<?php echo $TKT_min; ?>">
88 103
 									<input type="text" class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_min]" value="<?php echo $TKT_min; ?>" disabled>
89
-								<?php else: ?>
90
-									<input type="text" class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_min]" value="<?php echo $TKT_min; ?>">
104
+								<?php else {
105
+	: ?>
106
+									<input type="text" class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name;
107
+}
108
+?>[<?php echo $tkt_row; ?>][TKT_min]" value="<?php echo $TKT_min; ?>">
91 109
 								<?php endif; ?>
92 110
 							</td>
93 111
 							<td>
94 112
 								<?php if ( $disabled ) : ?>
95 113
 									<input type="hidden" class="edit-ticket-TKT_max ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_max]" value="<?php echo $TKT_max; ?>">
96 114
 									<input type="text" class="edit-ticket-TKT_max ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_max]" value="<?php echo $TKT_max; ?>" disabled>
97
-								<?php else : ?>
98
-									<input type="text" class="edit-ticket-TKT_max ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_max]" value="<?php echo $TKT_max; ?>">
115
+								<?php else {
116
+	: ?>
117
+									<input type="text" class="edit-ticket-TKT_max ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name;
118
+}
119
+?>[<?php echo $tkt_row; ?>][TKT_max]" value="<?php echo $TKT_max; ?>">
99 120
 								<?php endif; ?>
100 121
 							</td>
101 122
 						</tr>
@@ -116,8 +137,11 @@  discard block
 block discarded – undo
116 137
 							?>
117 138
 							<input class="TKT-taxable-checkbox" type="hidden" name="<?php echo $edit_tickets_name;?>[<?php echo $tkt_row; ?>][TKT_taxable]" value="<?php echo $tax_value; ?>">
118 139
 							<input class="TKT-taxable-checkbox" id="edit-ticket-TKT_taxable-<?php echo $tkt_row; ?>" type="checkbox" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_taxable]" value="1"<?php echo $TKT_taxable; ?> disabled>
119
-						<?php else : ?>
120
-							<input class="TKT-taxable-checkbox" id="edit-ticket-TKT_taxable-<?php echo $tkt_row; ?>" type="checkbox" name="<?php echo $edit_tickets_name;?>[<?php echo $tkt_row; ?>][TKT_taxable]" value="1"<?php echo $TKT_taxable; ?>>
140
+						<?php else {
141
+	: ?>
142
+							<input class="TKT-taxable-checkbox" id="edit-ticket-TKT_taxable-<?php echo $tkt_row;
143
+}
144
+?>" type="checkbox" name="<?php echo $edit_tickets_name;?>[<?php echo $tkt_row; ?>][TKT_taxable]" value="1"<?php echo $TKT_taxable; ?>>
121 145
 						<?php endif; ?>
122 146
 						<label for="edit-ticket-TKT_taxable-<?php echo $tkt_row; ?>"> <?php esc_html_e('This ticket is taxable.', 'event_espresso'); ?>
123 147
 					<?php } //end tax_rows check ?>
Please login to merge, or discard this patch.
acceptance_tests/Page/EventsAdmin.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -120,7 +120,7 @@
 block discarded – undo
120 120
 
121 121
     /**
122 122
      * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor.
123
-     * @param     $field_name
123
+     * @param     string $field_name
124 124
      * @param int $row_number
125 125
      * @return string
126 126
      */
Please login to merge, or discard this patch.
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -14,225 +14,225 @@
 block discarded – undo
14 14
 class EventsAdmin extends CoreAdmin
15 15
 {
16 16
 
17
-    /**
18
-     * Selector for the Add new Event button in the admin.
19
-     * @var string
20
-     */
21
-    const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event';
22
-
23
-
24
-    /**
25
-     * Selector for the Event Title field in the event editor
26
-     * @var string
27
-     */
28
-    const EVENT_EDITOR_TITLE_FIELD_SELECTOR = "//input[@id='title']";
29
-
30
-    /**
31
-     * Selector for the publish submit button in the event editor.
32
-     * @var string
33
-     */
34
-    const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = "#publish";
35
-
36
-
37
-    /**
38
-     * @var string
39
-     */
40
-    const EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR = '#EVT_default_registration_status';
41
-
42
-    /**
43
-     * Selector for the view link after publishing an event.
44
-     * @var string
45
-     */
46
-    const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//div[@id='message']/p/a";
17
+	/**
18
+	 * Selector for the Add new Event button in the admin.
19
+	 * @var string
20
+	 */
21
+	const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event';
22
+
23
+
24
+	/**
25
+	 * Selector for the Event Title field in the event editor
26
+	 * @var string
27
+	 */
28
+	const EVENT_EDITOR_TITLE_FIELD_SELECTOR = "//input[@id='title']";
29
+
30
+	/**
31
+	 * Selector for the publish submit button in the event editor.
32
+	 * @var string
33
+	 */
34
+	const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = "#publish";
35
+
36
+
37
+	/**
38
+	 * @var string
39
+	 */
40
+	const EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR = '#EVT_default_registration_status';
41
+
42
+	/**
43
+	 * Selector for the view link after publishing an event.
44
+	 * @var string
45
+	 */
46
+	const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//div[@id='message']/p/a";
47 47
 
48
-
49
-    /**
50
-     * Selector for the ID of the event in the event editor
51
-     * @var string
52
-     */
53
-    const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']";
48
+
49
+	/**
50
+	 * Selector for the ID of the event in the event editor
51
+	 * @var string
52
+	 */
53
+	const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']";
54 54
 
55 55
 
56
-    /**
57
-     * Selector for the search input on the event list table page.
58
-     * @var string
59
-     */
60
-    const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input';
61
-
62
-
63
-
64
-
65
-    /**
66
-     * @param string $additional_params
67
-     * @return string
68
-     */
69
-    public static function defaultEventsListTableUrl($additional_params = '')
70
-    {
71
-        return self::adminUrl('espresso_events', 'default', $additional_params);
72
-    }
73
-
74
-
75
-    /**
76
-     * The selector for the DTTname field for the given row in the event editor.
77
-     * @param int $row_number
78
-     * @return string
79
-     */
80
-    public static function eventEditorDatetimeNameFieldSelector($row_number = 1)
81
-    {
82
-        return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number);
83
-    }
84
-
85
-
86
-    /**
87
-     * The selector for the DTT_EVT_start field for the given row in the event editor.d
88
-     * @param int $row_number
89
-     * @return string
90
-     */
91
-    public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1)
92
-    {
93
-        return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number);
94
-    }
95
-
96
-
97
-    /**
98
-     * Wrapper for getting the selector for a given field and given row of a datetime in the event editor.
99
-     *
100
-     * @param string $field_name
101
-     * @param int    $row_number
102
-     * @return string
103
-     */
104
-    public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1)
105
-    {
106
-        return "//input[@id='event-datetime-$field_name-$row_number']";
107
-    }
108
-
109
-
110
-    /**
111
-     * The selector for the TKT_name field for the given display row in the event editor.
112
-     * @param int $row_number
113
-     * @return string
114
-     */
115
-    public static function eventEditorTicketNameFieldSelector($row_number = 1)
116
-    {
117
-        return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number);
118
-    }
119
-
120
-
121
-    public static function eventEditorTicketPriceFieldSelector($row_number = 1)
122
-    {
123
-        return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_base_price', $row_number);
124
-    }
125
-
126
-
127
-    public static function eventEditorTicketAdvancedDetailsSelector($row_number = 1)
128
-    {
129
-        return "//tr[@id='display-ticketrow-$row_number']//span[contains(@class, 'gear-icon')]";
130
-    }
131
-
132
-
133
-    public static function eventEditorTicketAdvancedDetailsSubtotalSelector($row_number = 1)
134
-    {
135
-        return "//span[@id='price-total-amount-$row_number']";
136
-    }
137
-
138
-
139
-    public static function eventEditorTicketAdvancedDetailsTotalSelector($row_number = 1)
140
-    {
141
-        return "//span[@id='price-total-amount-$row_number']";
142
-    }
143
-
144
-
145
-    public static function eventEditorTicketTaxableCheckboxSelector($row_number = 1)
146
-    {
147
-        return "//input[@id='edit-ticket-TKT_taxable-$row_number']";
148
-    }
149
-
150
-
151
-    /**
152
-     * This returns the xpath locater for the Tax amount display container within the advanced settings view for the
153
-     * given ticket (row) and the given tax id (PRC_ID).
154
-     *
155
-     * @param int $tax_id     The PRC_ID for the tax you want the locater for.  Note, this defaults to the default tax
156
-     *                        setup on a fresh install.
157
-     * @param int $row_number What row representing the ticket you want the locator for.
158
-     * @return string
159
-     */
160
-    public static function eventEditorTicketTaxAmountDisplayForTaxIdAndTicketRowSelector($tax_id = 2, $row_number = 1)
161
-    {
162
-        return "//span[@id='TKT-tax-amount-display-$tax_id-$row_number']";
163
-    }
164
-
165
-
166
-    /**
167
-     * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor.
168
-     * @param     $field_name
169
-     * @param int $row_number
170
-     * @return string
171
-     */
172
-    public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1)
173
-    {
174
-        return "//tr[@id='display-ticketrow-$row_number']//input[contains(@class, 'edit-ticket-$field_name')]";
175
-    }
176
-
177
-
178
-    /**
179
-     * Returns the selector for the event title edit link in the events list table for the given Event Title.
180
-     * @param string $event_title
181
-     * @return string
182
-     */
183
-    public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title)
184
-    {
185
-        return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']";
186
-    }
187
-
188
-
189
-    /**
190
-     * Locator for for the ID column in the event list table for a given event title.
191
-     * @param string $event_title
192
-     * @return string
193
-     */
194
-    public static function eventListTableEventIdSelectorForTitle($event_title)
195
-    {
196
-        return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"
197
-               . "//ancestor::tr/th[contains(@class, 'check-column')]/input";
198
-    }
199
-
200
-
201
-    /**
202
-     * Locator for the view link in the row of an event list table for the given event title.
203
-     * @param string $event_title
204
-     * @return string
205
-     */
206
-    public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title)
207
-    {
208
-        return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"
209
-               . "//ancestor::td//span[@class='view']/a";
210
-    }
211
-
212
-
213
-    /**
214
-     * Locator for the messenger tab in the Notifications metabox in the event editor.
215
-     * @param string $messenger_slug  The slug for the messenger (it's reference slug).
216
-     * @return string
217
-     */
218
-    public static function eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug)
219
-    {
220
-        return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']"
221
-               . "//a[@rel='ee-tab-$messenger_slug']";
222
-    }
223
-
224
-
225
-    /**
226
-     * Locator for the select input within the notifications metabox.
227
-     * Note, this assumes the tab content for the related messenger is already visible.
228
-     * @param string $message_type_label The message type label (visible string in the table) you want the selector for.
229
-     * @return string
230
-     */
231
-    public static function eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label)
232
-    {
233
-        return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']"
234
-               . "//table[@class='messages-custom-template-switcher']"
235
-               . "//tr/td[contains(.,'Registration Approved')]"
236
-               . "//ancestor::tr//select[contains(@class,'message-template-selector')]";
237
-    }
56
+	/**
57
+	 * Selector for the search input on the event list table page.
58
+	 * @var string
59
+	 */
60
+	const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input';
61
+
62
+
63
+
64
+
65
+	/**
66
+	 * @param string $additional_params
67
+	 * @return string
68
+	 */
69
+	public static function defaultEventsListTableUrl($additional_params = '')
70
+	{
71
+		return self::adminUrl('espresso_events', 'default', $additional_params);
72
+	}
73
+
74
+
75
+	/**
76
+	 * The selector for the DTTname field for the given row in the event editor.
77
+	 * @param int $row_number
78
+	 * @return string
79
+	 */
80
+	public static function eventEditorDatetimeNameFieldSelector($row_number = 1)
81
+	{
82
+		return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number);
83
+	}
84
+
85
+
86
+	/**
87
+	 * The selector for the DTT_EVT_start field for the given row in the event editor.d
88
+	 * @param int $row_number
89
+	 * @return string
90
+	 */
91
+	public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1)
92
+	{
93
+		return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number);
94
+	}
95
+
96
+
97
+	/**
98
+	 * Wrapper for getting the selector for a given field and given row of a datetime in the event editor.
99
+	 *
100
+	 * @param string $field_name
101
+	 * @param int    $row_number
102
+	 * @return string
103
+	 */
104
+	public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1)
105
+	{
106
+		return "//input[@id='event-datetime-$field_name-$row_number']";
107
+	}
108
+
109
+
110
+	/**
111
+	 * The selector for the TKT_name field for the given display row in the event editor.
112
+	 * @param int $row_number
113
+	 * @return string
114
+	 */
115
+	public static function eventEditorTicketNameFieldSelector($row_number = 1)
116
+	{
117
+		return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number);
118
+	}
119
+
120
+
121
+	public static function eventEditorTicketPriceFieldSelector($row_number = 1)
122
+	{
123
+		return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_base_price', $row_number);
124
+	}
125
+
126
+
127
+	public static function eventEditorTicketAdvancedDetailsSelector($row_number = 1)
128
+	{
129
+		return "//tr[@id='display-ticketrow-$row_number']//span[contains(@class, 'gear-icon')]";
130
+	}
131
+
132
+
133
+	public static function eventEditorTicketAdvancedDetailsSubtotalSelector($row_number = 1)
134
+	{
135
+		return "//span[@id='price-total-amount-$row_number']";
136
+	}
137
+
138
+
139
+	public static function eventEditorTicketAdvancedDetailsTotalSelector($row_number = 1)
140
+	{
141
+		return "//span[@id='price-total-amount-$row_number']";
142
+	}
143
+
144
+
145
+	public static function eventEditorTicketTaxableCheckboxSelector($row_number = 1)
146
+	{
147
+		return "//input[@id='edit-ticket-TKT_taxable-$row_number']";
148
+	}
149
+
150
+
151
+	/**
152
+	 * This returns the xpath locater for the Tax amount display container within the advanced settings view for the
153
+	 * given ticket (row) and the given tax id (PRC_ID).
154
+	 *
155
+	 * @param int $tax_id     The PRC_ID for the tax you want the locater for.  Note, this defaults to the default tax
156
+	 *                        setup on a fresh install.
157
+	 * @param int $row_number What row representing the ticket you want the locator for.
158
+	 * @return string
159
+	 */
160
+	public static function eventEditorTicketTaxAmountDisplayForTaxIdAndTicketRowSelector($tax_id = 2, $row_number = 1)
161
+	{
162
+		return "//span[@id='TKT-tax-amount-display-$tax_id-$row_number']";
163
+	}
164
+
165
+
166
+	/**
167
+	 * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor.
168
+	 * @param     $field_name
169
+	 * @param int $row_number
170
+	 * @return string
171
+	 */
172
+	public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1)
173
+	{
174
+		return "//tr[@id='display-ticketrow-$row_number']//input[contains(@class, 'edit-ticket-$field_name')]";
175
+	}
176
+
177
+
178
+	/**
179
+	 * Returns the selector for the event title edit link in the events list table for the given Event Title.
180
+	 * @param string $event_title
181
+	 * @return string
182
+	 */
183
+	public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title)
184
+	{
185
+		return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']";
186
+	}
187
+
188
+
189
+	/**
190
+	 * Locator for for the ID column in the event list table for a given event title.
191
+	 * @param string $event_title
192
+	 * @return string
193
+	 */
194
+	public static function eventListTableEventIdSelectorForTitle($event_title)
195
+	{
196
+		return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"
197
+			   . "//ancestor::tr/th[contains(@class, 'check-column')]/input";
198
+	}
199
+
200
+
201
+	/**
202
+	 * Locator for the view link in the row of an event list table for the given event title.
203
+	 * @param string $event_title
204
+	 * @return string
205
+	 */
206
+	public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title)
207
+	{
208
+		return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"
209
+			   . "//ancestor::td//span[@class='view']/a";
210
+	}
211
+
212
+
213
+	/**
214
+	 * Locator for the messenger tab in the Notifications metabox in the event editor.
215
+	 * @param string $messenger_slug  The slug for the messenger (it's reference slug).
216
+	 * @return string
217
+	 */
218
+	public static function eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug)
219
+	{
220
+		return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']"
221
+			   . "//a[@rel='ee-tab-$messenger_slug']";
222
+	}
223
+
224
+
225
+	/**
226
+	 * Locator for the select input within the notifications metabox.
227
+	 * Note, this assumes the tab content for the related messenger is already visible.
228
+	 * @param string $message_type_label The message type label (visible string in the table) you want the selector for.
229
+	 * @return string
230
+	 */
231
+	public static function eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label)
232
+	{
233
+		return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']"
234
+			   . "//table[@class='messages-custom-template-switcher']"
235
+			   . "//tr/td[contains(.,'Registration Approved')]"
236
+			   . "//ancestor::tr//select[contains(@class,'message-template-selector')]";
237
+	}
238 238
 }
Please login to merge, or discard this patch.
acceptance_tests/Helpers/BaseCoreAdmin.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -13,58 +13,58 @@
 block discarded – undo
13 13
 trait BaseCoreAdmin
14 14
 {
15 15
 
16
-    /**
17
-     * Core method for going to an Event Espresso Admin page.
18
-     * @param string $page
19
-     * @param string $action
20
-     * @param string $additional_params
21
-     */
22
-    public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '')
23
-    {
24
-        $this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params));
25
-    }
16
+	/**
17
+	 * Core method for going to an Event Espresso Admin page.
18
+	 * @param string $page
19
+	 * @param string $action
20
+	 * @param string $additional_params
21
+	 */
22
+	public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '')
23
+	{
24
+		$this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params));
25
+	}
26 26
 
27 27
 
28
-    /**
29
-     * Helper method for returning an instance of the Actor.  Intended to help with IDE fill out of methods.
30
-     * @return \EventEspressoAcceptanceTester;
31
-     */
32
-    protected function actor()
33
-    {
34
-        /** @var \EventEspressoAcceptanceTester $this */
35
-        return $this;
36
-    }
28
+	/**
29
+	 * Helper method for returning an instance of the Actor.  Intended to help with IDE fill out of methods.
30
+	 * @return \EventEspressoAcceptanceTester;
31
+	 */
32
+	protected function actor()
33
+	{
34
+		/** @var \EventEspressoAcceptanceTester $this */
35
+		return $this;
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * Use this to set the per page option for a list table page.
41
-     * Assumes you are on a page that has this field exposed.
42
-     *
43
-     * @param int|string $per_page_value
44
-     * @throws \Codeception\Exception\TestRuntimeException
45
-     */
46
-    public function setPerPageOptionForScreen($per_page_value)
47
-    {
48
-        $this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR);
49
-        $this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value);
50
-        $this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR);
51
-        $this->actor()->wait(8);
52
-    }
39
+	/**
40
+	 * Use this to set the per page option for a list table page.
41
+	 * Assumes you are on a page that has this field exposed.
42
+	 *
43
+	 * @param int|string $per_page_value
44
+	 * @throws \Codeception\Exception\TestRuntimeException
45
+	 */
46
+	public function setPerPageOptionForScreen($per_page_value)
47
+	{
48
+		$this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR);
49
+		$this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value);
50
+		$this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR);
51
+		$this->actor()->wait(8);
52
+	}
53 53
 
54 54
 
55 55
 
56
-    /**
57
-     * Use this to append a given value to a wpEditor instance.
58
-     * How it works is it first switched the instance to the text (or html) view so that the textarea is exposed and
59
-     * the value is added to the text area.
60
-     *
61
-     * @param $field_reference
62
-     * @param $value
63
-     * @throws \Codeception\Exception\ElementNotFound
64
-     */
65
-    public function appendToWPEditorField($field_reference, $value)
66
-    {
67
-        $this->actor()->click(CoreAdmin::wpEditorTextTabSelector($field_reference));
68
-        $this->actor()->appendField(CoreAdmin::wpEditorTextAreaSelector($field_reference), $value);
69
-    }
56
+	/**
57
+	 * Use this to append a given value to a wpEditor instance.
58
+	 * How it works is it first switched the instance to the text (or html) view so that the textarea is exposed and
59
+	 * the value is added to the text area.
60
+	 *
61
+	 * @param $field_reference
62
+	 * @param $value
63
+	 * @throws \Codeception\Exception\ElementNotFound
64
+	 */
65
+	public function appendToWPEditorField($field_reference, $value)
66
+	{
67
+		$this->actor()->click(CoreAdmin::wpEditorTextTabSelector($field_reference));
68
+		$this->actor()->appendField(CoreAdmin::wpEditorTextAreaSelector($field_reference), $value);
69
+	}
70 70
 }
Please login to merge, or discard this patch.
acceptance_tests/Page/CoreAdmin.php 2 patches
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -13,84 +13,84 @@
 block discarded – undo
13 13
 class CoreAdmin
14 14
 {
15 15
 
16
-    /**
17
-     * @var string
18
-     */
19
-    const URL_PREFIX = 'admin.php?page=';
20
-
21
-
22
-    /**
23
-     * This is the selector for the next page button on list tables.
24
-     * @var string
25
-     */
26
-    const ADMIN_LIST_TABLE_NEXT_PAGE_CLASS = '.next-page';
27
-
28
-
29
-    /**
30
-     * The selector for the search input submit button on list table pages
31
-     * @var string
32
-     */
33
-    const LIST_TABLE_SEARCH_SUBMIT_SELECTOR = '#search-submit';
34
-
35
-
36
-    /**
37
-     * Selector for the screen options dropdown.
38
-     * @var string
39
-     */
40
-    const WP_SCREEN_SETTINGS_LINK_SELECTOR = '#show-settings-link';
41
-
42
-
43
-    /**
44
-     * Selector for the per page field setting selector (found within screen options dropdown)
45
-     * @var string
46
-     */
47
-    const WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR = '.screen-per-page';
48
-
49
-
50
-    /**
51
-     * Selector for apply screen options settings.
52
-     * @var string
53
-     */
54
-    const WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR = '#screen-options-apply';
55
-
56
-
57
-    /**
58
-     * Get the EE admin url for the given properties.
59
-     * Note, this is JUST the endpoint for the admin route.  It is expected that the actor/test would be calling this
60
-     * with `amOnAdminPage` action.
61
-     *
62
-     * @param string $page
63
-     * @param string $action
64
-     * @param string $additional_params
65
-     * @return string
66
-     */
67
-    public static function adminUrl($page = 'espresso_events', $action = 'default', $additional_params = '')
68
-    {
69
-        $url = self::URL_PREFIX . $page;
70
-        $url .= $action ? '&action=' . $action : '';
71
-        $url .= $additional_params ? '&' . ltrim('&', ltrim('?', $additional_params)) : '';
72
-        return $url;
73
-    }
74
-
75
-
76
-    /**
77
-     * Returns the selector for the text tab switcher for a wp-editor instance.
78
-     * @param $field_reference
79
-     * @return string
80
-     */
81
-    public static function wpEditorTextTabSelector($field_reference)
82
-    {
83
-        return '#content-' . $field_reference . '-content-html';
84
-    }
85
-
86
-
87
-    /**
88
-     * Returns the selector for the textarea exposed when clicing the text tab switcher for a wp-editor instance.
89
-     * @param $field_reference
90
-     * @return string
91
-     */
92
-    public static function wpEditorTextAreaSelector($field_reference)
93
-    {
94
-        return '#content-' . $field_reference . '-content';
95
-    }
16
+	/**
17
+	 * @var string
18
+	 */
19
+	const URL_PREFIX = 'admin.php?page=';
20
+
21
+
22
+	/**
23
+	 * This is the selector for the next page button on list tables.
24
+	 * @var string
25
+	 */
26
+	const ADMIN_LIST_TABLE_NEXT_PAGE_CLASS = '.next-page';
27
+
28
+
29
+	/**
30
+	 * The selector for the search input submit button on list table pages
31
+	 * @var string
32
+	 */
33
+	const LIST_TABLE_SEARCH_SUBMIT_SELECTOR = '#search-submit';
34
+
35
+
36
+	/**
37
+	 * Selector for the screen options dropdown.
38
+	 * @var string
39
+	 */
40
+	const WP_SCREEN_SETTINGS_LINK_SELECTOR = '#show-settings-link';
41
+
42
+
43
+	/**
44
+	 * Selector for the per page field setting selector (found within screen options dropdown)
45
+	 * @var string
46
+	 */
47
+	const WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR = '.screen-per-page';
48
+
49
+
50
+	/**
51
+	 * Selector for apply screen options settings.
52
+	 * @var string
53
+	 */
54
+	const WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR = '#screen-options-apply';
55
+
56
+
57
+	/**
58
+	 * Get the EE admin url for the given properties.
59
+	 * Note, this is JUST the endpoint for the admin route.  It is expected that the actor/test would be calling this
60
+	 * with `amOnAdminPage` action.
61
+	 *
62
+	 * @param string $page
63
+	 * @param string $action
64
+	 * @param string $additional_params
65
+	 * @return string
66
+	 */
67
+	public static function adminUrl($page = 'espresso_events', $action = 'default', $additional_params = '')
68
+	{
69
+		$url = self::URL_PREFIX . $page;
70
+		$url .= $action ? '&action=' . $action : '';
71
+		$url .= $additional_params ? '&' . ltrim('&', ltrim('?', $additional_params)) : '';
72
+		return $url;
73
+	}
74
+
75
+
76
+	/**
77
+	 * Returns the selector for the text tab switcher for a wp-editor instance.
78
+	 * @param $field_reference
79
+	 * @return string
80
+	 */
81
+	public static function wpEditorTextTabSelector($field_reference)
82
+	{
83
+		return '#content-' . $field_reference . '-content-html';
84
+	}
85
+
86
+
87
+	/**
88
+	 * Returns the selector for the textarea exposed when clicing the text tab switcher for a wp-editor instance.
89
+	 * @param $field_reference
90
+	 * @return string
91
+	 */
92
+	public static function wpEditorTextAreaSelector($field_reference)
93
+	{
94
+		return '#content-' . $field_reference . '-content';
95
+	}
96 96
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public static function adminUrl($page = 'espresso_events', $action = 'default', $additional_params = '')
68 68
     {
69
-        $url = self::URL_PREFIX . $page;
70
-        $url .= $action ? '&action=' . $action : '';
71
-        $url .= $additional_params ? '&' . ltrim('&', ltrim('?', $additional_params)) : '';
69
+        $url = self::URL_PREFIX.$page;
70
+        $url .= $action ? '&action='.$action : '';
71
+        $url .= $additional_params ? '&'.ltrim('&', ltrim('?', $additional_params)) : '';
72 72
         return $url;
73 73
     }
74 74
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     public static function wpEditorTextTabSelector($field_reference)
82 82
     {
83
-        return '#content-' . $field_reference . '-content-html';
83
+        return '#content-'.$field_reference.'-content-html';
84 84
     }
85 85
 
86 86
 
@@ -91,6 +91,6 @@  discard block
 block discarded – undo
91 91
      */
92 92
     public static function wpEditorTextAreaSelector($field_reference)
93 93
     {
94
-        return '#content-' . $field_reference . '-content';
94
+        return '#content-'.$field_reference.'-content';
95 95
     }
96 96
 }
Please login to merge, or discard this patch.
acceptance_tests/Page/MessagesAdmin.php 1 patch
Indentation   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -12,255 +12,255 @@
 block discarded – undo
12 12
 class MessagesAdmin extends CoreAdmin
13 13
 {
14 14
 
15
-    /**
16
-     * Context slug for the admin messages context.
17
-     * @var string
18
-     */
19
-    const ADMIN_CONTEXT_SLUG = 'admin';
15
+	/**
16
+	 * Context slug for the admin messages context.
17
+	 * @var string
18
+	 */
19
+	const ADMIN_CONTEXT_SLUG = 'admin';
20 20
 
21
-    /**
22
-     * Context slug for the primary attendee messages context
23
-     * @var string
24
-     */
25
-    const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee';
21
+	/**
22
+	 * Context slug for the primary attendee messages context
23
+	 * @var string
24
+	 */
25
+	const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee';
26 26
 
27 27
 
28
-    /**
29
-     * Status reference for the EEM_Message::status_sent status.
30
-     * @var string
31
-     */
32
-    const MESSAGE_STATUS_SENT = 'MSN';
28
+	/**
29
+	 * Status reference for the EEM_Message::status_sent status.
30
+	 * @var string
31
+	 */
32
+	const MESSAGE_STATUS_SENT = 'MSN';
33 33
 
34 34
 
35
-    /**
36
-     * Message type slug for the Payment Failed message type
37
-     */
38
-    const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed';
35
+	/**
36
+	 * Message type slug for the Payment Failed message type
37
+	 */
38
+	const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed';
39 39
 
40 40
 
41
-    /**
42
-     * Selector for the Global Messages "Send on same request" field in the Messages Settings tab.
43
-     * @var string
44
-     */
45
-    const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR =
46
-        '#global_messages_settings-do-messages-on-same-request';
47
-
41
+	/**
42
+	 * Selector for the Global Messages "Send on same request" field in the Messages Settings tab.
43
+	 * @var string
44
+	 */
45
+	const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR =
46
+		'#global_messages_settings-do-messages-on-same-request';
47
+
48 48
 
49
-    /**
50
-     * Selector for the Global Messages Settings submit button in the Messages Settings tab.
51
-     * @var string
52
-     */
53
-    const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit';
54
-
55
-
56
-    /**
57
-     * This is the container where active message types for a messenger are found/dragged to.
58
-     * @var string
59
-     */
60
-    const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types';
61
-
62
-
63
-    /**
64
-     * Locator for the context switcher selector on the Message Template Editor page.
65
-     * @var string
66
-     */
67
-    const MESSAGES_CONTEXT_SWITCHER_SELECTOR = "//form[@id='ee-msg-context-switcher-frm']/select";
68
-
69
-
70
-    /**
71
-     * Locator for the context switcher submit button in the Message Template Editor page.
72
-     * @var string
73
-     */
74
-    const MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR = "#submit-msg-context-switcher-sbmt";
75
-
76
-
77
-    /**
78
-     * Locator for the dialog container used for housing viewed messages in the message activity list table.
79
-     * @var string
80
-     */
81
-    const MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR = '.ee-admin-dialog-container-inner-content';
82
-
83
-
84
-
85
-    /**
86
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
87
-     *                                  a string.
88
-     * @return string
89
-     */
90
-    public static function messageActivityListTableUrl($additional_params = '')
91
-    {
92
-        return self::adminUrl('espresso_messages', 'default', $additional_params);
93
-    }
94
-
95
-
96
-    /**
97
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
98
-     *                                  a string.
99
-     * @return string
100
-     */
101
-    public static function defaultMessageTemplateListTableUrl($additional_params = '')
102
-    {
103
-        return self::adminUrl('espresso_messages', 'global_mtps', $additional_params);
104
-    }
105
-
106
-
107
-    /**
108
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
109
-     *                                  a string.
110
-     * @return string
111
-     */
112
-    public static function customMessageTemplateListTableUrl($additional_params = '')
113
-    {
114
-        return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params);
115
-    }
116
-
117
-
118
-    /**
119
-     * @return string
120
-     */
121
-    public static function messageSettingsUrl()
122
-    {
123
-        return self::adminUrl('espresso_messages', 'settings');
124
-    }
125
-
126
-
127
-
128
-    public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger(
129
-        $message_type_slug,
130
-        $messenger_slug = 'email'
131
-    ) {
132
-        return "#$message_type_slug-messagetype-$messenger_slug";
133
-    }
134
-
135
-
136
-    /**
137
-     * @param string $message_type_slug
138
-     * @param string $context
139
-     * @return string
140
-     */
141
-    public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '')
142
-    {
143
-        return $context
144
-            ? '.' . $message_type_slug . '-' . $context . '-edit-link'
145
-            : '.' . $message_type_slug . '-edit-link';
146
-    }
147
-
148
-
149
-    /**
150
-     * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters.
151
-     *
152
-     * @param        $field
153
-     * @param        $message_type_label
154
-     * @param string $message_status
155
-     * @param string $messenger
156
-     * @param string $context
157
-     * @param string $table_cell_content_for_field
158
-     * @param int    $number_in_set   It's possible that the given parameters could match multiple items in the view.
159
-     *                                This allows you to indicate which item from the set to match.  If this is set to 0
160
-     *                                then all matches for the locator will be returned.
161
-     * @return string
162
-     */
163
-    public static function messagesActivityListTableCellSelectorFor(
164
-        $field,
165
-        $message_type_label,
166
-        $message_status = self::MESSAGE_STATUS_SENT,
167
-        $messenger = 'Email',
168
-        $context = 'Event Admin',
169
-        $table_cell_content_for_field = '',
170
-        $number_in_set = 1
171
-    ) {
172
-        $selector = $number_in_set > 0 ? '(' : '';
173
-        $selector .= "//tr[contains(@class, 'msg-status-$message_status')]"
174
-                     . "//td[contains(@class, 'message_type') and text()='$message_type_label']";
175
-        if ($messenger) {
176
-            $selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']";
177
-        }
178
-        $selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']";
179
-        $selector .= $table_cell_content_for_field
180
-            ? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']"
181
-            : "/ancestor::tr/td[contains(@class, 'column-$field')]";
182
-        $selector .= $number_in_set > 0 ? ")[$number_in_set]" : '';
183
-        return $selector;
184
-    }
185
-
186
-
187
-    /**
188
-     * Selector for the Create Custom button found in the message template list table.
189
-     * @param string $message_type_label
190
-     * @param string $messenger_label
191
-     * @return string
192
-     */
193
-    public static function createCustomButtonForMessageTypeAndMessenger($message_type_label, $messenger_label)
194
-    {
195
-        $selector = "//tr/td[contains(@class, 'message_type') and text()='$message_type_label']"
196
-                    . "//ancestor::tr/td[contains(@class, 'messenger') and contains(., '$messenger_label')]"
197
-                    . "//ancestor::tr/td/a[@class='button button-small']";
198
-        return $selector;
199
-    }
200
-
201
-
202
-    /**
203
-     * Note, this could potentially match multiple buttons in the view so the selector is intentionally restricted to
204
-     * the FIRST match (which will be the latest message sent if the table is default sorted).
205
-     *
206
-     * @param string $message_type_label    The visible message type label for the row you want to match
207
-     * @param string $message_status        The status of the message for the row you want to match.
208
-     * @param string $messenger             The visible messenger label for the row you want to match.
209
-     * @param string $context               The visible context label for the row you want to match.
210
-     * @param int    $number_in_set         It's possible that the given parameters could match multiple items in the
211
-     *                                      view. This allows you to indicate which item from the set to match.
212
-     * @return string
213
-     */
214
-    public static function messagesActivityListTableViewButtonSelectorFor(
215
-        $message_type_label,
216
-        $message_status = self::MESSAGE_STATUS_SENT,
217
-        $messenger = 'Email',
218
-        $context = 'Event Admin',
219
-        $number_in_set = 1
220
-    ) {
221
-        $selector = self::messagesActivityListTableCellSelectorFor(
222
-            'action',
223
-            $message_type_label,
224
-            $message_status,
225
-            $messenger,
226
-            $context,
227
-            '',
228
-            $number_in_set
229
-        );
230
-        $selector .= "/a/span[contains(@class, 'ee-message-action-link-view')"
231
-                     . " and not(contains(@class, 'ee-message-action-link-view_transaction'))]";
232
-        return $selector;
233
-    }
234
-
235
-
236
-
237
-    /**
238
-     * Locator for the delete action link for a message item in the message activity list table.
239
-     * Note: The link is not visible by default, so the column would need hovered over for the link to appear.
240
-     * @param        $message_type_label
241
-     * @param string $message_status
242
-     * @param string $messenger
243
-     * @param string $context
244
-     * @param int    $number_in_set
245
-     * @return string
246
-     */
247
-    public static function messagesActivityListTableDeleteActionSelectorFor(
248
-        $message_type_label,
249
-        $message_status = self::MESSAGE_STATUS_SENT,
250
-        $messenger = 'Email',
251
-        $context = 'Event Admin',
252
-        $number_in_set = 1
253
-    ) {
254
-        $selector = self::messagesActivityListTableCellSelectorFor(
255
-            'to',
256
-            $message_type_label,
257
-            $message_status,
258
-            $messenger,
259
-            $context,
260
-            '',
261
-            $number_in_set
262
-        );
263
-        $selector .= "/div/span[@class='delete']/a";
264
-        return $selector;
265
-    }
49
+	/**
50
+	 * Selector for the Global Messages Settings submit button in the Messages Settings tab.
51
+	 * @var string
52
+	 */
53
+	const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit';
54
+
55
+
56
+	/**
57
+	 * This is the container where active message types for a messenger are found/dragged to.
58
+	 * @var string
59
+	 */
60
+	const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types';
61
+
62
+
63
+	/**
64
+	 * Locator for the context switcher selector on the Message Template Editor page.
65
+	 * @var string
66
+	 */
67
+	const MESSAGES_CONTEXT_SWITCHER_SELECTOR = "//form[@id='ee-msg-context-switcher-frm']/select";
68
+
69
+
70
+	/**
71
+	 * Locator for the context switcher submit button in the Message Template Editor page.
72
+	 * @var string
73
+	 */
74
+	const MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR = "#submit-msg-context-switcher-sbmt";
75
+
76
+
77
+	/**
78
+	 * Locator for the dialog container used for housing viewed messages in the message activity list table.
79
+	 * @var string
80
+	 */
81
+	const MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR = '.ee-admin-dialog-container-inner-content';
82
+
83
+
84
+
85
+	/**
86
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
87
+	 *                                  a string.
88
+	 * @return string
89
+	 */
90
+	public static function messageActivityListTableUrl($additional_params = '')
91
+	{
92
+		return self::adminUrl('espresso_messages', 'default', $additional_params);
93
+	}
94
+
95
+
96
+	/**
97
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
98
+	 *                                  a string.
99
+	 * @return string
100
+	 */
101
+	public static function defaultMessageTemplateListTableUrl($additional_params = '')
102
+	{
103
+		return self::adminUrl('espresso_messages', 'global_mtps', $additional_params);
104
+	}
105
+
106
+
107
+	/**
108
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
109
+	 *                                  a string.
110
+	 * @return string
111
+	 */
112
+	public static function customMessageTemplateListTableUrl($additional_params = '')
113
+	{
114
+		return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params);
115
+	}
116
+
117
+
118
+	/**
119
+	 * @return string
120
+	 */
121
+	public static function messageSettingsUrl()
122
+	{
123
+		return self::adminUrl('espresso_messages', 'settings');
124
+	}
125
+
126
+
127
+
128
+	public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger(
129
+		$message_type_slug,
130
+		$messenger_slug = 'email'
131
+	) {
132
+		return "#$message_type_slug-messagetype-$messenger_slug";
133
+	}
134
+
135
+
136
+	/**
137
+	 * @param string $message_type_slug
138
+	 * @param string $context
139
+	 * @return string
140
+	 */
141
+	public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '')
142
+	{
143
+		return $context
144
+			? '.' . $message_type_slug . '-' . $context . '-edit-link'
145
+			: '.' . $message_type_slug . '-edit-link';
146
+	}
147
+
148
+
149
+	/**
150
+	 * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters.
151
+	 *
152
+	 * @param        $field
153
+	 * @param        $message_type_label
154
+	 * @param string $message_status
155
+	 * @param string $messenger
156
+	 * @param string $context
157
+	 * @param string $table_cell_content_for_field
158
+	 * @param int    $number_in_set   It's possible that the given parameters could match multiple items in the view.
159
+	 *                                This allows you to indicate which item from the set to match.  If this is set to 0
160
+	 *                                then all matches for the locator will be returned.
161
+	 * @return string
162
+	 */
163
+	public static function messagesActivityListTableCellSelectorFor(
164
+		$field,
165
+		$message_type_label,
166
+		$message_status = self::MESSAGE_STATUS_SENT,
167
+		$messenger = 'Email',
168
+		$context = 'Event Admin',
169
+		$table_cell_content_for_field = '',
170
+		$number_in_set = 1
171
+	) {
172
+		$selector = $number_in_set > 0 ? '(' : '';
173
+		$selector .= "//tr[contains(@class, 'msg-status-$message_status')]"
174
+					 . "//td[contains(@class, 'message_type') and text()='$message_type_label']";
175
+		if ($messenger) {
176
+			$selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']";
177
+		}
178
+		$selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']";
179
+		$selector .= $table_cell_content_for_field
180
+			? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']"
181
+			: "/ancestor::tr/td[contains(@class, 'column-$field')]";
182
+		$selector .= $number_in_set > 0 ? ")[$number_in_set]" : '';
183
+		return $selector;
184
+	}
185
+
186
+
187
+	/**
188
+	 * Selector for the Create Custom button found in the message template list table.
189
+	 * @param string $message_type_label
190
+	 * @param string $messenger_label
191
+	 * @return string
192
+	 */
193
+	public static function createCustomButtonForMessageTypeAndMessenger($message_type_label, $messenger_label)
194
+	{
195
+		$selector = "//tr/td[contains(@class, 'message_type') and text()='$message_type_label']"
196
+					. "//ancestor::tr/td[contains(@class, 'messenger') and contains(., '$messenger_label')]"
197
+					. "//ancestor::tr/td/a[@class='button button-small']";
198
+		return $selector;
199
+	}
200
+
201
+
202
+	/**
203
+	 * Note, this could potentially match multiple buttons in the view so the selector is intentionally restricted to
204
+	 * the FIRST match (which will be the latest message sent if the table is default sorted).
205
+	 *
206
+	 * @param string $message_type_label    The visible message type label for the row you want to match
207
+	 * @param string $message_status        The status of the message for the row you want to match.
208
+	 * @param string $messenger             The visible messenger label for the row you want to match.
209
+	 * @param string $context               The visible context label for the row you want to match.
210
+	 * @param int    $number_in_set         It's possible that the given parameters could match multiple items in the
211
+	 *                                      view. This allows you to indicate which item from the set to match.
212
+	 * @return string
213
+	 */
214
+	public static function messagesActivityListTableViewButtonSelectorFor(
215
+		$message_type_label,
216
+		$message_status = self::MESSAGE_STATUS_SENT,
217
+		$messenger = 'Email',
218
+		$context = 'Event Admin',
219
+		$number_in_set = 1
220
+	) {
221
+		$selector = self::messagesActivityListTableCellSelectorFor(
222
+			'action',
223
+			$message_type_label,
224
+			$message_status,
225
+			$messenger,
226
+			$context,
227
+			'',
228
+			$number_in_set
229
+		);
230
+		$selector .= "/a/span[contains(@class, 'ee-message-action-link-view')"
231
+					 . " and not(contains(@class, 'ee-message-action-link-view_transaction'))]";
232
+		return $selector;
233
+	}
234
+
235
+
236
+
237
+	/**
238
+	 * Locator for the delete action link for a message item in the message activity list table.
239
+	 * Note: The link is not visible by default, so the column would need hovered over for the link to appear.
240
+	 * @param        $message_type_label
241
+	 * @param string $message_status
242
+	 * @param string $messenger
243
+	 * @param string $context
244
+	 * @param int    $number_in_set
245
+	 * @return string
246
+	 */
247
+	public static function messagesActivityListTableDeleteActionSelectorFor(
248
+		$message_type_label,
249
+		$message_status = self::MESSAGE_STATUS_SENT,
250
+		$messenger = 'Email',
251
+		$context = 'Event Admin',
252
+		$number_in_set = 1
253
+	) {
254
+		$selector = self::messagesActivityListTableCellSelectorFor(
255
+			'to',
256
+			$message_type_label,
257
+			$message_status,
258
+			$messenger,
259
+			$context,
260
+			'',
261
+			$number_in_set
262
+		);
263
+		$selector .= "/div/span[@class='delete']/a";
264
+		return $selector;
265
+	}
266 266
 }
267 267
\ No newline at end of file
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Generator.lib.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
      * there's a single shared message template group among all the events.  Otherwise it returns null.
444 444
      *
445 445
      * @param array $event_ids
446
-     * @return EE_Message_Template_Group|null
446
+     * @return null|EE_Base_Class
447 447
      * @throws EE_Error
448 448
      */
449 449
     protected function _get_shared_message_template_for_events(array $event_ids)
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
     /**
477 477
      * Retrieves the global message template group for the current messenger and message type.
478 478
      *
479
-     * @return EE_Message_Template_Group|null
479
+     * @return null|EE_Base_Class
480 480
      * @throws EE_Error
481 481
      */
482 482
     protected function _get_global_message_template_group_for_current_messenger_and_message_type()
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
      * @param EE_Messages_Addressee     $recipient
618 618
      * @param array                     $templates formatted array of templates used for parsing data.
619 619
      * @param EE_Message_Template_Group $message_template_group
620
-     * @return bool|EE_Message
620
+     * @return EE_Message
621 621
      * @throws EE_Error
622 622
      */
623 623
     protected function _setup_message_object(
Please login to merge, or discard this patch.
Indentation   +931 added lines, -931 removed lines patch added patch discarded remove patch
@@ -13,935 +13,935 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * @type EE_Messages_Data_Handler_Collection
18
-     */
19
-    protected $_data_handler_collection;
20
-
21
-    /**
22
-     * @type  EE_Message_Template_Group_Collection
23
-     */
24
-    protected $_template_collection;
25
-
26
-    /**
27
-     * This will hold the data handler for the current EE_Message being generated.
28
-     *
29
-     * @type EE_Messages_incoming_data
30
-     */
31
-    protected $_current_data_handler;
32
-
33
-    /**
34
-     * This holds the EE_Messages_Queue that contains the messages to generate.
35
-     *
36
-     * @type EE_Messages_Queue
37
-     */
38
-    protected $_generation_queue;
39
-
40
-    /**
41
-     * This holds the EE_Messages_Queue that will store the generated EE_Message objects.
42
-     *
43
-     * @type EE_Messages_Queue
44
-     */
45
-    protected $_ready_queue;
46
-
47
-    /**
48
-     * This is a container for any error messages that get created through the generation
49
-     * process.
50
-     *
51
-     * @type array
52
-     */
53
-    protected $_error_msg = array();
54
-
55
-    /**
56
-     * Flag used to set when the current EE_Message in the generation queue has been verified.
57
-     *
58
-     * @type bool
59
-     */
60
-    protected $_verified = false;
61
-
62
-    /**
63
-     * This will hold the current messenger object corresponding with the current EE_Message in the generation queue.
64
-     *
65
-     * @type EE_messenger
66
-     */
67
-    protected $_current_messenger;
68
-
69
-    /**
70
-     * This will hold the current message type object corresponding with the current EE_Message in the generation queue.
71
-     *
72
-     * @type EE_message_type
73
-     */
74
-    protected $_current_message_type;
75
-
76
-    /**
77
-     * @type EEH_Parse_Shortcodes
78
-     */
79
-    protected $_shortcode_parser;
80
-
81
-
82
-    /**
83
-     * @param EE_Messages_Queue                     $generation_queue
84
-     * @param \EE_Messages_Queue                    $ready_queue
85
-     * @param \EE_Messages_Data_Handler_Collection  $data_handler_collection
86
-     * @param \EE_Message_Template_Group_Collection $template_collection
87
-     * @param \EEH_Parse_Shortcodes                 $shortcode_parser
88
-     */
89
-    public function __construct(
90
-        EE_Messages_Queue $generation_queue,
91
-        EE_Messages_Queue $ready_queue,
92
-        EE_Messages_Data_Handler_Collection $data_handler_collection,
93
-        EE_Message_Template_Group_Collection $template_collection,
94
-        EEH_Parse_Shortcodes $shortcode_parser
95
-    ) {
96
-        $this->_generation_queue        = $generation_queue;
97
-        $this->_ready_queue             = $ready_queue;
98
-        $this->_data_handler_collection = $data_handler_collection;
99
-        $this->_template_collection     = $template_collection;
100
-        $this->_shortcode_parser        = $shortcode_parser;
101
-    }
102
-
103
-
104
-    /**
105
-     * @return EE_Messages_Queue
106
-     */
107
-    public function generation_queue()
108
-    {
109
-        return $this->_generation_queue;
110
-    }
111
-
112
-
113
-    /**
114
-     *  This iterates through the provided queue and generates the EE_Message objects.
115
-     *  When iterating through the queue, the queued item that served as the base for generating other EE_Message
116
-     *  objects gets removed and the new EE_Message objects get added to a NEW queue.  The NEW queue is then returned
117
-     *  for the caller to decide what to do with it.
118
-     *
119
-     * @param   bool $save Whether to save the EE_Message objects in the new queue or just return.
120
-     * @return EE_Messages_Queue  The new queue for holding generated EE_Message objects.
121
-     */
122
-    public function generate($save = true)
123
-    {
124
-        //iterate through the messages in the queue, generate, and add to new queue.
125
-        $this->_generation_queue->get_message_repository()->rewind();
126
-        while ($this->_generation_queue->get_message_repository()->valid()) {
127
-            //reset "current" properties
128
-            $this->_reset_current_properties();
129
-
130
-            /** @type EE_Message $msg */
131
-            $msg = $this->_generation_queue->get_message_repository()->current();
132
-
133
-            /**
134
-             * need to get the next object and capture it for setting manually after deletes.  The reason is that when
135
-             * an object is removed from the repo then valid for the next object will fail.
136
-             */
137
-            $this->_generation_queue->get_message_repository()->next();
138
-            $next_msg = $this->_generation_queue->get_message_repository()->current();
139
-            //restore pointer to current item
140
-            $this->_generation_queue->get_message_repository()->set_current($msg);
141
-
142
-            //skip and delete if the current $msg is NOT incomplete (queued for generation)
143
-            if ($msg->STS_ID() !== EEM_Message::status_incomplete) {
144
-                //we keep this item in the db just remove from the repo.
145
-                $this->_generation_queue->get_message_repository()->remove($msg);
146
-                //next item
147
-                $this->_generation_queue->get_message_repository()->set_current($next_msg);
148
-                continue;
149
-            }
150
-
151
-            if ($this->_verify()) {
152
-                //let's get generating!
153
-                $this->_generate();
154
-            }
155
-
156
-            //don't persist debug_only messages if the messages system is not in debug mode.
157
-            if ($msg->STS_ID() === EEM_Message::status_debug_only
158
-                && ! EEM_Message::debug()
159
-            ) {
160
-                do_action(
161
-                    'AHEE__EE_Messages_Generator__generate__before_debug_delete',
162
-                    $msg,
163
-                    $this->_error_msg,
164
-                    $this->_current_messenger,
165
-                    $this->_current_message_type,
166
-                    $this->_current_data_handler
167
-                );
168
-                $this->_generation_queue->get_message_repository()->delete();
169
-                $this->_generation_queue->get_message_repository()->set_current($next_msg);
170
-                continue;
171
-            }
172
-
173
-            //if there are error messages then let's set the status and the error message.
174
-            if ($this->_error_msg) {
175
-                //if the status is already debug only, then let's leave it at that.
176
-                if ($msg->STS_ID() !== EEM_Message::status_debug_only) {
177
-                    $msg->set_STS_ID(EEM_Message::status_failed);
178
-                }
179
-                do_action(
180
-                    'AHEE__EE_Messages_Generator__generate__processing_failed_message',
181
-                    $msg,
182
-                    $this->_error_msg,
183
-                    $this->_current_messenger,
184
-                    $this->_current_message_type,
185
-                    $this->_current_data_handler
186
-                );
187
-                $msg->set_error_message(
188
-                    esc_html__('Message failed to generate for the following reasons: ', 'event_espresso')
189
-                    . "\n"
190
-                    . implode("\n", $this->_error_msg)
191
-                );
192
-                $msg->set_modified(time());
193
-            } else {
194
-                do_action(
195
-                    'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete',
196
-                    $msg,
197
-                    $this->_error_msg,
198
-                    $this->_current_messenger,
199
-                    $this->_current_message_type,
200
-                    $this->_current_data_handler
201
-                );
202
-                //remove from db
203
-                $this->_generation_queue->get_message_repository()->delete();
204
-            }
205
-            //next item
206
-            $this->_generation_queue->get_message_repository()->set_current($next_msg);
207
-        }
208
-
209
-        //generation queue is ALWAYS saved to record any errors in the generation process.
210
-        $this->_generation_queue->save();
211
-
212
-        /**
213
-         * save _ready_queue if flag set.
214
-         * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method.  This
215
-         * means if a field was added that is not a valid database column.  The EE_Message was already saved to the db
216
-         * so a EE_Extra_Meta entry could be created and attached to the EE_Message.  In those cases the save flag is
217
-         * irrelevant.
218
-         */
219
-        if ($save) {
220
-            $this->_ready_queue->save();
221
-        }
222
-
223
-        //final reset of properties
224
-        $this->_reset_current_properties();
225
-
226
-        return $this->_ready_queue;
227
-    }
228
-
229
-
230
-    /**
231
-     * This resets all the properties used for holding "current" values corresponding to the current EE_Message object
232
-     * in the generation queue.
233
-     */
234
-    protected function _reset_current_properties()
235
-    {
236
-        $this->_verified = false;
237
-        //make sure any _data value in the current message type is reset
238
-        if ($this->_current_message_type instanceof EE_message_type) {
239
-            $this->_current_message_type->reset_data();
240
-        }
241
-        $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null;
242
-    }
243
-
244
-
245
-    /**
246
-     * This proceeds with the actual generation of a message.  By the time this is called, there should already be a
247
-     * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the
248
-     * _generating_queue.
249
-     *
250
-     * @return bool Whether the message was successfully generated or not.
251
-     * @throws EE_Error
252
-     */
253
-    protected function _generate()
254
-    {
255
-        //double check verification has run and that everything is ready to work with (saves us having to validate
256
-        // everything again).
257
-        if (! $this->_verified) {
258
-            return false; //get out because we don't have a valid setup to work with.
259
-        }
260
-
261
-
262
-        try {
263
-            $addressees = $this->_current_message_type->get_addressees(
264
-                $this->_current_data_handler,
265
-                $this->_generation_queue->get_message_repository()->current()->context()
266
-            );
267
-        } catch (EE_Error $e) {
268
-            $this->_error_msg[] = $e->getMessage();
269
-            return false;
270
-        }
271
-
272
-
273
-        //if no addressees then get out because there is nothing to generation (possible bad data).
274
-        if (! $this->_valid_addressees($addressees)) {
275
-            do_action(
276
-                'AHEE__EE_Messages_Generator___generate__invalid_addressees',
277
-                $this->_generation_queue->get_message_repository()->current(),
278
-                $addressees,
279
-                $this->_current_messenger,
280
-                $this->_current_message_type,
281
-                $this->_current_data_handler
282
-            );
283
-            $this->_generation_queue->get_message_repository()->current()->set_STS_ID(
284
-                EEM_Message::status_debug_only
285
-            );
286
-            $this->_error_msg[] = esc_html__(
287
-                'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects.  There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.',
288
-                'event_espresso'
289
-            );
290
-            return false;
291
-        }
292
-
293
-        $message_template_group = $this->_get_message_template_group();
294
-
295
-        //in the unlikely event there is no EE_Message_Template_Group available, get out!
296
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
297
-            $this->_error_msg[] = esc_html__(
298
-                'Unable to get the Message Templates for the Message being generated.  No message template group accessible.',
299
-                'event_espresso'
300
-            );
301
-            return false;
302
-        }
303
-
304
-        //get formatted templates for using to parse and setup EE_Message objects.
305
-        $templates = $this->_get_templates($message_template_group);
306
-
307
-
308
-        //setup new EE_Message objects (and add to _ready_queue)
309
-        return $this->_assemble_messages($addressees, $templates, $message_template_group);
310
-    }
311
-
312
-
313
-    /**
314
-     * Retrieves the message template group being used for generating messages.
315
-     * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times.
316
-     *
317
-     * @return EE_Message_Template_Group|null
318
-     * @throws EE_Error
319
-     */
320
-    protected function _get_message_template_group()
321
-    {
322
-        //first see if there is a specific message template group requested (current message in the queue has a specific
323
-        //GRP_ID
324
-        $message_template_group = $this->_specific_message_template_group_from_queue();
325
-        if ($message_template_group instanceof EE_Message_Template_Group) {
326
-            return $message_template_group;
327
-        }
328
-
329
-        //get event_ids from the datahandler so we can check to see if there's already a message template group for them
330
-        //in the collection.
331
-        $event_ids              = $this->_get_event_ids_from_current_data_handler();
332
-        $message_template_group = $this->_template_collection->get_by_key(
333
-            $this->_template_collection->getKey(
334
-                $this->_current_messenger->name,
335
-                $this->_current_message_type->name,
336
-                $event_ids
337
-            )
338
-        );
339
-
340
-        //if we have a message template group then no need to hit the database, just return it.
341
-        if ($message_template_group instanceof EE_Message_Template_Group) {
342
-            return $message_template_group;
343
-        }
344
-
345
-        //okay made it here, so let's get the global group first for this messenger and message type to ensure
346
-        //there is no override set.
347
-        $global_message_template_group = $this->_get_global_message_template_group_for_current_messenger_and_message_type();
348
-
349
-        if ($global_message_template_group instanceof EE_Message_Template_Group
350
-            && $global_message_template_group->get('MTP_is_override')
351
-        ) {
352
-            return $global_message_template_group;
353
-        }
354
-
355
-        //if we're still here, that means there was no message template group for the events in the collection and
356
-        //the global message template group for the messenger and message type is not set for override.  So next step is
357
-        //to see if there is a common shared custom message template group for this set of events.
358
-        $message_template_group = $this->_get_shared_message_template_for_events($event_ids);
359
-        if ($message_template_group instanceof EE_Message_Template_Group) {
360
-            return $message_template_group;
361
-        }
362
-
363
-        //STILL here?  Okay that means the fallback is to just use the global message template group for this event set.
364
-        //So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request)
365
-        //and return it.
366
-        if ($global_message_template_group instanceof EE_Message_Template_Group) {
367
-            $this->_template_collection->add(
368
-                $global_message_template_group,
369
-                $event_ids
370
-            );
371
-            return $global_message_template_group;
372
-        }
373
-
374
-        //if we land here that means there's NO active message template group for this set.
375
-        //TODO this will be a good target for some optimization down the road.  Whenever there is no active message
376
-        //template group for a given event set then cache that result so we don't repeat the logic.  However, for now,
377
-        //this should likely bit hit rarely enough that it's not a significant issue.
378
-        return null;
379
-    }
380
-
381
-
382
-    /**
383
-     * This checks the current message in the queue and determines if there is a specific Message Template Group
384
-     * requested for that message.
385
-     *
386
-     * @return EE_Message_Template_Group|null
387
-     */
388
-    protected function _specific_message_template_group_from_queue()
389
-    {
390
-        //is there a GRP_ID already on the EE_Message object?  If there is, then a specific template has been requested
391
-        //so let's use that.
392
-        $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID();
393
-
394
-        if ($GRP_ID) {
395
-            //attempt to retrieve from repo first
396
-            $message_template_group = $this->_template_collection->get_by_ID($GRP_ID);
397
-            if ($message_template_group instanceof EE_Message_Template_Group) {
398
-                return $message_template_group;  //got it!
399
-            }
400
-
401
-            //nope don't have it yet.  Get from DB then add to repo if its not here, then that means the current GRP_ID
402
-            //is not valid, so we'll continue on in the code assuming there's NO GRP_ID.
403
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
404
-            if ($message_template_group instanceof EE_Message_Template_Group) {
405
-                $this->_template_collection->add($message_template_group);
406
-                return $message_template_group;
407
-            }
408
-        }
409
-        return null;
410
-    }
411
-
412
-
413
-    /**
414
-     * Returns whether the event ids passed in all share the same message template group for the current message type
415
-     * and messenger.
416
-     *
417
-     * @param array $event_ids
418
-     * @return bool true means they DO share the same message template group, false means they don't.
419
-     * @throws EE_Error
420
-     */
421
-    protected function _queue_shares_same_message_template_group_for_events(array $event_ids)
422
-    {
423
-        foreach ($this->_current_data_handler->events as $event) {
424
-            $event_ids[$event['ID']] = $event['ID'];
425
-        }
426
-        $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count(
427
-            array(
428
-                array(
429
-                    'Event.EVT_ID'           => array('IN', $event_ids),
430
-                    'MTP_messenger'    => $this->_current_messenger->name,
431
-                    'MTP_message_type' => $this->_current_message_type->name,
432
-                ),
433
-            ),
434
-            'GRP_ID',
435
-            true
436
-        );
437
-        return $count_of_message_template_groups === 1;
438
-    }
439
-
440
-
441
-    /**
442
-     * This will get the shared message template group for events that are in the current data handler but ONLY if
443
-     * there's a single shared message template group among all the events.  Otherwise it returns null.
444
-     *
445
-     * @param array $event_ids
446
-     * @return EE_Message_Template_Group|null
447
-     * @throws EE_Error
448
-     */
449
-    protected function _get_shared_message_template_for_events(array $event_ids)
450
-    {
451
-        $message_template_group = null;
452
-        if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) {
453
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one(
454
-                array(
455
-                    array(
456
-                        'Event.EVT_ID'           => array('IN', $event_ids),
457
-                        'MTP_messenger'    => $this->_current_messenger->name,
458
-                        'MTP_message_type' => $this->_current_message_type->name,
459
-                        'MTP_is_active'    => true,
460
-                    ),
461
-                    'group_by' => 'GRP_ID',
462
-                )
463
-            );
464
-            //store this in the collection if its valid
465
-            if ($message_template_group instanceof EE_Message_Template_Group) {
466
-                $this->_template_collection->add(
467
-                    $message_template_group,
468
-                    $event_ids
469
-                );
470
-            }
471
-        }
472
-        return $message_template_group;
473
-    }
474
-
475
-
476
-    /**
477
-     * Retrieves the global message template group for the current messenger and message type.
478
-     *
479
-     * @return EE_Message_Template_Group|null
480
-     * @throws EE_Error
481
-     */
482
-    protected function _get_global_message_template_group_for_current_messenger_and_message_type()
483
-    {
484
-        //first check the collection (we use an array with 0 in it to represent global groups).
485
-        $global_message_template_group = $this->_template_collection->get_by_key(
486
-            $this->_template_collection->getKey(
487
-                $this->_current_messenger->name,
488
-                $this->_current_message_type->name,
489
-                array(0)
490
-            )
491
-        );
492
-
493
-        //if we don't have a group lets hit the db.
494
-        if (! $global_message_template_group instanceof EE_Message_Template_Group) {
495
-            $global_message_template_group = EEM_Message_Template_Group::instance()->get_one(
496
-                array(
497
-                    array(
498
-                        'MTP_messenger'    => $this->_current_messenger->name,
499
-                        'MTP_message_type' => $this->_current_message_type->name,
500
-                        'MTP_is_active'    => true,
501
-                        'MTP_is_global'    => true,
502
-                    ),
503
-                )
504
-            );
505
-            //if we have a group, add it to the collection.
506
-            if ($global_message_template_group instanceof EE_Message_Template_Group) {
507
-                $this->_template_collection->add(
508
-                    $global_message_template_group,
509
-                    array(0)
510
-                );
511
-            }
512
-        }
513
-        return $global_message_template_group;
514
-    }
515
-
516
-
517
-    /**
518
-     * Returns an array of event ids for all the events within the current data handler.
519
-     *
520
-     * @return array
521
-     */
522
-    protected function _get_event_ids_from_current_data_handler()
523
-    {
524
-        $event_ids = array();
525
-        foreach ($this->_current_data_handler->events as $event) {
526
-            $event_ids[$event['ID']] = $event['ID'];
527
-        }
528
-        return $event_ids;
529
-    }
530
-
531
-
532
-    /**
533
-     *  Retrieves formatted array of template information for each context specific to the given
534
-     *  EE_Message_Template_Group
535
-     *
536
-     * @param EE_Message_Template_Group $message_template_group
537
-     * @return array The returned array is in this structure:
538
-     *                          array(
539
-     *                          'field_name' => array(
540
-     *                          'context' => 'content'
541
-     *                          )
542
-     *                          )
543
-     * @throws EE_Error
544
-     */
545
-    protected function _get_templates(EE_Message_Template_Group $message_template_group)
546
-    {
547
-        $templates         = array();
548
-        $context_templates = $message_template_group->context_templates();
549
-        foreach ($context_templates as $context => $template_fields) {
550
-            foreach ($template_fields as $template_field => $template_obj) {
551
-                if (! $template_obj instanceof EE_Message_Template) {
552
-                    continue;
553
-                }
554
-                $templates[$template_field][$context] = $template_obj->get('MTP_content');
555
-            }
556
-        }
557
-        return $templates;
558
-    }
559
-
560
-
561
-    /**
562
-     * Assembles new fully generated EE_Message objects and adds to _ready_queue
563
-     *
564
-     * @param array                     $addressees  Array of EE_Messages_Addressee objects indexed by message type
565
-     *                                               context.
566
-     * @param array                     $templates   formatted array of templates used for parsing data.
567
-     * @param EE_Message_Template_Group $message_template_group
568
-     * @return bool   true if message generation went a-ok.  false if some sort of exception occurred.  Note: The
569
-     *                                               method will attempt to generate ALL EE_Message objects and add to
570
-     *                                               the _ready_queue.  Successfully generated messages get added to the
571
-     *                                               queue with EEM_Message::status_idle, unsuccessfully generated
572
-     *                                               messages will get added to the queue as EEM_Message::status_failed.
573
-     *                                               Very rarely should "false" be returned from this method.
574
-     */
575
-    protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group)
576
-    {
577
-
578
-        //if templates are empty then get out because we can't generate anything.
579
-        if (! $templates) {
580
-            $this->_error_msg[] = esc_html__(
581
-                'Unable to assemble messages because there are no templates retrieved for generating the messages with',
582
-                'event_espresso'
583
-            );
584
-            return false;
585
-        }
586
-
587
-        //We use this as the counter for generated messages because don't forget we may be executing this inside of a
588
-        //generation_queue.  So _ready_queue may have generated EE_Message objects already.
589
-        $generated_count = 0;
590
-        foreach ($addressees as $context => $recipients) {
591
-            foreach ($recipients as $recipient) {
592
-                $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group);
593
-                if ($message instanceof EE_Message) {
594
-                    $this->_ready_queue->add(
595
-                        $message,
596
-                        array(),
597
-                        $this->_generation_queue->get_message_repository()->is_preview(),
598
-                        $this->_generation_queue->get_message_repository()->is_test_send()
599
-                    );
600
-                    $generated_count++;
601
-                }
602
-
603
-                //if the current MSG being generated is for a test send then we'll only use ONE message in the generation.
604
-                if ($this->_generation_queue->get_message_repository()->is_test_send()) {
605
-                    break 2;
606
-                }
607
-            }
608
-        }
609
-
610
-        //if there are no generated messages then something else fatal went wrong.
611
-        return $generated_count > 0;
612
-    }
613
-
614
-
615
-    /**
616
-     * @param string                    $context   The context for the generated message.
617
-     * @param EE_Messages_Addressee     $recipient
618
-     * @param array                     $templates formatted array of templates used for parsing data.
619
-     * @param EE_Message_Template_Group $message_template_group
620
-     * @return bool|EE_Message
621
-     * @throws EE_Error
622
-     */
623
-    protected function _setup_message_object(
624
-        $context,
625
-        EE_Messages_Addressee $recipient,
626
-        $templates,
627
-        EE_Message_Template_Group $message_template_group
628
-    ) {
629
-        //stuff we already know
630
-        $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0;
631
-        $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction
632
-            ? $this->_current_data_handler->txn->ID()
633
-            : $transaction_id;
634
-        $message_fields = array(
635
-            'GRP_ID'           => $message_template_group->ID(),
636
-            'TXN_ID'           => $transaction_id,
637
-            'MSG_messenger'    => $this->_current_messenger->name,
638
-            'MSG_message_type' => $this->_current_message_type->name,
639
-            'MSG_context'      => $context,
640
-        );
641
-
642
-        //recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab
643
-        // the info from the att_obj found in the EE_Messages_Addressee object.
644
-        if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) {
645
-            $message_fields['MSG_recipient_ID']   = $recipient->att_obj instanceof EE_Attendee
646
-                ? $recipient->att_obj->ID()
647
-                : 0;
648
-            $message_fields['MSG_recipient_type'] = 'Attendee';
649
-        } else {
650
-            $message_fields['MSG_recipient_ID']   = $recipient->recipient_id;
651
-            $message_fields['MSG_recipient_type'] = $recipient->recipient_type;
652
-        }
653
-        $message = EE_Message_Factory::create($message_fields);
654
-
655
-        //grab valid shortcodes for shortcode parser
656
-        $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes();
657
-        $m_shortcodes  = $this->_current_messenger->get_valid_shortcodes();
658
-
659
-        //if the 'to' field is empty (messages will ALWAYS have a "to" field, then we get out because that means this
660
-        //context is turned off) EXCEPT if we're previewing
661
-        if (empty($templates['to'][$context])
662
-            && ! $this->_generation_queue->get_message_repository()->is_preview()
663
-            && ! $this->_current_messenger->allow_empty_to_field()
664
-        ) {
665
-            //we silently exit here and do NOT record a fail because the message is "turned off" by having no "to"
666
-            //field.
667
-            return false;
668
-        }
669
-        $error_msg = array();
670
-        foreach ($templates as $field => $field_context) {
671
-            $error_msg = array();
672
-            //let's setup the valid shortcodes for the incoming context.
673
-            $valid_shortcodes = $mt_shortcodes[$context];
674
-            //merge in valid shortcodes for the field.
675
-            $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes;
676
-            if (isset($templates[$field][$context])) {
677
-                //prefix field.
678
-                $column_name = 'MSG_' . $field;
679
-                try {
680
-                    $content = $this->_shortcode_parser->parse_message_template(
681
-                        $templates[$field][$context],
682
-                        $recipient,
683
-                        $shortcodes,
684
-                        $this->_current_message_type,
685
-                        $this->_current_messenger,
686
-                        $message
687
-                    );
688
-                    $message->set_field_or_extra_meta($column_name, $content);
689
-                } catch (EE_Error $e) {
690
-                    $error_msg[] = sprintf(
691
-                        esc_html__(
692
-                            'There was a problem generating the content for the field %s: %s',
693
-                            'event_espresso'
694
-                        ),
695
-                        $field,
696
-                        $e->getMessage()
697
-                    );
698
-                    $message->set_STS_ID(EEM_Message::status_failed);
699
-                }
700
-            }
701
-        }
702
-
703
-        if ($message->STS_ID() === EEM_Message::status_failed) {
704
-            $error_msg = esc_html__('There were problems generating this message:', 'event_espresso')
705
-                         . "\n"
706
-                         . implode("\n", $error_msg);
707
-            $message->set_error_message($error_msg);
708
-        } else {
709
-            $message->set_STS_ID(EEM_Message::status_idle);
710
-        }
711
-        return $message;
712
-    }
713
-
714
-
715
-    /**
716
-     * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate
717
-     * error message if either is missing.
718
-     *
719
-     * @return bool         true means there were no errors, false means there were errors.
720
-     */
721
-    protected function _verify()
722
-    {
723
-        //reset error message to an empty array.
724
-        $this->_error_msg = array();
725
-        $valid            = true;
726
-        $valid            = $valid ? $this->_validate_messenger_and_message_type() : $valid;
727
-        $valid            = $valid ? $this->_validate_and_setup_data() : $valid;
728
-
729
-        //set the verified flag so we know everything has been validated.
730
-        $this->_verified = $valid;
731
-
732
-        return $valid;
733
-    }
734
-
735
-
736
-    /**
737
-     * This accepts an array and validates that it is an array indexed by context with each value being an array of
738
-     * EE_Messages_Addressee objects.
739
-     *
740
-     * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[]
741
-     * @return bool
742
-     */
743
-    protected function _valid_addressees($addressees)
744
-    {
745
-        if (! $addressees || ! is_array($addressees)) {
746
-            return false;
747
-        }
748
-
749
-        foreach ($addressees as $addressee_array) {
750
-            foreach ($addressee_array as $addressee) {
751
-                if (! $addressee instanceof EE_Messages_Addressee) {
752
-                    return false;
753
-                }
754
-            }
755
-        }
756
-        return true;
757
-    }
758
-
759
-
760
-    /**
761
-     * This validates the messenger, message type, and presences of generation data for the current EE_Message in the
762
-     * queue. This process sets error messages if something is wrong.
763
-     *
764
-     * @return bool   true is if there are no errors.  false is if there is.
765
-     */
766
-    protected function _validate_messenger_and_message_type()
767
-    {
768
-
769
-        //first are there any existing error messages?  If so then return.
770
-        if ($this->_error_msg) {
771
-            return false;
772
-        }
773
-        /** @type EE_Message $message */
774
-        $message = $this->_generation_queue->get_message_repository()->current();
775
-        try {
776
-            $this->_current_messenger = $message->valid_messenger(true)
777
-                ? $message->messenger_object()
778
-                : null;
779
-        } catch (Exception $e) {
780
-            $this->_error_msg[] = $e->getMessage();
781
-        }
782
-        try {
783
-            $this->_current_message_type = $message->valid_message_type(true)
784
-                ? $message->message_type_object()
785
-                : null;
786
-        } catch (Exception $e) {
787
-            $this->_error_msg[] = $e->getMessage();
788
-        }
789
-
790
-        /**
791
-         * Check if there is any generation data, but only if this is not for a preview.
792
-         */
793
-        if (! $this->_generation_queue->get_message_repository()->get_generation_data()
794
-            && (
795
-                ! $this->_generation_queue->get_message_repository()->is_preview()
796
-                && $this->_generation_queue->get_message_repository()->get_data_handler()
797
-                   !== 'EE_Messages_Preview_incoming_data'
798
-            )
799
-        ) {
800
-            $this->_error_msg[] = esc_html__(
801
-                'There is no generation data for this message. Unable to generate.',
802
-                'event_espresso'
803
-            );
804
-        }
805
-
806
-        return empty($this->_error_msg);
807
-    }
808
-
809
-
810
-    /**
811
-     * This method retrieves the expected data handler for the message type and validates the generation data for that
812
-     * data handler.
813
-     *
814
-     * @return bool true means there are no errors.  false means there were errors (and handler did not get setup).
815
-     */
816
-    protected function _validate_and_setup_data()
817
-    {
818
-
819
-        //First, are there any existing error messages?  If so, return because if there were errors elsewhere this can't
820
-        //be used anyways.
821
-        if ($this->_error_msg) {
822
-            return false;
823
-        }
824
-
825
-        $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data();
826
-
827
-        /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually */
828
-        $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler()
829
-            ? $this->_generation_queue->get_message_repository()->get_data_handler()
830
-            : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data';
831
-
832
-        //If this EE_Message is for a preview, then let's switch out to the preview data handler.
833
-        if ($this->_generation_queue->get_message_repository()->is_preview()) {
834
-            $data_handler_class_name = 'EE_Messages_Preview_incoming_data';
835
-        }
836
-
837
-        //First get the class name for the data handler (and also verifies it exists.
838
-        if (! class_exists($data_handler_class_name)) {
839
-            $this->_error_msg[] = sprintf(
840
-                esc_html__(
841
-                    'The included data handler class name does not match any valid, accessible, "%1$s" classes.  Looking for %2$s.',
842
-                    'event_espresso'
843
-                ),
844
-                'EE_Messages_incoming_data',
845
-                $data_handler_class_name
846
-            );
847
-            return false;
848
-        }
849
-
850
-        //convert generation_data for data_handler_instantiation.
851
-        $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data);
852
-
853
-        //note, this may set error messages as well.
854
-        $this->_set_data_handler($generation_data, $data_handler_class_name);
855
-
856
-        return empty($this->_error_msg);
857
-    }
858
-
859
-
860
-    /**
861
-     * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and
862
-     * adds it to the _data repository.
863
-     *
864
-     * @param mixed  $generating_data           This is data expected by the instantiated data handler.
865
-     * @param string $data_handler_class_name   This is the reference string indicating what data handler is being
866
-     *                                          instantiated.
867
-     * @return void .
868
-     * @throws EE_Error
869
-     * @throws ReflectionException
870
-     */
871
-    protected function _set_data_handler($generating_data, $data_handler_class_name)
872
-    {
873
-        //valid classname for the data handler.  Now let's setup the key for the data handler repository to see if there
874
-        //is already a ready data handler in the repository.
875
-        $this->_current_data_handler = $this->_data_handler_collection->get_by_key(
876
-            $this->_data_handler_collection->get_key(
877
-                $data_handler_class_name,
878
-                $generating_data
879
-            )
880
-        );
881
-        if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) {
882
-            //no saved data_handler in the repo so let's set one up and add it to the repo.
883
-            try {
884
-                $this->_current_data_handler = new $data_handler_class_name($generating_data);
885
-                $this->_data_handler_collection->add($this->_current_data_handler, $generating_data);
886
-            } catch (EE_Error $e) {
887
-                $this->_error_msg[] = $e->get_error();
888
-            }
889
-        }
890
-    }
891
-
892
-
893
-    /**
894
-     * The queued EE_Message for generation does not save the data used for generation as objects
895
-     * because serialization of those objects could be problematic if the data is saved to the db.
896
-     * So this method calls the static method on the associated data_handler for the given message_type
897
-     * and that preps the data for later instantiation when generating.
898
-     *
899
-     * @param EE_Message_To_Generate $message_to_generate
900
-     * @param bool                   $preview Indicate whether this is being used for a preview or not.
901
-     * @return mixed Prepped data for persisting to the queue.  false is returned if unable to prep data.
902
-     */
903
-    protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview)
904
-    {
905
-        /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */
906
-        $data_handler = $message_to_generate->get_data_handler_class_name($preview);
907
-        if (! $message_to_generate->valid()) {
908
-            return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid.
909
-        }
910
-        return $data_handler::convert_data_for_persistent_storage($message_to_generate->data());
911
-    }
912
-
913
-
914
-    /**
915
-     * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue.
916
-     *
917
-     * @param EE_Message_To_Generate $message_to_generate
918
-     * @param bool                   $test_send Whether this is just a test send or not.  Typically used for previews.
919
-     */
920
-    public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false)
921
-    {
922
-        //prep data
923
-        $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview());
924
-
925
-        $message = $message_to_generate->get_EE_Message();
926
-
927
-        //is there a GRP_ID in the request?
928
-        if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) {
929
-            $message->set_GRP_ID($GRP_ID);
930
-        }
931
-
932
-        if ($data === false) {
933
-            $message->set_STS_ID(EEM_Message::status_failed);
934
-            $message->set_error_message(
935
-                esc_html__(
936
-                    'Unable to prepare data for persistence to the database.',
937
-                    'event_espresso'
938
-                )
939
-            );
940
-        } else {
941
-            //make sure that the data handler is cached on the message as well
942
-            $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name();
943
-        }
944
-
945
-        $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send);
946
-    }
16
+	/**
17
+	 * @type EE_Messages_Data_Handler_Collection
18
+	 */
19
+	protected $_data_handler_collection;
20
+
21
+	/**
22
+	 * @type  EE_Message_Template_Group_Collection
23
+	 */
24
+	protected $_template_collection;
25
+
26
+	/**
27
+	 * This will hold the data handler for the current EE_Message being generated.
28
+	 *
29
+	 * @type EE_Messages_incoming_data
30
+	 */
31
+	protected $_current_data_handler;
32
+
33
+	/**
34
+	 * This holds the EE_Messages_Queue that contains the messages to generate.
35
+	 *
36
+	 * @type EE_Messages_Queue
37
+	 */
38
+	protected $_generation_queue;
39
+
40
+	/**
41
+	 * This holds the EE_Messages_Queue that will store the generated EE_Message objects.
42
+	 *
43
+	 * @type EE_Messages_Queue
44
+	 */
45
+	protected $_ready_queue;
46
+
47
+	/**
48
+	 * This is a container for any error messages that get created through the generation
49
+	 * process.
50
+	 *
51
+	 * @type array
52
+	 */
53
+	protected $_error_msg = array();
54
+
55
+	/**
56
+	 * Flag used to set when the current EE_Message in the generation queue has been verified.
57
+	 *
58
+	 * @type bool
59
+	 */
60
+	protected $_verified = false;
61
+
62
+	/**
63
+	 * This will hold the current messenger object corresponding with the current EE_Message in the generation queue.
64
+	 *
65
+	 * @type EE_messenger
66
+	 */
67
+	protected $_current_messenger;
68
+
69
+	/**
70
+	 * This will hold the current message type object corresponding with the current EE_Message in the generation queue.
71
+	 *
72
+	 * @type EE_message_type
73
+	 */
74
+	protected $_current_message_type;
75
+
76
+	/**
77
+	 * @type EEH_Parse_Shortcodes
78
+	 */
79
+	protected $_shortcode_parser;
80
+
81
+
82
+	/**
83
+	 * @param EE_Messages_Queue                     $generation_queue
84
+	 * @param \EE_Messages_Queue                    $ready_queue
85
+	 * @param \EE_Messages_Data_Handler_Collection  $data_handler_collection
86
+	 * @param \EE_Message_Template_Group_Collection $template_collection
87
+	 * @param \EEH_Parse_Shortcodes                 $shortcode_parser
88
+	 */
89
+	public function __construct(
90
+		EE_Messages_Queue $generation_queue,
91
+		EE_Messages_Queue $ready_queue,
92
+		EE_Messages_Data_Handler_Collection $data_handler_collection,
93
+		EE_Message_Template_Group_Collection $template_collection,
94
+		EEH_Parse_Shortcodes $shortcode_parser
95
+	) {
96
+		$this->_generation_queue        = $generation_queue;
97
+		$this->_ready_queue             = $ready_queue;
98
+		$this->_data_handler_collection = $data_handler_collection;
99
+		$this->_template_collection     = $template_collection;
100
+		$this->_shortcode_parser        = $shortcode_parser;
101
+	}
102
+
103
+
104
+	/**
105
+	 * @return EE_Messages_Queue
106
+	 */
107
+	public function generation_queue()
108
+	{
109
+		return $this->_generation_queue;
110
+	}
111
+
112
+
113
+	/**
114
+	 *  This iterates through the provided queue and generates the EE_Message objects.
115
+	 *  When iterating through the queue, the queued item that served as the base for generating other EE_Message
116
+	 *  objects gets removed and the new EE_Message objects get added to a NEW queue.  The NEW queue is then returned
117
+	 *  for the caller to decide what to do with it.
118
+	 *
119
+	 * @param   bool $save Whether to save the EE_Message objects in the new queue or just return.
120
+	 * @return EE_Messages_Queue  The new queue for holding generated EE_Message objects.
121
+	 */
122
+	public function generate($save = true)
123
+	{
124
+		//iterate through the messages in the queue, generate, and add to new queue.
125
+		$this->_generation_queue->get_message_repository()->rewind();
126
+		while ($this->_generation_queue->get_message_repository()->valid()) {
127
+			//reset "current" properties
128
+			$this->_reset_current_properties();
129
+
130
+			/** @type EE_Message $msg */
131
+			$msg = $this->_generation_queue->get_message_repository()->current();
132
+
133
+			/**
134
+			 * need to get the next object and capture it for setting manually after deletes.  The reason is that when
135
+			 * an object is removed from the repo then valid for the next object will fail.
136
+			 */
137
+			$this->_generation_queue->get_message_repository()->next();
138
+			$next_msg = $this->_generation_queue->get_message_repository()->current();
139
+			//restore pointer to current item
140
+			$this->_generation_queue->get_message_repository()->set_current($msg);
141
+
142
+			//skip and delete if the current $msg is NOT incomplete (queued for generation)
143
+			if ($msg->STS_ID() !== EEM_Message::status_incomplete) {
144
+				//we keep this item in the db just remove from the repo.
145
+				$this->_generation_queue->get_message_repository()->remove($msg);
146
+				//next item
147
+				$this->_generation_queue->get_message_repository()->set_current($next_msg);
148
+				continue;
149
+			}
150
+
151
+			if ($this->_verify()) {
152
+				//let's get generating!
153
+				$this->_generate();
154
+			}
155
+
156
+			//don't persist debug_only messages if the messages system is not in debug mode.
157
+			if ($msg->STS_ID() === EEM_Message::status_debug_only
158
+				&& ! EEM_Message::debug()
159
+			) {
160
+				do_action(
161
+					'AHEE__EE_Messages_Generator__generate__before_debug_delete',
162
+					$msg,
163
+					$this->_error_msg,
164
+					$this->_current_messenger,
165
+					$this->_current_message_type,
166
+					$this->_current_data_handler
167
+				);
168
+				$this->_generation_queue->get_message_repository()->delete();
169
+				$this->_generation_queue->get_message_repository()->set_current($next_msg);
170
+				continue;
171
+			}
172
+
173
+			//if there are error messages then let's set the status and the error message.
174
+			if ($this->_error_msg) {
175
+				//if the status is already debug only, then let's leave it at that.
176
+				if ($msg->STS_ID() !== EEM_Message::status_debug_only) {
177
+					$msg->set_STS_ID(EEM_Message::status_failed);
178
+				}
179
+				do_action(
180
+					'AHEE__EE_Messages_Generator__generate__processing_failed_message',
181
+					$msg,
182
+					$this->_error_msg,
183
+					$this->_current_messenger,
184
+					$this->_current_message_type,
185
+					$this->_current_data_handler
186
+				);
187
+				$msg->set_error_message(
188
+					esc_html__('Message failed to generate for the following reasons: ', 'event_espresso')
189
+					. "\n"
190
+					. implode("\n", $this->_error_msg)
191
+				);
192
+				$msg->set_modified(time());
193
+			} else {
194
+				do_action(
195
+					'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete',
196
+					$msg,
197
+					$this->_error_msg,
198
+					$this->_current_messenger,
199
+					$this->_current_message_type,
200
+					$this->_current_data_handler
201
+				);
202
+				//remove from db
203
+				$this->_generation_queue->get_message_repository()->delete();
204
+			}
205
+			//next item
206
+			$this->_generation_queue->get_message_repository()->set_current($next_msg);
207
+		}
208
+
209
+		//generation queue is ALWAYS saved to record any errors in the generation process.
210
+		$this->_generation_queue->save();
211
+
212
+		/**
213
+		 * save _ready_queue if flag set.
214
+		 * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method.  This
215
+		 * means if a field was added that is not a valid database column.  The EE_Message was already saved to the db
216
+		 * so a EE_Extra_Meta entry could be created and attached to the EE_Message.  In those cases the save flag is
217
+		 * irrelevant.
218
+		 */
219
+		if ($save) {
220
+			$this->_ready_queue->save();
221
+		}
222
+
223
+		//final reset of properties
224
+		$this->_reset_current_properties();
225
+
226
+		return $this->_ready_queue;
227
+	}
228
+
229
+
230
+	/**
231
+	 * This resets all the properties used for holding "current" values corresponding to the current EE_Message object
232
+	 * in the generation queue.
233
+	 */
234
+	protected function _reset_current_properties()
235
+	{
236
+		$this->_verified = false;
237
+		//make sure any _data value in the current message type is reset
238
+		if ($this->_current_message_type instanceof EE_message_type) {
239
+			$this->_current_message_type->reset_data();
240
+		}
241
+		$this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null;
242
+	}
243
+
244
+
245
+	/**
246
+	 * This proceeds with the actual generation of a message.  By the time this is called, there should already be a
247
+	 * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the
248
+	 * _generating_queue.
249
+	 *
250
+	 * @return bool Whether the message was successfully generated or not.
251
+	 * @throws EE_Error
252
+	 */
253
+	protected function _generate()
254
+	{
255
+		//double check verification has run and that everything is ready to work with (saves us having to validate
256
+		// everything again).
257
+		if (! $this->_verified) {
258
+			return false; //get out because we don't have a valid setup to work with.
259
+		}
260
+
261
+
262
+		try {
263
+			$addressees = $this->_current_message_type->get_addressees(
264
+				$this->_current_data_handler,
265
+				$this->_generation_queue->get_message_repository()->current()->context()
266
+			);
267
+		} catch (EE_Error $e) {
268
+			$this->_error_msg[] = $e->getMessage();
269
+			return false;
270
+		}
271
+
272
+
273
+		//if no addressees then get out because there is nothing to generation (possible bad data).
274
+		if (! $this->_valid_addressees($addressees)) {
275
+			do_action(
276
+				'AHEE__EE_Messages_Generator___generate__invalid_addressees',
277
+				$this->_generation_queue->get_message_repository()->current(),
278
+				$addressees,
279
+				$this->_current_messenger,
280
+				$this->_current_message_type,
281
+				$this->_current_data_handler
282
+			);
283
+			$this->_generation_queue->get_message_repository()->current()->set_STS_ID(
284
+				EEM_Message::status_debug_only
285
+			);
286
+			$this->_error_msg[] = esc_html__(
287
+				'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects.  There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.',
288
+				'event_espresso'
289
+			);
290
+			return false;
291
+		}
292
+
293
+		$message_template_group = $this->_get_message_template_group();
294
+
295
+		//in the unlikely event there is no EE_Message_Template_Group available, get out!
296
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
297
+			$this->_error_msg[] = esc_html__(
298
+				'Unable to get the Message Templates for the Message being generated.  No message template group accessible.',
299
+				'event_espresso'
300
+			);
301
+			return false;
302
+		}
303
+
304
+		//get formatted templates for using to parse and setup EE_Message objects.
305
+		$templates = $this->_get_templates($message_template_group);
306
+
307
+
308
+		//setup new EE_Message objects (and add to _ready_queue)
309
+		return $this->_assemble_messages($addressees, $templates, $message_template_group);
310
+	}
311
+
312
+
313
+	/**
314
+	 * Retrieves the message template group being used for generating messages.
315
+	 * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times.
316
+	 *
317
+	 * @return EE_Message_Template_Group|null
318
+	 * @throws EE_Error
319
+	 */
320
+	protected function _get_message_template_group()
321
+	{
322
+		//first see if there is a specific message template group requested (current message in the queue has a specific
323
+		//GRP_ID
324
+		$message_template_group = $this->_specific_message_template_group_from_queue();
325
+		if ($message_template_group instanceof EE_Message_Template_Group) {
326
+			return $message_template_group;
327
+		}
328
+
329
+		//get event_ids from the datahandler so we can check to see if there's already a message template group for them
330
+		//in the collection.
331
+		$event_ids              = $this->_get_event_ids_from_current_data_handler();
332
+		$message_template_group = $this->_template_collection->get_by_key(
333
+			$this->_template_collection->getKey(
334
+				$this->_current_messenger->name,
335
+				$this->_current_message_type->name,
336
+				$event_ids
337
+			)
338
+		);
339
+
340
+		//if we have a message template group then no need to hit the database, just return it.
341
+		if ($message_template_group instanceof EE_Message_Template_Group) {
342
+			return $message_template_group;
343
+		}
344
+
345
+		//okay made it here, so let's get the global group first for this messenger and message type to ensure
346
+		//there is no override set.
347
+		$global_message_template_group = $this->_get_global_message_template_group_for_current_messenger_and_message_type();
348
+
349
+		if ($global_message_template_group instanceof EE_Message_Template_Group
350
+			&& $global_message_template_group->get('MTP_is_override')
351
+		) {
352
+			return $global_message_template_group;
353
+		}
354
+
355
+		//if we're still here, that means there was no message template group for the events in the collection and
356
+		//the global message template group for the messenger and message type is not set for override.  So next step is
357
+		//to see if there is a common shared custom message template group for this set of events.
358
+		$message_template_group = $this->_get_shared_message_template_for_events($event_ids);
359
+		if ($message_template_group instanceof EE_Message_Template_Group) {
360
+			return $message_template_group;
361
+		}
362
+
363
+		//STILL here?  Okay that means the fallback is to just use the global message template group for this event set.
364
+		//So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request)
365
+		//and return it.
366
+		if ($global_message_template_group instanceof EE_Message_Template_Group) {
367
+			$this->_template_collection->add(
368
+				$global_message_template_group,
369
+				$event_ids
370
+			);
371
+			return $global_message_template_group;
372
+		}
373
+
374
+		//if we land here that means there's NO active message template group for this set.
375
+		//TODO this will be a good target for some optimization down the road.  Whenever there is no active message
376
+		//template group for a given event set then cache that result so we don't repeat the logic.  However, for now,
377
+		//this should likely bit hit rarely enough that it's not a significant issue.
378
+		return null;
379
+	}
380
+
381
+
382
+	/**
383
+	 * This checks the current message in the queue and determines if there is a specific Message Template Group
384
+	 * requested for that message.
385
+	 *
386
+	 * @return EE_Message_Template_Group|null
387
+	 */
388
+	protected function _specific_message_template_group_from_queue()
389
+	{
390
+		//is there a GRP_ID already on the EE_Message object?  If there is, then a specific template has been requested
391
+		//so let's use that.
392
+		$GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID();
393
+
394
+		if ($GRP_ID) {
395
+			//attempt to retrieve from repo first
396
+			$message_template_group = $this->_template_collection->get_by_ID($GRP_ID);
397
+			if ($message_template_group instanceof EE_Message_Template_Group) {
398
+				return $message_template_group;  //got it!
399
+			}
400
+
401
+			//nope don't have it yet.  Get from DB then add to repo if its not here, then that means the current GRP_ID
402
+			//is not valid, so we'll continue on in the code assuming there's NO GRP_ID.
403
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
404
+			if ($message_template_group instanceof EE_Message_Template_Group) {
405
+				$this->_template_collection->add($message_template_group);
406
+				return $message_template_group;
407
+			}
408
+		}
409
+		return null;
410
+	}
411
+
412
+
413
+	/**
414
+	 * Returns whether the event ids passed in all share the same message template group for the current message type
415
+	 * and messenger.
416
+	 *
417
+	 * @param array $event_ids
418
+	 * @return bool true means they DO share the same message template group, false means they don't.
419
+	 * @throws EE_Error
420
+	 */
421
+	protected function _queue_shares_same_message_template_group_for_events(array $event_ids)
422
+	{
423
+		foreach ($this->_current_data_handler->events as $event) {
424
+			$event_ids[$event['ID']] = $event['ID'];
425
+		}
426
+		$count_of_message_template_groups = EEM_Message_Template_Group::instance()->count(
427
+			array(
428
+				array(
429
+					'Event.EVT_ID'           => array('IN', $event_ids),
430
+					'MTP_messenger'    => $this->_current_messenger->name,
431
+					'MTP_message_type' => $this->_current_message_type->name,
432
+				),
433
+			),
434
+			'GRP_ID',
435
+			true
436
+		);
437
+		return $count_of_message_template_groups === 1;
438
+	}
439
+
440
+
441
+	/**
442
+	 * This will get the shared message template group for events that are in the current data handler but ONLY if
443
+	 * there's a single shared message template group among all the events.  Otherwise it returns null.
444
+	 *
445
+	 * @param array $event_ids
446
+	 * @return EE_Message_Template_Group|null
447
+	 * @throws EE_Error
448
+	 */
449
+	protected function _get_shared_message_template_for_events(array $event_ids)
450
+	{
451
+		$message_template_group = null;
452
+		if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) {
453
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one(
454
+				array(
455
+					array(
456
+						'Event.EVT_ID'           => array('IN', $event_ids),
457
+						'MTP_messenger'    => $this->_current_messenger->name,
458
+						'MTP_message_type' => $this->_current_message_type->name,
459
+						'MTP_is_active'    => true,
460
+					),
461
+					'group_by' => 'GRP_ID',
462
+				)
463
+			);
464
+			//store this in the collection if its valid
465
+			if ($message_template_group instanceof EE_Message_Template_Group) {
466
+				$this->_template_collection->add(
467
+					$message_template_group,
468
+					$event_ids
469
+				);
470
+			}
471
+		}
472
+		return $message_template_group;
473
+	}
474
+
475
+
476
+	/**
477
+	 * Retrieves the global message template group for the current messenger and message type.
478
+	 *
479
+	 * @return EE_Message_Template_Group|null
480
+	 * @throws EE_Error
481
+	 */
482
+	protected function _get_global_message_template_group_for_current_messenger_and_message_type()
483
+	{
484
+		//first check the collection (we use an array with 0 in it to represent global groups).
485
+		$global_message_template_group = $this->_template_collection->get_by_key(
486
+			$this->_template_collection->getKey(
487
+				$this->_current_messenger->name,
488
+				$this->_current_message_type->name,
489
+				array(0)
490
+			)
491
+		);
492
+
493
+		//if we don't have a group lets hit the db.
494
+		if (! $global_message_template_group instanceof EE_Message_Template_Group) {
495
+			$global_message_template_group = EEM_Message_Template_Group::instance()->get_one(
496
+				array(
497
+					array(
498
+						'MTP_messenger'    => $this->_current_messenger->name,
499
+						'MTP_message_type' => $this->_current_message_type->name,
500
+						'MTP_is_active'    => true,
501
+						'MTP_is_global'    => true,
502
+					),
503
+				)
504
+			);
505
+			//if we have a group, add it to the collection.
506
+			if ($global_message_template_group instanceof EE_Message_Template_Group) {
507
+				$this->_template_collection->add(
508
+					$global_message_template_group,
509
+					array(0)
510
+				);
511
+			}
512
+		}
513
+		return $global_message_template_group;
514
+	}
515
+
516
+
517
+	/**
518
+	 * Returns an array of event ids for all the events within the current data handler.
519
+	 *
520
+	 * @return array
521
+	 */
522
+	protected function _get_event_ids_from_current_data_handler()
523
+	{
524
+		$event_ids = array();
525
+		foreach ($this->_current_data_handler->events as $event) {
526
+			$event_ids[$event['ID']] = $event['ID'];
527
+		}
528
+		return $event_ids;
529
+	}
530
+
531
+
532
+	/**
533
+	 *  Retrieves formatted array of template information for each context specific to the given
534
+	 *  EE_Message_Template_Group
535
+	 *
536
+	 * @param EE_Message_Template_Group $message_template_group
537
+	 * @return array The returned array is in this structure:
538
+	 *                          array(
539
+	 *                          'field_name' => array(
540
+	 *                          'context' => 'content'
541
+	 *                          )
542
+	 *                          )
543
+	 * @throws EE_Error
544
+	 */
545
+	protected function _get_templates(EE_Message_Template_Group $message_template_group)
546
+	{
547
+		$templates         = array();
548
+		$context_templates = $message_template_group->context_templates();
549
+		foreach ($context_templates as $context => $template_fields) {
550
+			foreach ($template_fields as $template_field => $template_obj) {
551
+				if (! $template_obj instanceof EE_Message_Template) {
552
+					continue;
553
+				}
554
+				$templates[$template_field][$context] = $template_obj->get('MTP_content');
555
+			}
556
+		}
557
+		return $templates;
558
+	}
559
+
560
+
561
+	/**
562
+	 * Assembles new fully generated EE_Message objects and adds to _ready_queue
563
+	 *
564
+	 * @param array                     $addressees  Array of EE_Messages_Addressee objects indexed by message type
565
+	 *                                               context.
566
+	 * @param array                     $templates   formatted array of templates used for parsing data.
567
+	 * @param EE_Message_Template_Group $message_template_group
568
+	 * @return bool   true if message generation went a-ok.  false if some sort of exception occurred.  Note: The
569
+	 *                                               method will attempt to generate ALL EE_Message objects and add to
570
+	 *                                               the _ready_queue.  Successfully generated messages get added to the
571
+	 *                                               queue with EEM_Message::status_idle, unsuccessfully generated
572
+	 *                                               messages will get added to the queue as EEM_Message::status_failed.
573
+	 *                                               Very rarely should "false" be returned from this method.
574
+	 */
575
+	protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group)
576
+	{
577
+
578
+		//if templates are empty then get out because we can't generate anything.
579
+		if (! $templates) {
580
+			$this->_error_msg[] = esc_html__(
581
+				'Unable to assemble messages because there are no templates retrieved for generating the messages with',
582
+				'event_espresso'
583
+			);
584
+			return false;
585
+		}
586
+
587
+		//We use this as the counter for generated messages because don't forget we may be executing this inside of a
588
+		//generation_queue.  So _ready_queue may have generated EE_Message objects already.
589
+		$generated_count = 0;
590
+		foreach ($addressees as $context => $recipients) {
591
+			foreach ($recipients as $recipient) {
592
+				$message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group);
593
+				if ($message instanceof EE_Message) {
594
+					$this->_ready_queue->add(
595
+						$message,
596
+						array(),
597
+						$this->_generation_queue->get_message_repository()->is_preview(),
598
+						$this->_generation_queue->get_message_repository()->is_test_send()
599
+					);
600
+					$generated_count++;
601
+				}
602
+
603
+				//if the current MSG being generated is for a test send then we'll only use ONE message in the generation.
604
+				if ($this->_generation_queue->get_message_repository()->is_test_send()) {
605
+					break 2;
606
+				}
607
+			}
608
+		}
609
+
610
+		//if there are no generated messages then something else fatal went wrong.
611
+		return $generated_count > 0;
612
+	}
613
+
614
+
615
+	/**
616
+	 * @param string                    $context   The context for the generated message.
617
+	 * @param EE_Messages_Addressee     $recipient
618
+	 * @param array                     $templates formatted array of templates used for parsing data.
619
+	 * @param EE_Message_Template_Group $message_template_group
620
+	 * @return bool|EE_Message
621
+	 * @throws EE_Error
622
+	 */
623
+	protected function _setup_message_object(
624
+		$context,
625
+		EE_Messages_Addressee $recipient,
626
+		$templates,
627
+		EE_Message_Template_Group $message_template_group
628
+	) {
629
+		//stuff we already know
630
+		$transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0;
631
+		$transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction
632
+			? $this->_current_data_handler->txn->ID()
633
+			: $transaction_id;
634
+		$message_fields = array(
635
+			'GRP_ID'           => $message_template_group->ID(),
636
+			'TXN_ID'           => $transaction_id,
637
+			'MSG_messenger'    => $this->_current_messenger->name,
638
+			'MSG_message_type' => $this->_current_message_type->name,
639
+			'MSG_context'      => $context,
640
+		);
641
+
642
+		//recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab
643
+		// the info from the att_obj found in the EE_Messages_Addressee object.
644
+		if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) {
645
+			$message_fields['MSG_recipient_ID']   = $recipient->att_obj instanceof EE_Attendee
646
+				? $recipient->att_obj->ID()
647
+				: 0;
648
+			$message_fields['MSG_recipient_type'] = 'Attendee';
649
+		} else {
650
+			$message_fields['MSG_recipient_ID']   = $recipient->recipient_id;
651
+			$message_fields['MSG_recipient_type'] = $recipient->recipient_type;
652
+		}
653
+		$message = EE_Message_Factory::create($message_fields);
654
+
655
+		//grab valid shortcodes for shortcode parser
656
+		$mt_shortcodes = $this->_current_message_type->get_valid_shortcodes();
657
+		$m_shortcodes  = $this->_current_messenger->get_valid_shortcodes();
658
+
659
+		//if the 'to' field is empty (messages will ALWAYS have a "to" field, then we get out because that means this
660
+		//context is turned off) EXCEPT if we're previewing
661
+		if (empty($templates['to'][$context])
662
+			&& ! $this->_generation_queue->get_message_repository()->is_preview()
663
+			&& ! $this->_current_messenger->allow_empty_to_field()
664
+		) {
665
+			//we silently exit here and do NOT record a fail because the message is "turned off" by having no "to"
666
+			//field.
667
+			return false;
668
+		}
669
+		$error_msg = array();
670
+		foreach ($templates as $field => $field_context) {
671
+			$error_msg = array();
672
+			//let's setup the valid shortcodes for the incoming context.
673
+			$valid_shortcodes = $mt_shortcodes[$context];
674
+			//merge in valid shortcodes for the field.
675
+			$shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes;
676
+			if (isset($templates[$field][$context])) {
677
+				//prefix field.
678
+				$column_name = 'MSG_' . $field;
679
+				try {
680
+					$content = $this->_shortcode_parser->parse_message_template(
681
+						$templates[$field][$context],
682
+						$recipient,
683
+						$shortcodes,
684
+						$this->_current_message_type,
685
+						$this->_current_messenger,
686
+						$message
687
+					);
688
+					$message->set_field_or_extra_meta($column_name, $content);
689
+				} catch (EE_Error $e) {
690
+					$error_msg[] = sprintf(
691
+						esc_html__(
692
+							'There was a problem generating the content for the field %s: %s',
693
+							'event_espresso'
694
+						),
695
+						$field,
696
+						$e->getMessage()
697
+					);
698
+					$message->set_STS_ID(EEM_Message::status_failed);
699
+				}
700
+			}
701
+		}
702
+
703
+		if ($message->STS_ID() === EEM_Message::status_failed) {
704
+			$error_msg = esc_html__('There were problems generating this message:', 'event_espresso')
705
+						 . "\n"
706
+						 . implode("\n", $error_msg);
707
+			$message->set_error_message($error_msg);
708
+		} else {
709
+			$message->set_STS_ID(EEM_Message::status_idle);
710
+		}
711
+		return $message;
712
+	}
713
+
714
+
715
+	/**
716
+	 * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate
717
+	 * error message if either is missing.
718
+	 *
719
+	 * @return bool         true means there were no errors, false means there were errors.
720
+	 */
721
+	protected function _verify()
722
+	{
723
+		//reset error message to an empty array.
724
+		$this->_error_msg = array();
725
+		$valid            = true;
726
+		$valid            = $valid ? $this->_validate_messenger_and_message_type() : $valid;
727
+		$valid            = $valid ? $this->_validate_and_setup_data() : $valid;
728
+
729
+		//set the verified flag so we know everything has been validated.
730
+		$this->_verified = $valid;
731
+
732
+		return $valid;
733
+	}
734
+
735
+
736
+	/**
737
+	 * This accepts an array and validates that it is an array indexed by context with each value being an array of
738
+	 * EE_Messages_Addressee objects.
739
+	 *
740
+	 * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[]
741
+	 * @return bool
742
+	 */
743
+	protected function _valid_addressees($addressees)
744
+	{
745
+		if (! $addressees || ! is_array($addressees)) {
746
+			return false;
747
+		}
748
+
749
+		foreach ($addressees as $addressee_array) {
750
+			foreach ($addressee_array as $addressee) {
751
+				if (! $addressee instanceof EE_Messages_Addressee) {
752
+					return false;
753
+				}
754
+			}
755
+		}
756
+		return true;
757
+	}
758
+
759
+
760
+	/**
761
+	 * This validates the messenger, message type, and presences of generation data for the current EE_Message in the
762
+	 * queue. This process sets error messages if something is wrong.
763
+	 *
764
+	 * @return bool   true is if there are no errors.  false is if there is.
765
+	 */
766
+	protected function _validate_messenger_and_message_type()
767
+	{
768
+
769
+		//first are there any existing error messages?  If so then return.
770
+		if ($this->_error_msg) {
771
+			return false;
772
+		}
773
+		/** @type EE_Message $message */
774
+		$message = $this->_generation_queue->get_message_repository()->current();
775
+		try {
776
+			$this->_current_messenger = $message->valid_messenger(true)
777
+				? $message->messenger_object()
778
+				: null;
779
+		} catch (Exception $e) {
780
+			$this->_error_msg[] = $e->getMessage();
781
+		}
782
+		try {
783
+			$this->_current_message_type = $message->valid_message_type(true)
784
+				? $message->message_type_object()
785
+				: null;
786
+		} catch (Exception $e) {
787
+			$this->_error_msg[] = $e->getMessage();
788
+		}
789
+
790
+		/**
791
+		 * Check if there is any generation data, but only if this is not for a preview.
792
+		 */
793
+		if (! $this->_generation_queue->get_message_repository()->get_generation_data()
794
+			&& (
795
+				! $this->_generation_queue->get_message_repository()->is_preview()
796
+				&& $this->_generation_queue->get_message_repository()->get_data_handler()
797
+				   !== 'EE_Messages_Preview_incoming_data'
798
+			)
799
+		) {
800
+			$this->_error_msg[] = esc_html__(
801
+				'There is no generation data for this message. Unable to generate.',
802
+				'event_espresso'
803
+			);
804
+		}
805
+
806
+		return empty($this->_error_msg);
807
+	}
808
+
809
+
810
+	/**
811
+	 * This method retrieves the expected data handler for the message type and validates the generation data for that
812
+	 * data handler.
813
+	 *
814
+	 * @return bool true means there are no errors.  false means there were errors (and handler did not get setup).
815
+	 */
816
+	protected function _validate_and_setup_data()
817
+	{
818
+
819
+		//First, are there any existing error messages?  If so, return because if there were errors elsewhere this can't
820
+		//be used anyways.
821
+		if ($this->_error_msg) {
822
+			return false;
823
+		}
824
+
825
+		$generation_data = $this->_generation_queue->get_message_repository()->get_generation_data();
826
+
827
+		/** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually */
828
+		$data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler()
829
+			? $this->_generation_queue->get_message_repository()->get_data_handler()
830
+			: 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data';
831
+
832
+		//If this EE_Message is for a preview, then let's switch out to the preview data handler.
833
+		if ($this->_generation_queue->get_message_repository()->is_preview()) {
834
+			$data_handler_class_name = 'EE_Messages_Preview_incoming_data';
835
+		}
836
+
837
+		//First get the class name for the data handler (and also verifies it exists.
838
+		if (! class_exists($data_handler_class_name)) {
839
+			$this->_error_msg[] = sprintf(
840
+				esc_html__(
841
+					'The included data handler class name does not match any valid, accessible, "%1$s" classes.  Looking for %2$s.',
842
+					'event_espresso'
843
+				),
844
+				'EE_Messages_incoming_data',
845
+				$data_handler_class_name
846
+			);
847
+			return false;
848
+		}
849
+
850
+		//convert generation_data for data_handler_instantiation.
851
+		$generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data);
852
+
853
+		//note, this may set error messages as well.
854
+		$this->_set_data_handler($generation_data, $data_handler_class_name);
855
+
856
+		return empty($this->_error_msg);
857
+	}
858
+
859
+
860
+	/**
861
+	 * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and
862
+	 * adds it to the _data repository.
863
+	 *
864
+	 * @param mixed  $generating_data           This is data expected by the instantiated data handler.
865
+	 * @param string $data_handler_class_name   This is the reference string indicating what data handler is being
866
+	 *                                          instantiated.
867
+	 * @return void .
868
+	 * @throws EE_Error
869
+	 * @throws ReflectionException
870
+	 */
871
+	protected function _set_data_handler($generating_data, $data_handler_class_name)
872
+	{
873
+		//valid classname for the data handler.  Now let's setup the key for the data handler repository to see if there
874
+		//is already a ready data handler in the repository.
875
+		$this->_current_data_handler = $this->_data_handler_collection->get_by_key(
876
+			$this->_data_handler_collection->get_key(
877
+				$data_handler_class_name,
878
+				$generating_data
879
+			)
880
+		);
881
+		if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) {
882
+			//no saved data_handler in the repo so let's set one up and add it to the repo.
883
+			try {
884
+				$this->_current_data_handler = new $data_handler_class_name($generating_data);
885
+				$this->_data_handler_collection->add($this->_current_data_handler, $generating_data);
886
+			} catch (EE_Error $e) {
887
+				$this->_error_msg[] = $e->get_error();
888
+			}
889
+		}
890
+	}
891
+
892
+
893
+	/**
894
+	 * The queued EE_Message for generation does not save the data used for generation as objects
895
+	 * because serialization of those objects could be problematic if the data is saved to the db.
896
+	 * So this method calls the static method on the associated data_handler for the given message_type
897
+	 * and that preps the data for later instantiation when generating.
898
+	 *
899
+	 * @param EE_Message_To_Generate $message_to_generate
900
+	 * @param bool                   $preview Indicate whether this is being used for a preview or not.
901
+	 * @return mixed Prepped data for persisting to the queue.  false is returned if unable to prep data.
902
+	 */
903
+	protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview)
904
+	{
905
+		/** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */
906
+		$data_handler = $message_to_generate->get_data_handler_class_name($preview);
907
+		if (! $message_to_generate->valid()) {
908
+			return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid.
909
+		}
910
+		return $data_handler::convert_data_for_persistent_storage($message_to_generate->data());
911
+	}
912
+
913
+
914
+	/**
915
+	 * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue.
916
+	 *
917
+	 * @param EE_Message_To_Generate $message_to_generate
918
+	 * @param bool                   $test_send Whether this is just a test send or not.  Typically used for previews.
919
+	 */
920
+	public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false)
921
+	{
922
+		//prep data
923
+		$data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview());
924
+
925
+		$message = $message_to_generate->get_EE_Message();
926
+
927
+		//is there a GRP_ID in the request?
928
+		if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) {
929
+			$message->set_GRP_ID($GRP_ID);
930
+		}
931
+
932
+		if ($data === false) {
933
+			$message->set_STS_ID(EEM_Message::status_failed);
934
+			$message->set_error_message(
935
+				esc_html__(
936
+					'Unable to prepare data for persistence to the database.',
937
+					'event_espresso'
938
+				)
939
+			);
940
+		} else {
941
+			//make sure that the data handler is cached on the message as well
942
+			$data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name();
943
+		}
944
+
945
+		$this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send);
946
+	}
947 947
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
     {
255 255
         //double check verification has run and that everything is ready to work with (saves us having to validate
256 256
         // everything again).
257
-        if (! $this->_verified) {
257
+        if ( ! $this->_verified) {
258 258
             return false; //get out because we don't have a valid setup to work with.
259 259
         }
260 260
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 
272 272
 
273 273
         //if no addressees then get out because there is nothing to generation (possible bad data).
274
-        if (! $this->_valid_addressees($addressees)) {
274
+        if ( ! $this->_valid_addressees($addressees)) {
275 275
             do_action(
276 276
                 'AHEE__EE_Messages_Generator___generate__invalid_addressees',
277 277
                 $this->_generation_queue->get_message_repository()->current(),
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
         $message_template_group = $this->_get_message_template_group();
294 294
 
295 295
         //in the unlikely event there is no EE_Message_Template_Group available, get out!
296
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
296
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
297 297
             $this->_error_msg[] = esc_html__(
298 298
                 'Unable to get the Message Templates for the Message being generated.  No message template group accessible.',
299 299
                 'event_espresso'
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
             //attempt to retrieve from repo first
396 396
             $message_template_group = $this->_template_collection->get_by_ID($GRP_ID);
397 397
             if ($message_template_group instanceof EE_Message_Template_Group) {
398
-                return $message_template_group;  //got it!
398
+                return $message_template_group; //got it!
399 399
             }
400 400
 
401 401
             //nope don't have it yet.  Get from DB then add to repo if its not here, then that means the current GRP_ID
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
         );
492 492
 
493 493
         //if we don't have a group lets hit the db.
494
-        if (! $global_message_template_group instanceof EE_Message_Template_Group) {
494
+        if ( ! $global_message_template_group instanceof EE_Message_Template_Group) {
495 495
             $global_message_template_group = EEM_Message_Template_Group::instance()->get_one(
496 496
                 array(
497 497
                     array(
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
         $context_templates = $message_template_group->context_templates();
549 549
         foreach ($context_templates as $context => $template_fields) {
550 550
             foreach ($template_fields as $template_field => $template_obj) {
551
-                if (! $template_obj instanceof EE_Message_Template) {
551
+                if ( ! $template_obj instanceof EE_Message_Template) {
552 552
                     continue;
553 553
                 }
554 554
                 $templates[$template_field][$context] = $template_obj->get('MTP_content');
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
     {
577 577
 
578 578
         //if templates are empty then get out because we can't generate anything.
579
-        if (! $templates) {
579
+        if ( ! $templates) {
580 580
             $this->_error_msg[] = esc_html__(
581 581
                 'Unable to assemble messages because there are no templates retrieved for generating the messages with',
582 582
                 'event_espresso'
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
             $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes;
676 676
             if (isset($templates[$field][$context])) {
677 677
                 //prefix field.
678
-                $column_name = 'MSG_' . $field;
678
+                $column_name = 'MSG_'.$field;
679 679
                 try {
680 680
                     $content = $this->_shortcode_parser->parse_message_template(
681 681
                         $templates[$field][$context],
@@ -742,13 +742,13 @@  discard block
 block discarded – undo
742 742
      */
743 743
     protected function _valid_addressees($addressees)
744 744
     {
745
-        if (! $addressees || ! is_array($addressees)) {
745
+        if ( ! $addressees || ! is_array($addressees)) {
746 746
             return false;
747 747
         }
748 748
 
749 749
         foreach ($addressees as $addressee_array) {
750 750
             foreach ($addressee_array as $addressee) {
751
-                if (! $addressee instanceof EE_Messages_Addressee) {
751
+                if ( ! $addressee instanceof EE_Messages_Addressee) {
752 752
                     return false;
753 753
                 }
754 754
             }
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
         /**
791 791
          * Check if there is any generation data, but only if this is not for a preview.
792 792
          */
793
-        if (! $this->_generation_queue->get_message_repository()->get_generation_data()
793
+        if ( ! $this->_generation_queue->get_message_repository()->get_generation_data()
794 794
             && (
795 795
                 ! $this->_generation_queue->get_message_repository()->is_preview()
796 796
                 && $this->_generation_queue->get_message_repository()->get_data_handler()
@@ -827,7 +827,7 @@  discard block
 block discarded – undo
827 827
         /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually */
828 828
         $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler()
829 829
             ? $this->_generation_queue->get_message_repository()->get_data_handler()
830
-            : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data';
830
+            : 'EE_Messages_'.$this->_current_message_type->get_data_handler($generation_data).'_incoming_data';
831 831
 
832 832
         //If this EE_Message is for a preview, then let's switch out to the preview data handler.
833 833
         if ($this->_generation_queue->get_message_repository()->is_preview()) {
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
         }
836 836
 
837 837
         //First get the class name for the data handler (and also verifies it exists.
838
-        if (! class_exists($data_handler_class_name)) {
838
+        if ( ! class_exists($data_handler_class_name)) {
839 839
             $this->_error_msg[] = sprintf(
840 840
                 esc_html__(
841 841
                     'The included data handler class name does not match any valid, accessible, "%1$s" classes.  Looking for %2$s.',
@@ -878,7 +878,7 @@  discard block
 block discarded – undo
878 878
                 $generating_data
879 879
             )
880 880
         );
881
-        if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) {
881
+        if ( ! $this->_current_data_handler instanceof EE_Messages_incoming_data) {
882 882
             //no saved data_handler in the repo so let's set one up and add it to the repo.
883 883
             try {
884 884
                 $this->_current_data_handler = new $data_handler_class_name($generating_data);
@@ -904,7 +904,7 @@  discard block
 block discarded – undo
904 904
     {
905 905
         /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */
906 906
         $data_handler = $message_to_generate->get_data_handler_class_name($preview);
907
-        if (! $message_to_generate->valid()) {
907
+        if ( ! $message_to_generate->valid()) {
908 908
             return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid.
909 909
         }
910 910
         return $data_handler::convert_data_for_persistent_storage($message_to_generate->data());
Please login to merge, or discard this patch.
acceptance_tests/tests/c-TestCustomMessageTemplateCept.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -18,14 +18,14 @@  discard block
 block discarded – undo
18 18
 $event_one_link = $event_two_link = $event_three_link = '';
19 19
 
20 20
 $I->wantTo(
21
-    'Test that when registrations for multiple events are completed, and those events share the same custom'
22
-    . 'template, that that custom template will be used.'
21
+	'Test that when registrations for multiple events are completed, and those events share the same custom'
22
+	. 'template, that that custom template will be used.'
23 23
 );
24 24
 
25 25
 //need the MER plugin active for this test (we'll deactivate it after).
26 26
 $I->ensurePluginActive(
27
-    'event-espresso-mer-multi-event-registration',
28
-    'activated'
27
+	'event-espresso-mer-multi-event-registration',
28
+	'activated'
29 29
 );
30 30
 
31 31
 $I->loginAsAdmin();
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
 
84 84
 
85 85
 $test_registration_details = array(
86
-    'fname' => 'CTGuy',
87
-    'lname' => 'Dude',
88
-    'email' => '[email protected]'
86
+	'fname' => 'CTGuy',
87
+	'lname' => 'Dude',
88
+	'email' => '[email protected]'
89 89
 );
90 90
 
91 91
 $I->amGoingTo('Register for Event One and Event Two and verify Custom Template A was used.');
@@ -111,24 +111,24 @@  discard block
 block discarded – undo
111 111
 $I->loginAsAdmin();
112 112
 $I->amOnMessagesActivityListTablePage();
113 113
 $I->viewMessageInMessagesListTableFor(
114
-    'Registration Approved',
115
-    MessagesAdmin::MESSAGE_STATUS_SENT,
116
-    'Email',
117
-    'Registrant'
114
+	'Registration Approved',
115
+	MessagesAdmin::MESSAGE_STATUS_SENT,
116
+	'Email',
117
+	'Registrant'
118 118
 );
119 119
 $I->seeTextInViewMessageModal($custom_template_a_label);
120 120
 //closes view window
121 121
 $I->click('#espresso-admin-page-overlay-dv');
122 122
 $I->deleteMessageInMessagesListTableFor(
123
-    'Registration Approved',
124
-    MessagesAdmin::MESSAGE_STATUS_SENT,
125
-    'Email',
126
-    'Registrant'
123
+	'Registration Approved',
124
+	MessagesAdmin::MESSAGE_STATUS_SENT,
125
+	'Email',
126
+	'Registrant'
127 127
 );
128 128
 
129 129
 //verify admin context
130 130
 $I->viewMessageInMessagesListTableFor(
131
-    'Registration Approved'
131
+	'Registration Approved'
132 132
 );
133 133
 $I->seeTextInViewMessageModal($custom_template_a_label);
134 134
 $I->click('#espresso-admin-page-overlay-dv');
@@ -157,10 +157,10 @@  discard block
 block discarded – undo
157 157
 $I->loginAsAdmin();
158 158
 $I->amOnMessagesActivityListTablePage();
159 159
 $I->viewMessageInMessagesListTableFor(
160
-    'Registration Approved',
161
-    MessagesAdmin::MESSAGE_STATUS_SENT,
162
-    'Email',
163
-    'Registrant'
160
+	'Registration Approved',
161
+	MessagesAdmin::MESSAGE_STATUS_SENT,
162
+	'Email',
163
+	'Registrant'
164 164
 );
165 165
 $I->waitForElementVisible(MessagesAdmin::MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR);
166 166
 $I->dontSeeTextInViewMessageModal($custom_template_a_label);
@@ -168,15 +168,15 @@  discard block
 block discarded – undo
168 168
 //closes view window
169 169
 $I->click('#espresso-admin-page-overlay-dv');
170 170
 $I->deleteMessageInMessagesListTableFor(
171
-    'Registration Approved',
172
-    MessagesAdmin::MESSAGE_STATUS_SENT,
173
-    'Email',
174
-    'Registrant'
171
+	'Registration Approved',
172
+	MessagesAdmin::MESSAGE_STATUS_SENT,
173
+	'Email',
174
+	'Registrant'
175 175
 );
176 176
 
177 177
 //verify admin context
178 178
 $I->viewMessageInMessagesListTableFor(
179
-    'Registration Approved'
179
+	'Registration Approved'
180 180
 );
181 181
 $I->waitForElementVisible(MessagesAdmin::MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR);
182 182
 $I->dontSee($custom_template_a_label);
@@ -188,6 +188,6 @@  discard block
 block discarded – undo
188 188
 
189 189
 //deactivate MER plugin so its not active for future tests
190 190
 $I->ensurePluginDeactivated(
191
-    'event-espresso-mer-multi-event-registration',
192
-    'Plugin deactivated'
191
+	'event-espresso-mer-multi-event-registration',
192
+	'Plugin deactivated'
193 193
 );
194 194
\ No newline at end of file
Please login to merge, or discard this patch.