Completed
Branch BUG-10626-dst-unit-test (8c5dd4)
by
unknown
138:48 queued 126:51
created
core/db_models/EEM_Payment.model.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@
 block discarded – undo
1
-<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3
+}
2 4
 require_once ( EE_MODELS . 'EEM_Base.model.php' );
3 5
 /**
4 6
  *
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
-require_once ( EE_MODELS . 'EEM_Base.model.php' );
2
+require_once (EE_MODELS.'EEM_Base.model.php');
3 3
 /**
4 4
  *
5 5
  * Payment Model
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  * @author				Michael Nelson, Brent Christensen
10 10
  *
11 11
  */
12
-class EEM_Payment extends EEM_Base implements EEMI_Payment{
12
+class EEM_Payment extends EEM_Base implements EEMI_Payment {
13 13
 
14 14
   	// private instance of the Payment object
15 15
 	protected static $_instance = NULL;
@@ -57,28 +57,28 @@  discard block
 block discarded – undo
57 57
 	 *		@param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
58 58
 	 *		@return EEM_Payment
59 59
 	 */
60
-	protected function __construct( $timezone ) {
60
+	protected function __construct($timezone) {
61 61
 
62
-		$this->singular_item = __('Payment','event_espresso');
63
-		$this->plural_item = __('Payments','event_espresso');
62
+		$this->singular_item = __('Payment', 'event_espresso');
63
+		$this->plural_item = __('Payments', 'event_espresso');
64 64
 
65 65
 		$this->_tables = array(
66
-			'Payment'=>new EE_Primary_Table('esp_payment','PAY_ID')
66
+			'Payment'=>new EE_Primary_Table('esp_payment', 'PAY_ID')
67 67
 		);
68 68
 		$this->_fields = array(
69 69
 			'Payment'=>array(
70
-				'PAY_ID'=>new EE_Primary_Key_Int_Field('PAY_ID', __('Payment ID','event_espresso')),
71
-				'TXN_ID'=>new EE_Foreign_Key_Int_Field('TXN_ID', __('Transaction ID','event_espresso'), false, 0, 'Transaction'),
72
-				'STS_ID'=>new EE_Foreign_Key_String_Field('STS_ID', __('Status ID','event_espresso'), false, EEM_Payment::status_id_failed, 'Status'),
73
-				'PAY_timestamp'=> new EE_Datetime_Field('PAY_timestamp', __('Timestamp of when payment was attempted','event_espresso'), false, EE_Datetime_Field::now, $timezone ),
74
-				'PAY_source'=>new EE_All_Caps_Text_Field('PAY_source', __('User-friendly description of payment','event_espresso'), false, 'CART'),
75
-				'PAY_amount'=>new EE_Money_Field('PAY_amount', __('Amount Payment should be for','event_espresso'), false, 0),
70
+				'PAY_ID'=>new EE_Primary_Key_Int_Field('PAY_ID', __('Payment ID', 'event_espresso')),
71
+				'TXN_ID'=>new EE_Foreign_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso'), false, 0, 'Transaction'),
72
+				'STS_ID'=>new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), false, EEM_Payment::status_id_failed, 'Status'),
73
+				'PAY_timestamp'=> new EE_Datetime_Field('PAY_timestamp', __('Timestamp of when payment was attempted', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
74
+				'PAY_source'=>new EE_All_Caps_Text_Field('PAY_source', __('User-friendly description of payment', 'event_espresso'), false, 'CART'),
75
+				'PAY_amount'=>new EE_Money_Field('PAY_amount', __('Amount Payment should be for', 'event_espresso'), false, 0),
76 76
 				'PMD_ID'=>new EE_Foreign_Key_Int_Field('PMD_ID', __("Payment Method ID", 'event_espresso'), false, NULL, 'Payment_Method'),
77
-				'PAY_gateway_response'=>new EE_Plain_Text_Field('PAY_gateway_response', __('Response from Gateway about the payment','event_espresso'), false, ''),
78
-				'PAY_txn_id_chq_nmbr'=>new EE_Plain_Text_Field('PAY_txn_id_chq_nmbr', __('Gateway Transaction ID or Cheque Number','event_espresso'), true, ''),
79
-				'PAY_po_number'=>new EE_Plain_Text_Field('PAY_po_number', __('Purchase or Sales Number','event_espresso'), true, ''),
80
-				'PAY_extra_accntng'=>new EE_Simple_HTML_Field('PAY_extra_accntng', __('Extra Account Info','event_espresso'), true, ''),
81
-				'PAY_details'=>new EE_Serialized_Text_Field('PAY_details', __('Full Gateway response about payment','event_espresso'), true, ''),
77
+				'PAY_gateway_response'=>new EE_Plain_Text_Field('PAY_gateway_response', __('Response from Gateway about the payment', 'event_espresso'), false, ''),
78
+				'PAY_txn_id_chq_nmbr'=>new EE_Plain_Text_Field('PAY_txn_id_chq_nmbr', __('Gateway Transaction ID or Cheque Number', 'event_espresso'), true, ''),
79
+				'PAY_po_number'=>new EE_Plain_Text_Field('PAY_po_number', __('Purchase or Sales Number', 'event_espresso'), true, ''),
80
+				'PAY_extra_accntng'=>new EE_Simple_HTML_Field('PAY_extra_accntng', __('Extra Account Info', 'event_espresso'), true, ''),
81
+				'PAY_details'=>new EE_Serialized_Text_Field('PAY_details', __('Full Gateway response about payment', 'event_espresso'), true, ''),
82 82
 				'PAY_redirect_url'=>new EE_Plain_Text_Field('PAY_redirect_url', __("Redirect URL", 'event_espresso'), true),
83 83
 				'PAY_redirect_args'=>new EE_Serialized_Text_Field('PAY_redirect_args', __("Key-Value POST vars to send along with redirect", 'event_espresso'), true)
84 84
 			)
@@ -88,11 +88,11 @@  discard block
 block discarded – undo
88 88
 			'Status'=> new EE_Belongs_To_Relation(),
89 89
 			'Payment_Method'=>new EE_Belongs_To_Relation(),
90 90
 			'Registration_Payment' => new EE_Has_Many_Relation(),
91
-			'Registration' => new EE_HABTM_Relation( 'Registration_Payment' ),
91
+			'Registration' => new EE_HABTM_Relation('Registration_Payment'),
92 92
 		);
93 93
 		$this->_model_chain_to_wp_user = 'Payment_Method';
94 94
 		$this->_caps_slug = 'transactions';
95
-		parent::__construct( $timezone );
95
+		parent::__construct($timezone);
96 96
 	}
97 97
 
98 98
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	 * @param string $PAY_txn_id_chq_nmbr
105 105
 	 * @return EE_Payment
106 106
 	 */
107
-	public function get_payment_by_txn_id_chq_nmbr( $PAY_txn_id_chq_nmbr ){
107
+	public function get_payment_by_txn_id_chq_nmbr($PAY_txn_id_chq_nmbr) {
108 108
 		return $this->get_one(array(array('PAY_txn_id_chq_nmbr'=>$PAY_txn_id_chq_nmbr)));
109 109
 	}
110 110
 
@@ -120,15 +120,15 @@  discard block
 block discarded – undo
120 120
 	 *		@param	string	$status_of_payment one of EEM_Payment::status_id_*, like 'PAP','PCN',etc. If none is provided, gets payments with any status
121 121
 	*		@return		EE_Payment[]
122 122
 	*/
123
-	public function get_payments_for_transaction( $TXN_ID = FALSE, $status_of_payment = null ) {
123
+	public function get_payments_for_transaction($TXN_ID = FALSE, $status_of_payment = null) {
124 124
 		// all payments for a TXN ordered chronologically
125
-		$query_params = array( array( 'TXN_ID' => $TXN_ID ), 'order_by' => array( 'PAY_timestamp' => 'ASC' ));
125
+		$query_params = array(array('TXN_ID' => $TXN_ID), 'order_by' => array('PAY_timestamp' => 'ASC'));
126 126
 		// if provided with a status, search specifically for that status. Otherwise get them all
127
-		if ( $status_of_payment ){
127
+		if ($status_of_payment) {
128 128
 			$query_params[0]['STS_ID'] = $status_of_payment;
129 129
 		}
130 130
 		// retrieve payments
131
-		return $this->get_all ( $query_params );
131
+		return $this->get_all($query_params);
132 132
 	}
133 133
 
134 134
 
@@ -138,8 +138,8 @@  discard block
 block discarded – undo
138 138
 	 * @param int $TXN_ID
139 139
 	 * @return EE_Payment[]
140 140
 	 */
141
-	public function get_approved_payments_for_transaction( $TXN_ID = 0 ) {
142
-		return $this->get_payments_for_transaction( $TXN_ID, EEM_Payment::status_id_approved );
141
+	public function get_approved_payments_for_transaction($TXN_ID = 0) {
142
+		return $this->get_payments_for_transaction($TXN_ID, EEM_Payment::status_id_approved);
143 143
 
144 144
 	}
145 145
 
@@ -160,36 +160,36 @@  discard block
 block discarded – undo
160 160
 	 *
161 161
 	 * @return EE_Payment[]
162 162
 	 */
163
-	public function get_payments_made_between_dates( $start_date = '', $end_date = '', $format = '', $timezone = '' ) {
164
-		$timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone;
163
+	public function get_payments_made_between_dates($start_date = '', $end_date = '', $format = '', $timezone = '') {
164
+		$timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
165 165
 		//if $start_date or $end date, verify $format is included.
166
-		if ( ( ! empty( $start_date ) || ! empty( $end_date ) ) && empty( $format ) ) {
167
-			throw new EE_Error( __('You included a start date and/or a end date for this method but did not include a format string.  The format string is needed for setting up the query', 'event_espresso' ) );
166
+		if (( ! empty($start_date) || ! empty($end_date)) && empty($format)) {
167
+			throw new EE_Error(__('You included a start date and/or a end date for this method but did not include a format string.  The format string is needed for setting up the query', 'event_espresso'));
168 168
 		}
169
-		$now = new DateTime( 'now' );
169
+		$now = new DateTime('now');
170 170
 		// setup timezone objects once
171
-		$modelDateTimeZone = new DateTimeZone( $this->_timezone );
172
-		$passedDateTimeZone = new DateTimeZone( $timezone );
171
+		$modelDateTimeZone = new DateTimeZone($this->_timezone);
172
+		$passedDateTimeZone = new DateTimeZone($timezone);
173 173
 		// setup start date
174
-		$start_date = ! empty( $start_date ) ? date_create_from_format( $format, $start_date, $passedDateTimeZone ) : $now;
175
-		$start_date->setTimeZone( $modelDateTimeZone );
176
-		$start_date = $start_date->format( 'Y-m-d' ) . ' 00:00:00';
177
-		$start_date = strtotime( $start_date );
174
+		$start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now;
175
+		$start_date->setTimeZone($modelDateTimeZone);
176
+		$start_date = $start_date->format('Y-m-d').' 00:00:00';
177
+		$start_date = strtotime($start_date);
178 178
 		// setup end date
179
-		$end_date = ! empty( $end_date ) ? date_create_from_format( $format, $end_date, $passedDateTimeZone ) : $now;
180
-		$end_date->setTimeZone( $modelDateTimeZone );
181
-		$end_date = $end_date->format('Y-m-d') . ' 23:59:59';
182
-		$end_date = strtotime( $end_date );
179
+		$end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now;
180
+		$end_date->setTimeZone($modelDateTimeZone);
181
+		$end_date = $end_date->format('Y-m-d').' 23:59:59';
182
+		$end_date = strtotime($end_date);
183 183
 
184 184
 		// make sure our start date is the lowest value and vice versa
185
-		$start = min( $start_date, $end_date );
186
-		$end = max( $start_date, $end_date );
185
+		$start = min($start_date, $end_date);
186
+		$end = max($start_date, $end_date);
187 187
 
188 188
 		//yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model.
189
-		$start_date = $this->convert_datetime_for_query( 'PAY_timestamp', date( 'Y-m-d', $start ) . ' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone() );
190
-		$end_date = $this->convert_datetime_for_query( 'PAY_timestamp', date( 'Y-m-d', $end) . ' 23:59:59' , 'Y-m-d H:i:s', $this->get_timezone() );
189
+		$start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start).' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone());
190
+		$end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end).' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone());
191 191
 
192
-		return $this->get_all(array(array('PAY_timestamp'=>array('>=',$start_date),'PAY_timestamp*'=>array('<=',$end_date))));
192
+		return $this->get_all(array(array('PAY_timestamp'=>array('>=', $start_date), 'PAY_timestamp*'=>array('<=', $end_date))));
193 193
 	}
194 194
 
195 195
 	/**
@@ -199,35 +199,35 @@  discard block
 block discarded – undo
199 199
 	 * returns a string for the approved status
200 200
 	 * @return 	string
201 201
 	 */
202
-	function approved_status(){
202
+	function approved_status() {
203 203
 		return self::status_id_approved;
204 204
 	}
205 205
 	/**
206 206
 	 * returns a string for the pending status
207 207
 	 * @return 	string
208 208
 	 */
209
-	function pending_status(){
209
+	function pending_status() {
210 210
 		return self::status_id_pending;
211 211
 	}
212 212
 	/**
213 213
 	 * returns a string for the cancelled status
214 214
 	 * @return 	string
215 215
 	 */
216
-	function cancelled_status(){
216
+	function cancelled_status() {
217 217
 		return self::status_id_cancelled;
218 218
 	}
219 219
 	/**
220 220
 	 * returns a string for the failed status
221 221
 	 * @return 	string
222 222
 	 */
223
-	function failed_status(){
223
+	function failed_status() {
224 224
 		return self::status_id_failed;
225 225
 	}
226 226
 	/**
227 227
 	 * returns a string for the declined status
228 228
 	 * @return 	string
229 229
 	 */
230
-	function declined_status(){
230
+	function declined_status() {
231 231
 		return self::status_id_declined;
232 232
 	}
233 233
 
Please login to merge, or discard this patch.
core/request_stack/EE_Request_Stack_Builder.core.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -44,12 +44,12 @@  discard block
 block discarded – undo
44 44
 	 * @return EE_Request_Stack_Builder
45 45
 	 */
46 46
 	public function unshift( /*$class_name, $args*/ ) {
47
-		if ( func_num_args() === 0 ) {
48
-			throw new InvalidArgumentException( "Missing argument(s) when calling unshift" );
47
+		if (func_num_args() === 0) {
48
+			throw new InvalidArgumentException("Missing argument(s) when calling unshift");
49 49
 		}
50 50
 		$middleware = func_get_args();
51 51
 		//$this->middleware_stack->unshift( $middleware );
52
-		array_unshift( $this->_middleware_stack, $middleware );
52
+		array_unshift($this->_middleware_stack, $middleware);
53 53
 		return $this;
54 54
 	}
55 55
 
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 	 * @return EE_Request_Stack_Builder
67 67
 	 */
68 68
 	public function push( /*$class_name, $args...*/ ) {
69
-		if ( func_num_args() === 0 ) {
70
-			throw new InvalidArgumentException( "Missing argument(s) when calling push" );
69
+		if (func_num_args() === 0) {
70
+			throw new InvalidArgumentException("Missing argument(s) when calling push");
71 71
 		}
72 72
 		$middleware = func_get_args();
73 73
 		//$this->middleware_stack->push( $middleware );
74
-		array_push( $this->_middleware_stack, $middleware );
74
+		array_push($this->_middleware_stack, $middleware);
75 75
 		return $this;
76 76
 	}
77 77
 
@@ -84,20 +84,20 @@  discard block
 block discarded – undo
84 84
 	 * @param EEI_Request_Decorator $application
85 85
 	 * @return EE_Request_Stack
86 86
 	 */
87
-	public function resolve( EEI_Request_Decorator $application ) {
88
-		$middlewares = array( $application );
89
-		foreach ( $this->_middleware_stack as $middleware_args ) {
90
-			$class_name = array_shift( $middleware_args );
91
-			if ( is_callable( $class_name ) ) {
92
-				$application = $class_name( $application );
87
+	public function resolve(EEI_Request_Decorator $application) {
88
+		$middlewares = array($application);
89
+		foreach ($this->_middleware_stack as $middleware_args) {
90
+			$class_name = array_shift($middleware_args);
91
+			if (is_callable($class_name)) {
92
+				$application = $class_name($application);
93 93
 			} else {
94
-				array_unshift( $middleware_args, $application );
95
-				$reflection = new ReflectionClass( $class_name );
96
-				$application = $reflection->newInstanceArgs( $middleware_args );
94
+				array_unshift($middleware_args, $application);
95
+				$reflection = new ReflectionClass($class_name);
96
+				$application = $reflection->newInstanceArgs($middleware_args);
97 97
 			}
98
-			array_unshift( $middlewares, $application );
98
+			array_unshift($middlewares, $application);
99 99
 		}
100
-		return new EE_Request_Stack( $application, $middlewares );
100
+		return new EE_Request_Stack($application, $middlewares);
101 101
 	}
102 102
 
103 103
 
Please login to merge, or discard this patch.
core/EE_Bootstrap.core.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -42,13 +42,13 @@  discard block
 block discarded – undo
42 42
 
43 43
 	public function __construct() {
44 44
 		// construct request stack and run middleware apps as soon as all WP plugins are loaded
45
-		add_action( 'plugins_loaded', array( $this, 'run_request_stack' ), 0 );
45
+		add_action('plugins_loaded', array($this, 'run_request_stack'), 0);
46 46
 		// set framework for the rest of EE to hook into when loading
47
-		add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'load_espresso_addons' ), 1 );
48
-		add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'detect_activations_or_upgrades' ), 3 );
49
-		add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'load_core_configuration' ), 5 );
50
-		add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'register_shortcodes_modules_and_widgets' ), 7 );
51
-		add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'brew_espresso' ), 9 );
47
+		add_action('plugins_loaded', array('EE_Bootstrap', 'load_espresso_addons'), 1);
48
+		add_action('plugins_loaded', array('EE_Bootstrap', 'detect_activations_or_upgrades'), 3);
49
+		add_action('plugins_loaded', array('EE_Bootstrap', 'load_core_configuration'), 5);
50
+		add_action('plugins_loaded', array('EE_Bootstrap', 'register_shortcodes_modules_and_widgets'), 7);
51
+		add_action('plugins_loaded', array('EE_Bootstrap', 'brew_espresso'), 9);
52 52
 	}
53 53
 
54 54
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 			new EE_Load_Espresso_Core()
66 66
 		);
67 67
 		$this->_request_stack->handle_request(
68
-			new EE_Request( $_GET, $_POST, $_COOKIE ),
68
+			new EE_Request($_GET, $_POST, $_COOKIE),
69 69
 			new EE_Response()
70 70
 		);
71 71
 		$this->_request_stack->handle_response();
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	 */
79 79
 	protected function load_autoloader() {
80 80
 		// load interfaces
81
-		espresso_load_required( 'EEH_Autoloader', EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php' );
81
+		espresso_load_required('EEH_Autoloader', EE_CORE.'helpers'.DS.'EEH_Autoloader.helper.php');
82 82
 		EEH_Autoloader::instance();
83 83
 	}
84 84
 
@@ -89,13 +89,13 @@  discard block
 block discarded – undo
89 89
 	 */
90 90
 	protected function set_autoloaders_for_required_files() {
91 91
 		// load interfaces
92
-		espresso_load_required( 'EEI_Interfaces', EE_CORE . 'interfaces' . DS . 'EEI_Interfaces.php' );
92
+		espresso_load_required('EEI_Interfaces', EE_CORE.'interfaces'.DS.'EEI_Interfaces.php');
93 93
 		// load helpers
94
-		EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_HELPERS );
94
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
95 95
 		// load request stack
96
-		EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_CORE . 'request_stack' . DS );
96
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'request_stack'.DS);
97 97
 		// load middleware
98
-		EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_CORE . 'middleware' . DS );
98
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'middleware'.DS);
99 99
 	}
100 100
 
101 101
 
@@ -118,9 +118,9 @@  discard block
 block discarded – undo
118 118
 			)
119 119
 		);
120 120
 		// load middleware onto stack : FILO (First In Last Out)
121
-		foreach ( (array)$stack_apps as $stack_app ) {
121
+		foreach ((array) $stack_apps as $stack_app) {
122 122
 			//$request_stack_builder->push( $stack_app );
123
-			$request_stack_builder->unshift( $stack_app );
123
+			$request_stack_builder->unshift($stack_app);
124 124
 		}
125 125
 		return apply_filters(
126 126
 			'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder',
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	 * no other logic should be performed at this point
138 138
 	 */
139 139
 	public static function load_espresso_addons() {
140
-		do_action( 'AHEE__EE_Bootstrap__load_espresso_addons' );
140
+		do_action('AHEE__EE_Bootstrap__load_espresso_addons');
141 141
 	}
142 142
 
143 143
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 * we can determine if anything needs activating or upgrading
150 150
 	 */
151 151
 	public static function detect_activations_or_upgrades() {
152
-		do_action( 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' );
152
+		do_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades');
153 153
 	}
154 154
 
155 155
 
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 	 * we can load and set all of the system configurations
162 162
 	 */
163 163
 	public static function load_core_configuration() {
164
-		do_action( 'AHEE__EE_Bootstrap__load_core_configuration' );
164
+		do_action('AHEE__EE_Bootstrap__load_core_configuration');
165 165
 	}
166 166
 
167 167
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 	 * so that they are ready to be used throughout the system
174 174
 	 */
175 175
 	public static function register_shortcodes_modules_and_widgets() {
176
-		do_action( 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' );
176
+		do_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets');
177 177
 	}
178 178
 
179 179
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 	 * so let the fun begin...
186 186
 	 */
187 187
 	public static function brew_espresso() {
188
-		do_action( 'AHEE__EE_Bootstrap__brew_espresso' );
188
+		do_action('AHEE__EE_Bootstrap__brew_espresso');
189 189
 	}
190 190
 
191 191
 
Please login to merge, or discard this patch.
core/services/container/CoffeeMaker.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 
70 70
 
71 71
     /**
72
-     * @param $type
72
+     * @param string $type
73 73
      */
74 74
     public static function validateType($type)
75 75
     {
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
      * Examines the constructor to determine which method should be used for instantiation
127 127
      *
128 128
      * @param \ReflectionClass $reflector
129
-     * @return mixed
129
+     * @return string
130 130
      */
131 131
     protected function resolveInstantiationMethod(\ReflectionClass $reflector)
132 132
     {
Please login to merge, or discard this patch.
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 use EventEspresso\core\services\container\exceptions\InstantiationException;
7 7
 
8 8
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
9
-    exit('No direct script access allowed');
9
+	exit('No direct script access allowed');
10 10
 }
11 11
 
12 12
 
@@ -23,158 +23,158 @@  discard block
 block discarded – undo
23 23
 abstract class CoffeeMaker implements CoffeeMakerInterface
24 24
 {
25 25
 
26
-    /**
27
-     * Indicates that CoffeeMaker should construct a NEW entity instance from the provided arguments (if given)
28
-     */
29
-    const BREW_NEW = 'new';
30
-
31
-    /**
32
-     * Indicates that CoffeeMaker should always return a SHARED instance
33
-     */
34
-    const BREW_SHARED = 'shared';
35
-
36
-    /**
37
-     * Indicates that CoffeeMaker should only load the file/class/interface but NOT instantiate
38
-     */
39
-    const BREW_LOAD_ONLY = 'load_only';
40
-
41
-
42
-    /**
43
-     * @var CoffeePotInterface $coffee_pot
44
-     */
45
-    private $coffee_pot;
46
-
47
-    /**
48
-     * @var DependencyInjector $injector
49
-     */
50
-    private $injector;
51
-
52
-
53
-
54
-    /**
55
-     * @return array
56
-     */
57
-    public static function getTypes()
58
-    {
59
-        return (array)apply_filters(
60
-            'FHEE__EventEspresso\core\services\container\CoffeeMaker__getTypes',
61
-            array(
62
-                CoffeeMaker::BREW_NEW,
63
-                CoffeeMaker::BREW_SHARED,
64
-                CoffeeMaker::BREW_LOAD_ONLY,
65
-            )
66
-        );
67
-    }
68
-
69
-
70
-
71
-    /**
72
-     * @param $type
73
-     */
74
-    public static function validateType($type)
75
-    {
76
-        $types = CoffeeMaker::getTypes();
77
-        if ( ! in_array($type, $types)) {
78
-            throw new InvalidIdentifierException(
79
-                is_object($type) ? get_class($type) : gettype($type),
80
-                __(
81
-                    'recipe type (one of the class constants on \EventEspresso\core\services\container\CoffeeMaker)',
82
-                    'event_espresso'
83
-                )
84
-            );
85
-        }
86
-        return $type;
87
-    }
88
-
89
-
90
-
91
-    /**
92
-     * CoffeeMaker constructor.
93
-     *
94
-     * @param CoffeePotInterface $coffee_pot
95
-     * @param InjectorInterface  $injector
96
-     */
97
-    public function __construct(CoffeePotInterface $coffee_pot, InjectorInterface $injector)
98
-    {
99
-        $this->coffee_pot = $coffee_pot;
100
-        $this->injector = $injector;
101
-    }
102
-
103
-
104
-
105
-    /**
106
-     * @return \EventEspresso\core\services\container\CoffeePotInterface
107
-     */
108
-    protected function coffeePot()
109
-    {
110
-        return $this->coffee_pot;
111
-    }
112
-
113
-
114
-
115
-    /**
116
-     * @return \EventEspresso\core\services\container\DependencyInjector
117
-     */
118
-    protected function injector()
119
-    {
120
-        return $this->injector;
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * Examines the constructor to determine which method should be used for instantiation
127
-     *
128
-     * @param \ReflectionClass $reflector
129
-     * @return mixed
130
-     */
131
-    protected function resolveInstantiationMethod(\ReflectionClass $reflector)
132
-    {
133
-        if ($reflector->getConstructor() === null) {
134
-            return 'NewInstance';
135
-        } else if ($reflector->isInstantiable()) {
136
-            return 'NewInstanceArgs';
137
-        } else if (method_exists($reflector->getName(), 'instance')) {
138
-            return 'instance';
139
-        } else if (method_exists($reflector->getName(), 'new_instance')) {
140
-            return 'new_instance';
141
-        } else if (method_exists($reflector->getName(), 'new_instance_from_db')) {
142
-            return 'new_instance_from_db';
143
-        } else {
144
-            throw new InstantiationException($reflector->getName());
145
-        }
146
-    }
147
-
148
-
149
-
150
-    /**
151
-     * Ensures files for classes that are not PSR-4 compatible are loaded
152
-     * and then verifies that classes exist where applicable
153
-     *
154
-     * @param RecipeInterface $recipe
155
-     * @throws InvalidClassException
156
-     */
157
-    protected function resolveClassAndFilepath(RecipeInterface $recipe)
158
-    {
159
-        $paths = $recipe->paths();
160
-        if ( ! empty($paths)) {
161
-            foreach ($paths as $path) {
162
-                if (strpos($path, '*') === false && is_readable($path)) {
163
-                    require_once($path);
164
-                }
165
-            }
166
-        }
167
-        // re: using "false" for class_exists() second param:
168
-        // if a class name is not already known to PHP, then class_exists() will run through
169
-        // all of the registered spl_autoload functions until it either finds the class,
170
-        // or gets to the end of the registered spl_autoload functions.
171
-        // When the second parameter is true, it will also attempt to load the class file,
172
-        // but it will also trigger an error if the class can not be loaded.
173
-        // We don't want that extra error in the mix, so we have set the second param to "false"
174
-        if ($recipe->type() !== CoffeeMaker::BREW_LOAD_ONLY && ! class_exists($recipe->fqcn(), false)) {
175
-            throw new InvalidClassException($recipe->identifier());
176
-        }
177
-    }
26
+	/**
27
+	 * Indicates that CoffeeMaker should construct a NEW entity instance from the provided arguments (if given)
28
+	 */
29
+	const BREW_NEW = 'new';
30
+
31
+	/**
32
+	 * Indicates that CoffeeMaker should always return a SHARED instance
33
+	 */
34
+	const BREW_SHARED = 'shared';
35
+
36
+	/**
37
+	 * Indicates that CoffeeMaker should only load the file/class/interface but NOT instantiate
38
+	 */
39
+	const BREW_LOAD_ONLY = 'load_only';
40
+
41
+
42
+	/**
43
+	 * @var CoffeePotInterface $coffee_pot
44
+	 */
45
+	private $coffee_pot;
46
+
47
+	/**
48
+	 * @var DependencyInjector $injector
49
+	 */
50
+	private $injector;
51
+
52
+
53
+
54
+	/**
55
+	 * @return array
56
+	 */
57
+	public static function getTypes()
58
+	{
59
+		return (array)apply_filters(
60
+			'FHEE__EventEspresso\core\services\container\CoffeeMaker__getTypes',
61
+			array(
62
+				CoffeeMaker::BREW_NEW,
63
+				CoffeeMaker::BREW_SHARED,
64
+				CoffeeMaker::BREW_LOAD_ONLY,
65
+			)
66
+		);
67
+	}
68
+
69
+
70
+
71
+	/**
72
+	 * @param $type
73
+	 */
74
+	public static function validateType($type)
75
+	{
76
+		$types = CoffeeMaker::getTypes();
77
+		if ( ! in_array($type, $types)) {
78
+			throw new InvalidIdentifierException(
79
+				is_object($type) ? get_class($type) : gettype($type),
80
+				__(
81
+					'recipe type (one of the class constants on \EventEspresso\core\services\container\CoffeeMaker)',
82
+					'event_espresso'
83
+				)
84
+			);
85
+		}
86
+		return $type;
87
+	}
88
+
89
+
90
+
91
+	/**
92
+	 * CoffeeMaker constructor.
93
+	 *
94
+	 * @param CoffeePotInterface $coffee_pot
95
+	 * @param InjectorInterface  $injector
96
+	 */
97
+	public function __construct(CoffeePotInterface $coffee_pot, InjectorInterface $injector)
98
+	{
99
+		$this->coffee_pot = $coffee_pot;
100
+		$this->injector = $injector;
101
+	}
102
+
103
+
104
+
105
+	/**
106
+	 * @return \EventEspresso\core\services\container\CoffeePotInterface
107
+	 */
108
+	protected function coffeePot()
109
+	{
110
+		return $this->coffee_pot;
111
+	}
112
+
113
+
114
+
115
+	/**
116
+	 * @return \EventEspresso\core\services\container\DependencyInjector
117
+	 */
118
+	protected function injector()
119
+	{
120
+		return $this->injector;
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * Examines the constructor to determine which method should be used for instantiation
127
+	 *
128
+	 * @param \ReflectionClass $reflector
129
+	 * @return mixed
130
+	 */
131
+	protected function resolveInstantiationMethod(\ReflectionClass $reflector)
132
+	{
133
+		if ($reflector->getConstructor() === null) {
134
+			return 'NewInstance';
135
+		} else if ($reflector->isInstantiable()) {
136
+			return 'NewInstanceArgs';
137
+		} else if (method_exists($reflector->getName(), 'instance')) {
138
+			return 'instance';
139
+		} else if (method_exists($reflector->getName(), 'new_instance')) {
140
+			return 'new_instance';
141
+		} else if (method_exists($reflector->getName(), 'new_instance_from_db')) {
142
+			return 'new_instance_from_db';
143
+		} else {
144
+			throw new InstantiationException($reflector->getName());
145
+		}
146
+	}
147
+
148
+
149
+
150
+	/**
151
+	 * Ensures files for classes that are not PSR-4 compatible are loaded
152
+	 * and then verifies that classes exist where applicable
153
+	 *
154
+	 * @param RecipeInterface $recipe
155
+	 * @throws InvalidClassException
156
+	 */
157
+	protected function resolveClassAndFilepath(RecipeInterface $recipe)
158
+	{
159
+		$paths = $recipe->paths();
160
+		if ( ! empty($paths)) {
161
+			foreach ($paths as $path) {
162
+				if (strpos($path, '*') === false && is_readable($path)) {
163
+					require_once($path);
164
+				}
165
+			}
166
+		}
167
+		// re: using "false" for class_exists() second param:
168
+		// if a class name is not already known to PHP, then class_exists() will run through
169
+		// all of the registered spl_autoload functions until it either finds the class,
170
+		// or gets to the end of the registered spl_autoload functions.
171
+		// When the second parameter is true, it will also attempt to load the class file,
172
+		// but it will also trigger an error if the class can not be loaded.
173
+		// We don't want that extra error in the mix, so we have set the second param to "false"
174
+		if ($recipe->type() !== CoffeeMaker::BREW_LOAD_ONLY && ! class_exists($recipe->fqcn(), false)) {
175
+			throw new InvalidClassException($recipe->identifier());
176
+		}
177
+	}
178 178
 
179 179
 
180 180
 
Please login to merge, or discard this patch.
core/services/container/LoadOnlyCoffeeMaker.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 namespace EventEspresso\core\services\container;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -24,26 +24,26 @@  discard block
 block discarded – undo
24 24
 class LoadOnlyCoffeeMaker extends CoffeeMaker
25 25
 {
26 26
 
27
-    /**
28
-     * @return string
29
-     */
30
-    public function type()
31
-    {
32
-        return CoffeeMaker::BREW_LOAD_ONLY;
33
-    }
34
-
35
-
36
-
37
-    /**
38
-     * @param RecipeInterface $recipe
39
-     * @param array           $arguments
40
-     * @return mixed
41
-     */
42
-    public function brew(RecipeInterface $recipe, $arguments = array())
43
-    {
44
-        $this->resolveClassAndFilepath($recipe);
45
-        return null;
46
-    }
27
+	/**
28
+	 * @return string
29
+	 */
30
+	public function type()
31
+	{
32
+		return CoffeeMaker::BREW_LOAD_ONLY;
33
+	}
34
+
35
+
36
+
37
+	/**
38
+	 * @param RecipeInterface $recipe
39
+	 * @param array           $arguments
40
+	 * @return mixed
41
+	 */
42
+	public function brew(RecipeInterface $recipe, $arguments = array())
43
+	{
44
+		$this->resolveClassAndFilepath($recipe);
45
+		return null;
46
+	}
47 47
 
48 48
 
49 49
 
Please login to merge, or discard this patch.
core/services/container/CoffeeShop.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
      * Adds instructions on how to brew objects
237 237
      *
238 238
      * @param RecipeInterface $recipe
239
-     * @return mixed
239
+     * @return boolean
240 240
      */
241 241
     public function addRecipe(RecipeInterface $recipe)
242 242
     {
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
     /**
313 313
      * Adds a service to one of the internal collections
314 314
      *
315
-     * @param        $identifier
315
+     * @param        string $identifier
316 316
      * @param array  $arguments
317 317
      * @param string $type
318 318
      * @return mixed
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
         // array for storing class aliases
80 80
         $this->filters = array();
81 81
         // create collection for storing shared services
82
-        $this->carafe = new LooseCollection( '' );
82
+        $this->carafe = new LooseCollection('');
83 83
         // create collection for storing recipes that tell how to build services and entities
84 84
         $this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface');
85 85
         // create collection for storing closures for constructing new entities
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
             return;
303 303
         }
304 304
         $identifier = $this->processIdentifier($identifier);
305
-        foreach ((array)$aliases as $alias) {
305
+        foreach ((array) $aliases as $alias) {
306 306
             $this->filters[$this->processIdentifier($alias)] = $identifier;
307 307
         }
308 308
     }
Please login to merge, or discard this patch.
Indentation   +497 added lines, -497 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 use OutOfBoundsException;
14 14
 
15 15
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
16
-    exit('No direct script access allowed');
16
+	exit('No direct script access allowed');
17 17
 }
18 18
 
19 19
 
@@ -32,502 +32,502 @@  discard block
 block discarded – undo
32 32
 {
33 33
 
34 34
 
35
-    /**
36
-     * This was the best coffee related name I could think of to represent class name "aliases"
37
-     * So classes can be found via an alias identifier,
38
-     * that is revealed when it is run through... the filters... eh? get it?
39
-     *
40
-     * @var array $filters
41
-     */
42
-    private $filters = array();
43
-
44
-    /**
45
-     * These are the classes that will actually build the objects (to order of course)
46
-     *
47
-     * @var array $coffee_makers
48
-     */
49
-    private $coffee_makers = array();
50
-
51
-    /**
52
-     * where the instantiated "singleton" objects are stored
53
-     *
54
-     * @var CollectionInterface $carafe
55
-     */
56
-    private $carafe;
57
-
58
-    /**
59
-     * collection of Recipes that instruct us how to brew objects
60
-     *
61
-     * @var CollectionInterface $recipes
62
-     */
63
-    private $recipes;
64
-
65
-    /**
66
-     * collection of closures for brewing objects
67
-     *
68
-     * @var CollectionInterface $reservoir
69
-     */
70
-    private $reservoir;
71
-
72
-
73
-
74
-    /**
75
-     * CoffeeShop constructor
76
-     */
77
-    public function __construct()
78
-    {
79
-        // array for storing class aliases
80
-        $this->filters = array();
81
-        // create collection for storing shared services
82
-        $this->carafe = new LooseCollection( '' );
83
-        // create collection for storing recipes that tell how to build services and entities
84
-        $this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface');
85
-        // create collection for storing closures for constructing new entities
86
-        $this->reservoir = new Collection('Closure');
87
-        // create collection for storing the generators that build our services and entity closures
88
-        $this->coffee_makers = new Collection('EventEspresso\core\services\container\CoffeeMakerInterface');
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * Returns true if the container can return an entry for the given identifier.
95
-     * Returns false otherwise.
96
-     * `has($identifier)` returning true does not mean that `get($identifier)` will not throw an exception.
97
-     * It does however mean that `get($identifier)` will not throw a `ServiceNotFoundException`.
98
-     *
99
-     * @param string $identifier  Identifier of the entry to look for.
100
-     *                            Typically a Fully Qualified Class Name
101
-     * @return boolean
102
-     */
103
-    public function has($identifier)
104
-    {
105
-        $identifier = $this->filterIdentifier($identifier);
106
-        return $this->carafe->has($identifier);
107
-    }
108
-
109
-
110
-
111
-    /**
112
-     * finds a previously brewed (SHARED) service and returns it
113
-     *
114
-     * @param  string $identifier Identifier for the entity class to be constructed.
115
-     *                            Typically a Fully Qualified Class Name
116
-     * @return mixed
117
-     * @throws ServiceNotFoundException No service was found for this identifier.
118
-     */
119
-    public function get($identifier)
120
-    {
121
-        $identifier = $this->filterIdentifier($identifier);
122
-        if ($this->carafe->has($identifier)) {
123
-            return $this->carafe->get($identifier);
124
-        }
125
-        throw new ServiceNotFoundException($identifier);
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * returns an instance of the requested entity type using the supplied arguments.
132
-     * If a shared service is requested and an instance is already in the carafe, then it will be returned.
133
-     * If it is not already in the carafe, then the service will be constructed, added to the carafe, and returned
134
-     * If the request is for a new entity and a closure exists in the reservoir for creating it,
135
-     * then a new entity will be instantiated from the closure and returned.
136
-     * If a closure does not exist, then one will be built and added to the reservoir
137
-     * before instantiating the requested entity.
138
-     *
139
-     * @param  string $identifier Identifier for the entity class to be constructed.
140
-     *                            Typically a Fully Qualified Class Name
141
-     * @param array   $arguments  an array of arguments to be passed to the entity constructor
142
-     * @param string  $type
143
-     * @return mixed
144
-     * @throws ServiceNotFoundException No service was found for this identifier.
145
-     */
146
-    public function brew($identifier, $arguments = array(), $type = '')
147
-    {
148
-        // resolve any class aliases that may exist
149
-        $identifier = $this->filterIdentifier($identifier);
150
-        try {
151
-            // is a shared service being requested?
152
-            if (empty($type) || $type === CoffeeMaker::BREW_SHARED) {
153
-                // if a shared service was requested and an instance is in the carafe, then return it
154
-                return $this->get($identifier);
155
-            }
156
-        } catch (ServiceNotFoundException $e) {
157
-            // if not then we'll just catch the ServiceNotFoundException but not do anything just yet,
158
-            // and instead, attempt to build whatever was requested
159
-        }
160
-        $brewed = false;
161
-        // if the reservoir doesn't have a closure already for the requested identifier,
162
-        // then neither a shared service nor a closure for making entities has been built yet
163
-        if ( ! $this->reservoir->has($identifier)) {
164
-            // so let's brew something up and add it to the proper collection
165
-            $brewed = $this->makeCoffee($identifier, $arguments, $type);
166
-        }
167
-        // was the brewed item a callable factory function ?
168
-        if (is_callable($brewed)) {
169
-            // then instantiate a new entity from the cached closure
170
-            $entity = $brewed($arguments);
171
-        } else if ($brewed) {
172
-            // requested object was a shared entity, so attempt to get it from the carafe again
173
-            // because if it wasn't there before, then it should have just been brewed and added,
174
-            // but if it still isn't there, then this time
175
-            // the thrown ServiceNotFoundException will not be caught
176
-            $entity = $this->get($identifier);
177
-        } else {
178
-            // if identifier is for a non-shared entity,
179
-            // then either a cached closure already existed, or was just brewed
180
-            $closure = $this->reservoir->get($identifier);
181
-            $entity = $closure($arguments);
182
-        }
183
-        return $entity;
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * @param CoffeeMakerInterface $coffee_maker
190
-     * @param string               $type
191
-     * @return bool
192
-     */
193
-    public function addCoffeeMaker(CoffeeMakerInterface $coffee_maker, $type)
194
-    {
195
-        $type = CoffeeMaker::validateType($type);
196
-        return $this->coffee_makers->add($coffee_maker, $type);
197
-    }
198
-
199
-
200
-
201
-    /**
202
-     * @param string   $identifier
203
-     * @param callable $closure
204
-     * @return callable|null
205
-     */
206
-    public function addClosure($identifier, $closure)
207
-    {
208
-        if ( ! is_callable($closure)) {
209
-            throw new InvalidDataTypeException('$closure', $closure, 'Closure');
210
-        }
211
-        $identifier = $this->processIdentifier($identifier);
212
-        if ($this->reservoir->add($closure, $identifier)) {
213
-            return $closure;
214
-        }
215
-        return null;
216
-    }
217
-
218
-
219
-
220
-    /**
221
-     * @param string   $identifier
222
-     * @return boolean
223
-     */
224
-    public function removeClosure($identifier)
225
-    {
226
-        $identifier = $this->processIdentifier($identifier);
227
-        if ($this->reservoir->has($identifier)) {
228
-            $this->reservoir->remove($this->reservoir->get($identifier));
229
-            if ( ! $this->reservoir->has($identifier)) {
230
-                return true;
231
-            }
232
-        }
233
-        return false;
234
-    }
235
-
236
-
237
-
238
-    /**
239
-     * @param  string $identifier Identifier for the entity class that the service applies to
240
-     *                            Typically a Fully Qualified Class Name
241
-     * @param mixed  $service
242
-     * @return bool
243
-     */
244
-    public function addService($identifier, $service)
245
-    {
246
-        $identifier = $this->processIdentifier($identifier);
247
-        $service = $this->validateService($identifier, $service);
248
-        return $this->carafe->add($service, $identifier);
249
-    }
250
-
251
-
252
-
253
-    /**
254
-     * @param string $identifier
255
-     * @return boolean
256
-     */
257
-    public function removeService($identifier)
258
-    {
259
-        $identifier = $this->processIdentifier($identifier);
260
-        if ($this->carafe->has($identifier)) {
261
-            $this->carafe->remove($this->carafe->get($identifier));
262
-            if ( ! $this->carafe->has($identifier)) {
263
-                return true;
264
-            }
265
-        }
266
-        return false;
267
-    }
268
-
269
-
270
-
271
-    /**
272
-     * Adds instructions on how to brew objects
273
-     *
274
-     * @param RecipeInterface $recipe
275
-     * @return mixed
276
-     */
277
-    public function addRecipe(RecipeInterface $recipe)
278
-    {
279
-        $this->addAliases($recipe->identifier(), $recipe->filters());
280
-        $identifier = $this->processIdentifier($recipe->identifier());
281
-        return $this->recipes->add($recipe, $identifier);
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * @param string $identifier The Recipe's identifier
288
-     * @return boolean
289
-     */
290
-    public function removeRecipe($identifier)
291
-    {
292
-        $identifier = $this->processIdentifier($identifier);
293
-        if ($this->recipes->has($identifier)) {
294
-            $this->recipes->remove(
295
-                $this->recipes->get($identifier)
296
-            );
297
-            if ( ! $this->recipes->has($identifier)) {
298
-                return true;
299
-            }
300
-        }
301
-        return false;
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * Get instructions on how to brew objects
308
-     *
309
-     * @param  string $identifier Identifier for the entity class that the recipe applies to
310
-     *                            Typically a Fully Qualified Class Name
311
-     * @param string $type
312
-     * @return RecipeInterface
313
-     */
314
-    public function getRecipe($identifier, $type = '')
315
-    {
316
-        $identifier = $this->processIdentifier($identifier);
317
-        if ($this->recipes->has($identifier)) {
318
-            return $this->recipes->get($identifier);
319
-        }
320
-        $default_recipes = $this->getDefaultRecipes();
321
-        $matches = array();
322
-        foreach ($default_recipes as $wildcard => $default_recipe) {
323
-            // is the wildcard recipe prefix in the identifier ?
324
-            if (strpos($identifier, $wildcard) !== false) {
325
-                // track matches and use the number of wildcard characters matched for the key
326
-                $matches[strlen($wildcard)] = $default_recipe;
327
-            }
328
-        }
329
-        if (count($matches) > 0) {
330
-            // sort our recipes by the number of wildcard characters matched
331
-            ksort($matches);
332
-            // then grab the last recipe form the list, since it had the most matching characters
333
-            $match = array_pop($matches);
334
-            // since we are using a default recipe, we need to set it's identifier and fqcn
335
-            return $this->copyDefaultRecipe($match, $identifier, $type);
336
-        }
337
-        if ($this->recipes->has(Recipe::DEFAULT_ID)) {
338
-            // since we are using a default recipe, we need to set it's identifier and fqcn
339
-            return $this->copyDefaultRecipe($this->recipes->get(Recipe::DEFAULT_ID), $identifier, $type);
340
-        }
341
-        throw new OutOfBoundsException(
342
-            sprintf(
343
-                __('Could not brew coffee because no recipes were found for class "%1$s".', 'event_espresso'),
344
-                $identifier
345
-            )
346
-        );
347
-    }
348
-
349
-
350
-
351
-    /**
352
-     * adds class name aliases to list of filters
353
-     *
354
-     * @param  string $identifier Identifier for the entity class that the alias applies to
355
-     *                            Typically a Fully Qualified Class Name
356
-     * @param  array  $aliases
357
-     * @return void
358
-     * @throws InvalidIdentifierException
359
-     */
360
-    public function addAliases($identifier, $aliases)
361
-    {
362
-        if (empty($aliases)) {
363
-            return;
364
-        }
365
-        $identifier = $this->processIdentifier($identifier);
366
-        foreach ((array)$aliases as $alias) {
367
-            $this->filters[$this->processIdentifier($alias)] = $identifier;
368
-        }
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * Adds a service to one of the internal collections
375
-     *
376
-     * @param        $identifier
377
-     * @param array  $arguments
378
-     * @param string $type
379
-     * @return mixed
380
-     * @throws ServiceExistsException
381
-     */
382
-    private function makeCoffee($identifier, $arguments = array(), $type = '')
383
-    {
384
-        if ((empty($type) || $type === CoffeeMaker::BREW_SHARED) && $this->has($identifier)) {
385
-            throw new ServiceExistsException($identifier);
386
-        }
387
-        $identifier = $this->filterIdentifier($identifier);
388
-        $recipe = $this->getRecipe($identifier, $type);
389
-        $type = ! empty($type) ? $type : $recipe->type();
390
-        $coffee_maker = $this->getCoffeeMaker($type);
391
-        return $coffee_maker->brew($recipe, $arguments);
392
-    }
393
-
394
-
395
-
396
-    /**
397
-     * filters alias identifiers to find the real class name
398
-     *
399
-     * @param  string $identifier Identifier for the entity class that the filter applies to
400
-     *                            Typically a Fully Qualified Class Name
401
-     * @return string
402
-     * @throws InvalidIdentifierException
403
-     */
404
-    private function filterIdentifier($identifier)
405
-    {
406
-        $identifier = $this->processIdentifier($identifier);
407
-        return isset($this->filters[$identifier]) && ! empty($this->filters[$identifier])
408
-            ? $this->filters[$identifier]
409
-            : $identifier;
410
-    }
411
-
412
-
413
-
414
-    /**
415
-     * verifies and standardizes identifiers
416
-     *
417
-     * @param  string $identifier Identifier for the entity class
418
-     *                            Typically a Fully Qualified Class Name
419
-     * @return string
420
-     * @throws InvalidIdentifierException
421
-     */
422
-    private function processIdentifier($identifier)
423
-    {
424
-        if ( ! is_string($identifier)) {
425
-            throw new InvalidIdentifierException(
426
-                is_object($identifier) ? get_class($identifier) : gettype($identifier),
427
-                '\Fully\Qualified\ClassName'
428
-            );
429
-        }
430
-        return ltrim($identifier, '\\');
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * @param string $type
437
-     * @return CoffeeMakerInterface
438
-     * @throws InvalidDataTypeException
439
-     * @throws InvalidClassException
440
-     */
441
-    private function getCoffeeMaker($type)
442
-    {
443
-        if ( ! $this->coffee_makers->has($type)) {
444
-            throw new OutOfBoundsException(
445
-                __('The requested coffee maker is either missing or invalid.', 'event_espresso')
446
-            );
447
-        }
448
-        return $this->coffee_makers->get($type);
449
-    }
450
-
451
-
452
-
453
-    /**
454
-     * Retrieves all recipes that use a wildcard "*" in their identifier
455
-     * This allows recipes to be set up for handling
456
-     * legacy classes that do not support PSR-4 autoloading.
457
-     * for example:
458
-     * using "EEM_*" for a recipe identifier would target all legacy models like EEM_Attendee
459
-     *
460
-     * @return array
461
-     */
462
-    private function getDefaultRecipes()
463
-    {
464
-        $default_recipes = array();
465
-        $this->recipes->rewind();
466
-        while ($this->recipes->valid()) {
467
-            $identifier = $this->recipes->getInfo();
468
-            // does this recipe use a wildcard ? (but is NOT the global default)
469
-            if ($identifier !== Recipe::DEFAULT_ID && strpos($identifier, '*') !== false) {
470
-                // strip the wildcard and use identifier as key
471
-                $default_recipes[str_replace('*', '', $identifier)] = $this->recipes->current();
472
-            }
473
-            $this->recipes->next();
474
-        }
475
-        return $default_recipes;
476
-    }
477
-
478
-
479
-
480
-    /**
481
-     * clones a default recipe and then copies details
482
-     * from the incoming request to it so that it can be used
483
-     *
484
-     * @param RecipeInterface $default_recipe
485
-     * @param string          $identifier
486
-     * @param string          $type
487
-     * @return RecipeInterface
488
-     */
489
-    private function copyDefaultRecipe(RecipeInterface $default_recipe, $identifier, $type = '')
490
-    {
491
-        $recipe = clone $default_recipe;
492
-        if ( ! empty($type)) {
493
-            $recipe->setType($type);
494
-        }
495
-        // is this the base default recipe ?
496
-        if ($default_recipe->identifier() === Recipe::DEFAULT_ID) {
497
-            $recipe->setIdentifier($identifier);
498
-            $recipe->setFqcn($identifier);
499
-            return $recipe;
500
-        }
501
-        $recipe->setIdentifier($identifier);
502
-        foreach ($default_recipe->paths() as $path) {
503
-            $path = str_replace('*', $identifier, $path);
504
-            if (is_readable($path)) {
505
-                $recipe->setPaths($path);
506
-            }
507
-        }
508
-        $recipe->setFqcn($identifier);
509
-        return $recipe;
510
-    }
511
-
512
-
513
-
514
-    /**
515
-     * @param  string $identifier Identifier for the entity class that the service applies to
516
-     *                            Typically a Fully Qualified Class Name
517
-     * @param mixed  $service
518
-     * @return object
519
-     * @throws InvalidServiceException
520
-     */
521
-    private function validateService($identifier, $service)
522
-    {
523
-        if ( ! is_object($service)) {
524
-            throw new InvalidServiceException(
525
-                $identifier,
526
-                $service
527
-            );
528
-        }
529
-        return $service;
530
-    }
35
+	/**
36
+	 * This was the best coffee related name I could think of to represent class name "aliases"
37
+	 * So classes can be found via an alias identifier,
38
+	 * that is revealed when it is run through... the filters... eh? get it?
39
+	 *
40
+	 * @var array $filters
41
+	 */
42
+	private $filters = array();
43
+
44
+	/**
45
+	 * These are the classes that will actually build the objects (to order of course)
46
+	 *
47
+	 * @var array $coffee_makers
48
+	 */
49
+	private $coffee_makers = array();
50
+
51
+	/**
52
+	 * where the instantiated "singleton" objects are stored
53
+	 *
54
+	 * @var CollectionInterface $carafe
55
+	 */
56
+	private $carafe;
57
+
58
+	/**
59
+	 * collection of Recipes that instruct us how to brew objects
60
+	 *
61
+	 * @var CollectionInterface $recipes
62
+	 */
63
+	private $recipes;
64
+
65
+	/**
66
+	 * collection of closures for brewing objects
67
+	 *
68
+	 * @var CollectionInterface $reservoir
69
+	 */
70
+	private $reservoir;
71
+
72
+
73
+
74
+	/**
75
+	 * CoffeeShop constructor
76
+	 */
77
+	public function __construct()
78
+	{
79
+		// array for storing class aliases
80
+		$this->filters = array();
81
+		// create collection for storing shared services
82
+		$this->carafe = new LooseCollection( '' );
83
+		// create collection for storing recipes that tell how to build services and entities
84
+		$this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface');
85
+		// create collection for storing closures for constructing new entities
86
+		$this->reservoir = new Collection('Closure');
87
+		// create collection for storing the generators that build our services and entity closures
88
+		$this->coffee_makers = new Collection('EventEspresso\core\services\container\CoffeeMakerInterface');
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * Returns true if the container can return an entry for the given identifier.
95
+	 * Returns false otherwise.
96
+	 * `has($identifier)` returning true does not mean that `get($identifier)` will not throw an exception.
97
+	 * It does however mean that `get($identifier)` will not throw a `ServiceNotFoundException`.
98
+	 *
99
+	 * @param string $identifier  Identifier of the entry to look for.
100
+	 *                            Typically a Fully Qualified Class Name
101
+	 * @return boolean
102
+	 */
103
+	public function has($identifier)
104
+	{
105
+		$identifier = $this->filterIdentifier($identifier);
106
+		return $this->carafe->has($identifier);
107
+	}
108
+
109
+
110
+
111
+	/**
112
+	 * finds a previously brewed (SHARED) service and returns it
113
+	 *
114
+	 * @param  string $identifier Identifier for the entity class to be constructed.
115
+	 *                            Typically a Fully Qualified Class Name
116
+	 * @return mixed
117
+	 * @throws ServiceNotFoundException No service was found for this identifier.
118
+	 */
119
+	public function get($identifier)
120
+	{
121
+		$identifier = $this->filterIdentifier($identifier);
122
+		if ($this->carafe->has($identifier)) {
123
+			return $this->carafe->get($identifier);
124
+		}
125
+		throw new ServiceNotFoundException($identifier);
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * returns an instance of the requested entity type using the supplied arguments.
132
+	 * If a shared service is requested and an instance is already in the carafe, then it will be returned.
133
+	 * If it is not already in the carafe, then the service will be constructed, added to the carafe, and returned
134
+	 * If the request is for a new entity and a closure exists in the reservoir for creating it,
135
+	 * then a new entity will be instantiated from the closure and returned.
136
+	 * If a closure does not exist, then one will be built and added to the reservoir
137
+	 * before instantiating the requested entity.
138
+	 *
139
+	 * @param  string $identifier Identifier for the entity class to be constructed.
140
+	 *                            Typically a Fully Qualified Class Name
141
+	 * @param array   $arguments  an array of arguments to be passed to the entity constructor
142
+	 * @param string  $type
143
+	 * @return mixed
144
+	 * @throws ServiceNotFoundException No service was found for this identifier.
145
+	 */
146
+	public function brew($identifier, $arguments = array(), $type = '')
147
+	{
148
+		// resolve any class aliases that may exist
149
+		$identifier = $this->filterIdentifier($identifier);
150
+		try {
151
+			// is a shared service being requested?
152
+			if (empty($type) || $type === CoffeeMaker::BREW_SHARED) {
153
+				// if a shared service was requested and an instance is in the carafe, then return it
154
+				return $this->get($identifier);
155
+			}
156
+		} catch (ServiceNotFoundException $e) {
157
+			// if not then we'll just catch the ServiceNotFoundException but not do anything just yet,
158
+			// and instead, attempt to build whatever was requested
159
+		}
160
+		$brewed = false;
161
+		// if the reservoir doesn't have a closure already for the requested identifier,
162
+		// then neither a shared service nor a closure for making entities has been built yet
163
+		if ( ! $this->reservoir->has($identifier)) {
164
+			// so let's brew something up and add it to the proper collection
165
+			$brewed = $this->makeCoffee($identifier, $arguments, $type);
166
+		}
167
+		// was the brewed item a callable factory function ?
168
+		if (is_callable($brewed)) {
169
+			// then instantiate a new entity from the cached closure
170
+			$entity = $brewed($arguments);
171
+		} else if ($brewed) {
172
+			// requested object was a shared entity, so attempt to get it from the carafe again
173
+			// because if it wasn't there before, then it should have just been brewed and added,
174
+			// but if it still isn't there, then this time
175
+			// the thrown ServiceNotFoundException will not be caught
176
+			$entity = $this->get($identifier);
177
+		} else {
178
+			// if identifier is for a non-shared entity,
179
+			// then either a cached closure already existed, or was just brewed
180
+			$closure = $this->reservoir->get($identifier);
181
+			$entity = $closure($arguments);
182
+		}
183
+		return $entity;
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * @param CoffeeMakerInterface $coffee_maker
190
+	 * @param string               $type
191
+	 * @return bool
192
+	 */
193
+	public function addCoffeeMaker(CoffeeMakerInterface $coffee_maker, $type)
194
+	{
195
+		$type = CoffeeMaker::validateType($type);
196
+		return $this->coffee_makers->add($coffee_maker, $type);
197
+	}
198
+
199
+
200
+
201
+	/**
202
+	 * @param string   $identifier
203
+	 * @param callable $closure
204
+	 * @return callable|null
205
+	 */
206
+	public function addClosure($identifier, $closure)
207
+	{
208
+		if ( ! is_callable($closure)) {
209
+			throw new InvalidDataTypeException('$closure', $closure, 'Closure');
210
+		}
211
+		$identifier = $this->processIdentifier($identifier);
212
+		if ($this->reservoir->add($closure, $identifier)) {
213
+			return $closure;
214
+		}
215
+		return null;
216
+	}
217
+
218
+
219
+
220
+	/**
221
+	 * @param string   $identifier
222
+	 * @return boolean
223
+	 */
224
+	public function removeClosure($identifier)
225
+	{
226
+		$identifier = $this->processIdentifier($identifier);
227
+		if ($this->reservoir->has($identifier)) {
228
+			$this->reservoir->remove($this->reservoir->get($identifier));
229
+			if ( ! $this->reservoir->has($identifier)) {
230
+				return true;
231
+			}
232
+		}
233
+		return false;
234
+	}
235
+
236
+
237
+
238
+	/**
239
+	 * @param  string $identifier Identifier for the entity class that the service applies to
240
+	 *                            Typically a Fully Qualified Class Name
241
+	 * @param mixed  $service
242
+	 * @return bool
243
+	 */
244
+	public function addService($identifier, $service)
245
+	{
246
+		$identifier = $this->processIdentifier($identifier);
247
+		$service = $this->validateService($identifier, $service);
248
+		return $this->carafe->add($service, $identifier);
249
+	}
250
+
251
+
252
+
253
+	/**
254
+	 * @param string $identifier
255
+	 * @return boolean
256
+	 */
257
+	public function removeService($identifier)
258
+	{
259
+		$identifier = $this->processIdentifier($identifier);
260
+		if ($this->carafe->has($identifier)) {
261
+			$this->carafe->remove($this->carafe->get($identifier));
262
+			if ( ! $this->carafe->has($identifier)) {
263
+				return true;
264
+			}
265
+		}
266
+		return false;
267
+	}
268
+
269
+
270
+
271
+	/**
272
+	 * Adds instructions on how to brew objects
273
+	 *
274
+	 * @param RecipeInterface $recipe
275
+	 * @return mixed
276
+	 */
277
+	public function addRecipe(RecipeInterface $recipe)
278
+	{
279
+		$this->addAliases($recipe->identifier(), $recipe->filters());
280
+		$identifier = $this->processIdentifier($recipe->identifier());
281
+		return $this->recipes->add($recipe, $identifier);
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * @param string $identifier The Recipe's identifier
288
+	 * @return boolean
289
+	 */
290
+	public function removeRecipe($identifier)
291
+	{
292
+		$identifier = $this->processIdentifier($identifier);
293
+		if ($this->recipes->has($identifier)) {
294
+			$this->recipes->remove(
295
+				$this->recipes->get($identifier)
296
+			);
297
+			if ( ! $this->recipes->has($identifier)) {
298
+				return true;
299
+			}
300
+		}
301
+		return false;
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * Get instructions on how to brew objects
308
+	 *
309
+	 * @param  string $identifier Identifier for the entity class that the recipe applies to
310
+	 *                            Typically a Fully Qualified Class Name
311
+	 * @param string $type
312
+	 * @return RecipeInterface
313
+	 */
314
+	public function getRecipe($identifier, $type = '')
315
+	{
316
+		$identifier = $this->processIdentifier($identifier);
317
+		if ($this->recipes->has($identifier)) {
318
+			return $this->recipes->get($identifier);
319
+		}
320
+		$default_recipes = $this->getDefaultRecipes();
321
+		$matches = array();
322
+		foreach ($default_recipes as $wildcard => $default_recipe) {
323
+			// is the wildcard recipe prefix in the identifier ?
324
+			if (strpos($identifier, $wildcard) !== false) {
325
+				// track matches and use the number of wildcard characters matched for the key
326
+				$matches[strlen($wildcard)] = $default_recipe;
327
+			}
328
+		}
329
+		if (count($matches) > 0) {
330
+			// sort our recipes by the number of wildcard characters matched
331
+			ksort($matches);
332
+			// then grab the last recipe form the list, since it had the most matching characters
333
+			$match = array_pop($matches);
334
+			// since we are using a default recipe, we need to set it's identifier and fqcn
335
+			return $this->copyDefaultRecipe($match, $identifier, $type);
336
+		}
337
+		if ($this->recipes->has(Recipe::DEFAULT_ID)) {
338
+			// since we are using a default recipe, we need to set it's identifier and fqcn
339
+			return $this->copyDefaultRecipe($this->recipes->get(Recipe::DEFAULT_ID), $identifier, $type);
340
+		}
341
+		throw new OutOfBoundsException(
342
+			sprintf(
343
+				__('Could not brew coffee because no recipes were found for class "%1$s".', 'event_espresso'),
344
+				$identifier
345
+			)
346
+		);
347
+	}
348
+
349
+
350
+
351
+	/**
352
+	 * adds class name aliases to list of filters
353
+	 *
354
+	 * @param  string $identifier Identifier for the entity class that the alias applies to
355
+	 *                            Typically a Fully Qualified Class Name
356
+	 * @param  array  $aliases
357
+	 * @return void
358
+	 * @throws InvalidIdentifierException
359
+	 */
360
+	public function addAliases($identifier, $aliases)
361
+	{
362
+		if (empty($aliases)) {
363
+			return;
364
+		}
365
+		$identifier = $this->processIdentifier($identifier);
366
+		foreach ((array)$aliases as $alias) {
367
+			$this->filters[$this->processIdentifier($alias)] = $identifier;
368
+		}
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * Adds a service to one of the internal collections
375
+	 *
376
+	 * @param        $identifier
377
+	 * @param array  $arguments
378
+	 * @param string $type
379
+	 * @return mixed
380
+	 * @throws ServiceExistsException
381
+	 */
382
+	private function makeCoffee($identifier, $arguments = array(), $type = '')
383
+	{
384
+		if ((empty($type) || $type === CoffeeMaker::BREW_SHARED) && $this->has($identifier)) {
385
+			throw new ServiceExistsException($identifier);
386
+		}
387
+		$identifier = $this->filterIdentifier($identifier);
388
+		$recipe = $this->getRecipe($identifier, $type);
389
+		$type = ! empty($type) ? $type : $recipe->type();
390
+		$coffee_maker = $this->getCoffeeMaker($type);
391
+		return $coffee_maker->brew($recipe, $arguments);
392
+	}
393
+
394
+
395
+
396
+	/**
397
+	 * filters alias identifiers to find the real class name
398
+	 *
399
+	 * @param  string $identifier Identifier for the entity class that the filter applies to
400
+	 *                            Typically a Fully Qualified Class Name
401
+	 * @return string
402
+	 * @throws InvalidIdentifierException
403
+	 */
404
+	private function filterIdentifier($identifier)
405
+	{
406
+		$identifier = $this->processIdentifier($identifier);
407
+		return isset($this->filters[$identifier]) && ! empty($this->filters[$identifier])
408
+			? $this->filters[$identifier]
409
+			: $identifier;
410
+	}
411
+
412
+
413
+
414
+	/**
415
+	 * verifies and standardizes identifiers
416
+	 *
417
+	 * @param  string $identifier Identifier for the entity class
418
+	 *                            Typically a Fully Qualified Class Name
419
+	 * @return string
420
+	 * @throws InvalidIdentifierException
421
+	 */
422
+	private function processIdentifier($identifier)
423
+	{
424
+		if ( ! is_string($identifier)) {
425
+			throw new InvalidIdentifierException(
426
+				is_object($identifier) ? get_class($identifier) : gettype($identifier),
427
+				'\Fully\Qualified\ClassName'
428
+			);
429
+		}
430
+		return ltrim($identifier, '\\');
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * @param string $type
437
+	 * @return CoffeeMakerInterface
438
+	 * @throws InvalidDataTypeException
439
+	 * @throws InvalidClassException
440
+	 */
441
+	private function getCoffeeMaker($type)
442
+	{
443
+		if ( ! $this->coffee_makers->has($type)) {
444
+			throw new OutOfBoundsException(
445
+				__('The requested coffee maker is either missing or invalid.', 'event_espresso')
446
+			);
447
+		}
448
+		return $this->coffee_makers->get($type);
449
+	}
450
+
451
+
452
+
453
+	/**
454
+	 * Retrieves all recipes that use a wildcard "*" in their identifier
455
+	 * This allows recipes to be set up for handling
456
+	 * legacy classes that do not support PSR-4 autoloading.
457
+	 * for example:
458
+	 * using "EEM_*" for a recipe identifier would target all legacy models like EEM_Attendee
459
+	 *
460
+	 * @return array
461
+	 */
462
+	private function getDefaultRecipes()
463
+	{
464
+		$default_recipes = array();
465
+		$this->recipes->rewind();
466
+		while ($this->recipes->valid()) {
467
+			$identifier = $this->recipes->getInfo();
468
+			// does this recipe use a wildcard ? (but is NOT the global default)
469
+			if ($identifier !== Recipe::DEFAULT_ID && strpos($identifier, '*') !== false) {
470
+				// strip the wildcard and use identifier as key
471
+				$default_recipes[str_replace('*', '', $identifier)] = $this->recipes->current();
472
+			}
473
+			$this->recipes->next();
474
+		}
475
+		return $default_recipes;
476
+	}
477
+
478
+
479
+
480
+	/**
481
+	 * clones a default recipe and then copies details
482
+	 * from the incoming request to it so that it can be used
483
+	 *
484
+	 * @param RecipeInterface $default_recipe
485
+	 * @param string          $identifier
486
+	 * @param string          $type
487
+	 * @return RecipeInterface
488
+	 */
489
+	private function copyDefaultRecipe(RecipeInterface $default_recipe, $identifier, $type = '')
490
+	{
491
+		$recipe = clone $default_recipe;
492
+		if ( ! empty($type)) {
493
+			$recipe->setType($type);
494
+		}
495
+		// is this the base default recipe ?
496
+		if ($default_recipe->identifier() === Recipe::DEFAULT_ID) {
497
+			$recipe->setIdentifier($identifier);
498
+			$recipe->setFqcn($identifier);
499
+			return $recipe;
500
+		}
501
+		$recipe->setIdentifier($identifier);
502
+		foreach ($default_recipe->paths() as $path) {
503
+			$path = str_replace('*', $identifier, $path);
504
+			if (is_readable($path)) {
505
+				$recipe->setPaths($path);
506
+			}
507
+		}
508
+		$recipe->setFqcn($identifier);
509
+		return $recipe;
510
+	}
511
+
512
+
513
+
514
+	/**
515
+	 * @param  string $identifier Identifier for the entity class that the service applies to
516
+	 *                            Typically a Fully Qualified Class Name
517
+	 * @param mixed  $service
518
+	 * @return object
519
+	 * @throws InvalidServiceException
520
+	 */
521
+	private function validateService($identifier, $service)
522
+	{
523
+		if ( ! is_object($service)) {
524
+			throw new InvalidServiceException(
525
+				$identifier,
526
+				$service
527
+			);
528
+		}
529
+		return $service;
530
+	}
531 531
 
532 532
 }
533 533
 // End of file CoffeeShop.php
Please login to merge, or discard this patch.
core/services/container/OpenCoffeeShop.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	 * OpenCoffeeShop constructor.
34 34
 	 */
35 35
 	public function __construct()
36
-    {
36
+	{
37 37
 		// instantiate the container
38 38
 		$this->CoffeeShop = new CoffeeShop();
39 39
 		// create a dependency injector class for resolving class constructor arguments
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 			new Recipe(
84 84
 				'CommandHandlerManager',
85 85
 				'EventEspresso\core\services\commands\CommandHandlerManager',
86
-                array(
87
-                    'CommandHandlerManagerInterface',
88
-                    'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
89
-                ),
90
-                array(),
86
+				array(
87
+					'CommandHandlerManagerInterface',
88
+					'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
89
+				),
90
+				array(),
91 91
 				CoffeeMaker::BREW_SHARED
92 92
 			)
93 93
 		);
@@ -96,11 +96,11 @@  discard block
 block discarded – undo
96 96
 			new Recipe(
97 97
 				'CommandBus',
98 98
 				'EventEspresso\core\services\commands\CommandBus',
99
-                array(
100
-                    'CommandBusInterface',
101
-                    'EventEspresso\core\services\commands\CommandBusInterface',
102
-                ),
103
-                array(),
99
+				array(
100
+					'CommandBusInterface',
101
+					'EventEspresso\core\services\commands\CommandBusInterface',
102
+				),
103
+				array(),
104 104
 				CoffeeMaker::BREW_SHARED
105 105
 			)
106 106
 		);
@@ -110,22 +110,22 @@  discard block
 block discarded – undo
110 110
 			new Recipe(
111 111
 				'EEI_*',
112 112
 				'',
113
-                array(),
114
-                array(),
113
+				array(),
114
+				array(),
115 115
 				CoffeeMaker::BREW_LOAD_ONLY,
116
-                array(
117
-                    EE_INTERFACES . '*.php',
118
-                    EE_INTERFACES . '*.interfaces.php',
119
-                )
116
+				array(
117
+					EE_INTERFACES . '*.php',
118
+					EE_INTERFACES . '*.interfaces.php',
119
+				)
120 120
 			)
121 121
 		);
122 122
 		// add a wildcard recipe for loading models
123 123
 		$this->CoffeeShop->addRecipe(
124 124
 			new Recipe(
125 125
 				'EEM_*',
126
-                '',
127
-                array(),
128
-                array(),
126
+				'',
127
+				array(),
128
+				array(),
129 129
 				CoffeeMaker::BREW_SHARED,
130 130
 				EE_MODELS . '*.model.php'
131 131
 			)
@@ -134,10 +134,10 @@  discard block
 block discarded – undo
134 134
 		$this->CoffeeShop->addRecipe(
135 135
 			new Recipe(
136 136
 				'EE_*',
137
-                '',
138
-                array(),
139
-                array(),
140
-                CoffeeMaker::BREW_SHARED,
137
+				'',
138
+				array(),
139
+				array(),
140
+				CoffeeMaker::BREW_SHARED,
141 141
 				array(
142 142
 					EE_CORE . '*.core.php',
143 143
 					EE_ADMIN . '*.core.php',
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
 		$this->CoffeeShop->addRecipe(
153 153
 			new Recipe(
154 154
 				'EE_Admin_Page*',
155
-                '',
156
-                array(),
157
-                array(),
158
-                CoffeeMaker::BREW_LOAD_ONLY,
155
+				'',
156
+				array(),
157
+				array(),
158
+				CoffeeMaker::BREW_LOAD_ONLY,
159 159
 				array( EE_ADMIN . '*.core.php' )
160 160
 			)
161 161
 		);
@@ -163,10 +163,10 @@  discard block
 block discarded – undo
163 163
 		// $this->CoffeeShop->addRecipe(
164 164
 		// 	new Recipe(
165 165
 		// 		'*_Admin_Page',
166
-        //      '',
167
-        //      array(),
168
-        // 		array(),
169
-        // 		CoffeeMaker::BREW_SHARED,
166
+		//      '',
167
+		//      array(),
168
+		// 		array(),
169
+		// 		CoffeeMaker::BREW_SHARED,
170 170
 		// 		array(
171 171
 		// 			EE_ADMIN_PAGES . 'transactions' . DS . '*.core.php',
172 172
 		// 		)
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\services\container;
3 3
 
4
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-	exit( 'No direct script access allowed' );
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -43,17 +43,17 @@  discard block
 block discarded – undo
43 43
 		);
44 44
 		// and some coffeemakers, one for creating new instances
45 45
 		$this->CoffeeShop->addCoffeeMaker(
46
-			new NewCoffeeMaker( $this->CoffeeShop, $this->DependencyInjector ),
46
+			new NewCoffeeMaker($this->CoffeeShop, $this->DependencyInjector),
47 47
 			CoffeeMaker::BREW_NEW
48 48
 		);
49 49
 		// one for shared services
50 50
 		$this->CoffeeShop->addCoffeeMaker(
51
-			new SharedCoffeeMaker( $this->CoffeeShop, $this->DependencyInjector ),
51
+			new SharedCoffeeMaker($this->CoffeeShop, $this->DependencyInjector),
52 52
 			CoffeeMaker::BREW_SHARED
53 53
 		);
54 54
 		// and one for classes that only get loaded
55 55
 		$this->CoffeeShop->addCoffeeMaker(
56
-			new LoadOnlyCoffeeMaker( $this->CoffeeShop, $this->DependencyInjector ),
56
+			new LoadOnlyCoffeeMaker($this->CoffeeShop, $this->DependencyInjector),
57 57
 			CoffeeMaker::BREW_LOAD_ONLY
58 58
 		);
59 59
 		// add default recipe, which should handle loading for most PSR-4 compatible classes
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
                 array(),
115 115
 				CoffeeMaker::BREW_LOAD_ONLY,
116 116
                 array(
117
-                    EE_INTERFACES . '*.php',
118
-                    EE_INTERFACES . '*.interfaces.php',
117
+                    EE_INTERFACES.'*.php',
118
+                    EE_INTERFACES.'*.interfaces.php',
119 119
                 )
120 120
 			)
121 121
 		);
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
                 array(),
128 128
                 array(),
129 129
 				CoffeeMaker::BREW_SHARED,
130
-				EE_MODELS . '*.model.php'
130
+				EE_MODELS.'*.model.php'
131 131
 			)
132 132
 		);
133 133
 		// add a wildcard recipe for loading core classes
@@ -139,12 +139,12 @@  discard block
 block discarded – undo
139 139
                 array(),
140 140
                 CoffeeMaker::BREW_SHARED,
141 141
 				array(
142
-					EE_CORE . '*.core.php',
143
-					EE_ADMIN . '*.core.php',
144
-					EE_CPTS . '*.core.php',
145
-					EE_CORE . 'data_migration_scripts' . DS . '*.core.php',
146
-					EE_CORE . 'request_stack' . DS . '*.core.php',
147
-					EE_CORE . 'middleware' . DS . '*.core.php',
142
+					EE_CORE.'*.core.php',
143
+					EE_ADMIN.'*.core.php',
144
+					EE_CPTS.'*.core.php',
145
+					EE_CORE.'data_migration_scripts'.DS.'*.core.php',
146
+					EE_CORE.'request_stack'.DS.'*.core.php',
147
+					EE_CORE.'middleware'.DS.'*.core.php',
148 148
 				)
149 149
 			)
150 150
 		);
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
                 array(),
157 157
                 array(),
158 158
                 CoffeeMaker::BREW_LOAD_ONLY,
159
-				array( EE_ADMIN . '*.core.php' )
159
+				array(EE_ADMIN.'*.core.php')
160 160
 			)
161 161
 		);
162 162
 		// add a wildcard recipe for loading core classes
Please login to merge, or discard this patch.
core/services/container/Recipe.php 1 patch
Indentation   +308 added lines, -308 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use RuntimeException;
8 8
 
9 9
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
10
-    exit('No direct script access allowed');
10
+	exit('No direct script access allowed');
11 11
 }
12 12
 
13 13
 
@@ -23,313 +23,313 @@  discard block
 block discarded – undo
23 23
 class Recipe implements RecipeInterface
24 24
 {
25 25
 
26
-    /**
27
-     * A default Recipe to use if none is specified for a class
28
-     */
29
-    const DEFAULT_ID = '*';
30
-
31
-    /**
32
-     * Identifier for the entity class to be constructed.
33
-     * Typically a Fully Qualified Class Name
34
-     *
35
-     * @var string $identifier
36
-     */
37
-    private $identifier;
38
-
39
-    /**
40
-     * Fully Qualified Class Name
41
-     *
42
-     * @var string $fqcn
43
-     */
44
-    private $fqcn;
45
-
46
-    /**
47
-     * a dependency class map array
48
-     * If a Recipe is for a single class (or group of classes that shares the EXACT SAME constructor arguments),
49
-     * and that class type hints for an interface, then this property allows you to configure what dependencies
50
-     * get used when instantiating the class.
51
-     * For example:
52
-     *  There's a class called Coffee, and one of its constructor arguments is BeanInterface
53
-     *  There are two implementations of BeanInterface: HonduranBean, and KenyanBean
54
-     *  We want one Coffee object to use HonduranBean for its BeanInterface,
55
-     *  and the 2nd Coffee object to use KenyanBean for its BeanInterface.
56
-     *  To do this, we need to create two Recipes:
57
-     *      one with an identifier of 'HonduranCoffee' using the following ingredients :
58
-     *          array('BeanInterface' => 'HonduranBean')
59
-     *      and the other with an identifier of 'KenyanCoffee' using the following ingredients :
60
-     *          array('BeanInterface' => 'KenyanBean')
61
-     *  Then, whenever the CoffeeShop brews an instance of HonduranCoffee,
62
-     *  an instance of HonduranBean will get injected for the BeanInterface dependency,
63
-     *  and whenever the CoffeeShop brews an instance of KenyanCoffee,
64
-     *  an instance of KenyanBean will get injected for the BeanInterface dependency
65
-     *
66
-     * @var array $ingredients
67
-     */
68
-    private $ingredients = array();
69
-
70
-    /**
71
-     * one of the class constants from CoffeeShop:
72
-     *  CoffeeMaker::BREW_NEW - creates a new instance
73
-     *  CoffeeMaker::BREW_SHARED - creates a shared instance
74
-     *  CoffeeMaker::BREW_LOAD_ONLY - loads but does not instantiate
75
-     *
76
-     * @var string $type
77
-     */
78
-    private $type;
79
-
80
-    /**
81
-     * class name aliases - typically a Fully Qualified Interface that the class implements
82
-     * identifiers passed to the CoffeeShop will be run through the filters to find the correct class name
83
-     *
84
-     * @var array $filters
85
-     */
86
-    private $filters = array();
87
-
88
-    /**
89
-     * array of full server filepaths to files that may contain the class
90
-     *
91
-     * @var array $paths
92
-     */
93
-    private $paths = array();
94
-
95
-
96
-
97
-    /**
98
-     * Recipe constructor.
99
-     *
100
-     * @param string $identifier    class identifier, can be an alias, or FQCN, or whatever
101
-     * @param string $fqcn          \Fully\Qualified\ClassName, optional if $identifier is FQCN
102
-     * @param array  $ingredients   array of dependencies that can not be resolved automatically,
103
-     *                              used for resolving concrete classes for type hinted interfaces
104
-     *                              for the dependencies of THIS class
105
-     * @param string $type          recipe type: one of the class constants on
106
-     *                              \EventEspresso\core\services\container\CoffeeMaker
107
-     * @param array  $filters       array of class aliases, or class interfaces
108
-     *                              this works somewhat opposite to the $ingredients array above,
109
-     *                              in that this array specifies interfaces or aliases
110
-     *                              that this Recipe can be used for when resolving OTHER class's dependencies
111
-     * @param array  $paths         if class can not be loaded via PSR-4 autoloading,
112
-     *                              then supply a filepath, or array of filepaths, so that it can be included
113
-     */
114
-    public function __construct(
115
-	    $identifier,
116
-        $fqcn = '',
117
-        $filters = array(),
118
-        $ingredients = array(),
119
-	    $type = CoffeeMaker::BREW_NEW,
120
-	    $paths = array()
121
-    )
122
-    {
123
-        $this->setIdentifier($identifier);
124
-        $this->setFilters((array)$filters);
125
-        $this->setIngredients((array)$ingredients);
126
-        $this->setType($type);
127
-        $this->setPaths($paths);
128
-        $this->setFqcn($fqcn);
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     * @return string
135
-     */
136
-    public function identifier()
137
-    {
138
-        return $this->identifier;
139
-    }
140
-
141
-
142
-
143
-    /**
144
-     * @return string
145
-     */
146
-    public function fqcn()
147
-    {
148
-        return $this->fqcn;
149
-    }
150
-
151
-
152
-
153
-    /**
154
-     * @return array
155
-     */
156
-    public function filters()
157
-    {
158
-        return (array)$this->filters;
159
-    }
160
-
161
-
162
-
163
-    /**
164
-     * @return array
165
-     */
166
-    public function ingredients()
167
-    {
168
-        return $this->ingredients;
169
-    }
170
-
171
-
172
-
173
-    /**
174
-     * @return string
175
-     */
176
-    public function type()
177
-    {
178
-        return $this->type;
179
-    }
180
-
181
-
182
-
183
-    /**
184
-     * @return array
185
-     */
186
-    public function paths()
187
-    {
188
-        return (array)$this->paths;
189
-    }
190
-
191
-
192
-
193
-    /**
194
-     * @param  string $identifier Identifier for the entity class that the Recipe applies to
195
-     *                            Typically a Fully Qualified Class Name
196
-     */
197
-    public function setIdentifier($identifier)
198
-    {
199
-        if ( ! is_string($identifier) || empty($identifier)) {
200
-            throw new InvalidIdentifierException(
201
-                is_object($identifier) ? get_class($identifier) : gettype($identifier),
202
-                __('class identifier (typically a \Fully\Qualified\ClassName)', 'event_espresso')
203
-            );
204
-        }
205
-        $this->identifier = $identifier;
206
-    }
207
-
208
-
209
-
210
-    /**
211
-     * Ensures incoming string is a valid Fully Qualified Class Name,
212
-     * except if this is the default wildcard Recipe ( * ),
213
-     * or it's NOT an actual FQCN because the Recipe is using filepaths
214
-     * for classes that are not PSR-4 compatible
215
-     * PLZ NOTE:
216
-     *  Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not,
217
-     *  therefore you should always call Recipe::setPaths() before Recipe::setFqcn()
218
-     *
219
-     * @param string $fqcn
220
-     */
221
-    public function setFqcn($fqcn)
222
-    {
223
-	    $fqcn = ! empty($fqcn) ? $fqcn : $this->identifier;
224
-        if ( ! is_string($fqcn)) {
225
-            throw new InvalidDataTypeException(
226
-                '$fqcn',
227
-                is_object($fqcn) ? get_class($fqcn) : gettype($fqcn),
228
-                __('string (Fully\Qualified\ClassName)', 'event_espresso')
229
-            );
230
-        }
231
-        $fqcn = ltrim($fqcn, '\\');
232
-        if (
233
-            $fqcn !== Recipe::DEFAULT_ID
234
-            && ! empty($fqcn)
235
-            && empty($this->paths)
236
-            && ! class_exists($fqcn)
237
-        ) {
238
-            throw new InvalidClassException($fqcn);
239
-        }
240
-        $this->fqcn = $fqcn;
241
-    }
242
-
243
-
244
-
245
-    /**
246
-     * @param array $ingredients    an array of dependencies where keys are the aliases and values are the FQCNs
247
-     *                              example:
248
-     *                              array( 'ClassInterface' => 'Fully\Qualified\ClassName' )
249
-     */
250
-    public function setIngredients(array $ingredients)
251
-    {
252
-        if (empty($ingredients)) {
253
-            return;
254
-        }
255
-        if ( ! is_array($ingredients)) {
256
-            throw new InvalidDataTypeException(
257
-                '$ingredients',
258
-                is_object($ingredients) ? get_class($ingredients) : gettype($ingredients),
259
-                __('array of class dependencies', 'event_espresso')
260
-            );
261
-        }
262
-        $this->ingredients = array_merge($this->ingredients, $ingredients);
263
-    }
264
-
265
-
266
-    /**
267
-     * @param string $type one of the class constants returned from CoffeeMaker::getTypes()
268
-     */
269
-    public function setType($type = CoffeeMaker::BREW_NEW)
270
-    {
271
-        $this->type = CoffeeMaker::validateType($type);
272
-    }
273
-
274
-
275
-
276
-    /**
277
-     * @param array $filters an array of filters where keys are the aliases and values are the FQCNs
278
-     *                          example:
279
-     *                          array( 'ClassInterface' => 'Fully\Qualified\ClassName' )
280
-     */
281
-    public function setFilters(array $filters)
282
-    {
283
-        if (empty($filters)) {
284
-            return;
285
-        }
286
-        if ( ! is_array($filters)) {
287
-            throw new InvalidDataTypeException(
288
-                '$filters',
289
-                is_object($filters) ? get_class($filters) : gettype($filters),
290
-                __('array of class aliases', 'event_espresso')
291
-            );
292
-        }
293
-        $this->filters = array_merge($this->filters, $filters);
294
-    }
295
-
296
-
297
-
298
-    /**
299
-     * Ensures incoming paths is a valid filepath, or array of valid filepaths,
300
-     * and merges them in with any existing filepaths
301
-     *
302
-     * PLZ NOTE:
303
-     *  Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not,
304
-     *  therefore you should always call Recipe::setPaths() before Recipe::setFqcn()
305
-     *
306
-     * @param string|array $paths
307
-     */
308
-    public function setPaths($paths = array())
309
-    {
310
-        if (empty($paths)) {
311
-            return;
312
-        }
313
-        if ( ! (is_string($paths) || is_array($paths))) {
314
-            throw new InvalidDataTypeException(
315
-                '$path',
316
-                is_object($paths) ? get_class($paths) : gettype($paths),
317
-                __('string or array of strings (full server filepath(s))', 'event_espresso')
318
-            );
319
-        }
320
-        $paths = (array)$paths;
321
-        foreach ($paths as $path) {
322
-            if (strpos($path, '*') === false && ! is_readable($path)) {
323
-                throw new RuntimeException(
324
-                    sprintf(
325
-                        __('The following filepath is not readable: "%1$s"', 'event_espresso'),
326
-                        $path
327
-                    )
328
-                );
329
-            }
330
-        }
331
-        $this->paths = array_merge($this->paths, $paths);
332
-    }
26
+	/**
27
+	 * A default Recipe to use if none is specified for a class
28
+	 */
29
+	const DEFAULT_ID = '*';
30
+
31
+	/**
32
+	 * Identifier for the entity class to be constructed.
33
+	 * Typically a Fully Qualified Class Name
34
+	 *
35
+	 * @var string $identifier
36
+	 */
37
+	private $identifier;
38
+
39
+	/**
40
+	 * Fully Qualified Class Name
41
+	 *
42
+	 * @var string $fqcn
43
+	 */
44
+	private $fqcn;
45
+
46
+	/**
47
+	 * a dependency class map array
48
+	 * If a Recipe is for a single class (or group of classes that shares the EXACT SAME constructor arguments),
49
+	 * and that class type hints for an interface, then this property allows you to configure what dependencies
50
+	 * get used when instantiating the class.
51
+	 * For example:
52
+	 *  There's a class called Coffee, and one of its constructor arguments is BeanInterface
53
+	 *  There are two implementations of BeanInterface: HonduranBean, and KenyanBean
54
+	 *  We want one Coffee object to use HonduranBean for its BeanInterface,
55
+	 *  and the 2nd Coffee object to use KenyanBean for its BeanInterface.
56
+	 *  To do this, we need to create two Recipes:
57
+	 *      one with an identifier of 'HonduranCoffee' using the following ingredients :
58
+	 *          array('BeanInterface' => 'HonduranBean')
59
+	 *      and the other with an identifier of 'KenyanCoffee' using the following ingredients :
60
+	 *          array('BeanInterface' => 'KenyanBean')
61
+	 *  Then, whenever the CoffeeShop brews an instance of HonduranCoffee,
62
+	 *  an instance of HonduranBean will get injected for the BeanInterface dependency,
63
+	 *  and whenever the CoffeeShop brews an instance of KenyanCoffee,
64
+	 *  an instance of KenyanBean will get injected for the BeanInterface dependency
65
+	 *
66
+	 * @var array $ingredients
67
+	 */
68
+	private $ingredients = array();
69
+
70
+	/**
71
+	 * one of the class constants from CoffeeShop:
72
+	 *  CoffeeMaker::BREW_NEW - creates a new instance
73
+	 *  CoffeeMaker::BREW_SHARED - creates a shared instance
74
+	 *  CoffeeMaker::BREW_LOAD_ONLY - loads but does not instantiate
75
+	 *
76
+	 * @var string $type
77
+	 */
78
+	private $type;
79
+
80
+	/**
81
+	 * class name aliases - typically a Fully Qualified Interface that the class implements
82
+	 * identifiers passed to the CoffeeShop will be run through the filters to find the correct class name
83
+	 *
84
+	 * @var array $filters
85
+	 */
86
+	private $filters = array();
87
+
88
+	/**
89
+	 * array of full server filepaths to files that may contain the class
90
+	 *
91
+	 * @var array $paths
92
+	 */
93
+	private $paths = array();
94
+
95
+
96
+
97
+	/**
98
+	 * Recipe constructor.
99
+	 *
100
+	 * @param string $identifier    class identifier, can be an alias, or FQCN, or whatever
101
+	 * @param string $fqcn          \Fully\Qualified\ClassName, optional if $identifier is FQCN
102
+	 * @param array  $ingredients   array of dependencies that can not be resolved automatically,
103
+	 *                              used for resolving concrete classes for type hinted interfaces
104
+	 *                              for the dependencies of THIS class
105
+	 * @param string $type          recipe type: one of the class constants on
106
+	 *                              \EventEspresso\core\services\container\CoffeeMaker
107
+	 * @param array  $filters       array of class aliases, or class interfaces
108
+	 *                              this works somewhat opposite to the $ingredients array above,
109
+	 *                              in that this array specifies interfaces or aliases
110
+	 *                              that this Recipe can be used for when resolving OTHER class's dependencies
111
+	 * @param array  $paths         if class can not be loaded via PSR-4 autoloading,
112
+	 *                              then supply a filepath, or array of filepaths, so that it can be included
113
+	 */
114
+	public function __construct(
115
+		$identifier,
116
+		$fqcn = '',
117
+		$filters = array(),
118
+		$ingredients = array(),
119
+		$type = CoffeeMaker::BREW_NEW,
120
+		$paths = array()
121
+	)
122
+	{
123
+		$this->setIdentifier($identifier);
124
+		$this->setFilters((array)$filters);
125
+		$this->setIngredients((array)$ingredients);
126
+		$this->setType($type);
127
+		$this->setPaths($paths);
128
+		$this->setFqcn($fqcn);
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 * @return string
135
+	 */
136
+	public function identifier()
137
+	{
138
+		return $this->identifier;
139
+	}
140
+
141
+
142
+
143
+	/**
144
+	 * @return string
145
+	 */
146
+	public function fqcn()
147
+	{
148
+		return $this->fqcn;
149
+	}
150
+
151
+
152
+
153
+	/**
154
+	 * @return array
155
+	 */
156
+	public function filters()
157
+	{
158
+		return (array)$this->filters;
159
+	}
160
+
161
+
162
+
163
+	/**
164
+	 * @return array
165
+	 */
166
+	public function ingredients()
167
+	{
168
+		return $this->ingredients;
169
+	}
170
+
171
+
172
+
173
+	/**
174
+	 * @return string
175
+	 */
176
+	public function type()
177
+	{
178
+		return $this->type;
179
+	}
180
+
181
+
182
+
183
+	/**
184
+	 * @return array
185
+	 */
186
+	public function paths()
187
+	{
188
+		return (array)$this->paths;
189
+	}
190
+
191
+
192
+
193
+	/**
194
+	 * @param  string $identifier Identifier for the entity class that the Recipe applies to
195
+	 *                            Typically a Fully Qualified Class Name
196
+	 */
197
+	public function setIdentifier($identifier)
198
+	{
199
+		if ( ! is_string($identifier) || empty($identifier)) {
200
+			throw new InvalidIdentifierException(
201
+				is_object($identifier) ? get_class($identifier) : gettype($identifier),
202
+				__('class identifier (typically a \Fully\Qualified\ClassName)', 'event_espresso')
203
+			);
204
+		}
205
+		$this->identifier = $identifier;
206
+	}
207
+
208
+
209
+
210
+	/**
211
+	 * Ensures incoming string is a valid Fully Qualified Class Name,
212
+	 * except if this is the default wildcard Recipe ( * ),
213
+	 * or it's NOT an actual FQCN because the Recipe is using filepaths
214
+	 * for classes that are not PSR-4 compatible
215
+	 * PLZ NOTE:
216
+	 *  Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not,
217
+	 *  therefore you should always call Recipe::setPaths() before Recipe::setFqcn()
218
+	 *
219
+	 * @param string $fqcn
220
+	 */
221
+	public function setFqcn($fqcn)
222
+	{
223
+		$fqcn = ! empty($fqcn) ? $fqcn : $this->identifier;
224
+		if ( ! is_string($fqcn)) {
225
+			throw new InvalidDataTypeException(
226
+				'$fqcn',
227
+				is_object($fqcn) ? get_class($fqcn) : gettype($fqcn),
228
+				__('string (Fully\Qualified\ClassName)', 'event_espresso')
229
+			);
230
+		}
231
+		$fqcn = ltrim($fqcn, '\\');
232
+		if (
233
+			$fqcn !== Recipe::DEFAULT_ID
234
+			&& ! empty($fqcn)
235
+			&& empty($this->paths)
236
+			&& ! class_exists($fqcn)
237
+		) {
238
+			throw new InvalidClassException($fqcn);
239
+		}
240
+		$this->fqcn = $fqcn;
241
+	}
242
+
243
+
244
+
245
+	/**
246
+	 * @param array $ingredients    an array of dependencies where keys are the aliases and values are the FQCNs
247
+	 *                              example:
248
+	 *                              array( 'ClassInterface' => 'Fully\Qualified\ClassName' )
249
+	 */
250
+	public function setIngredients(array $ingredients)
251
+	{
252
+		if (empty($ingredients)) {
253
+			return;
254
+		}
255
+		if ( ! is_array($ingredients)) {
256
+			throw new InvalidDataTypeException(
257
+				'$ingredients',
258
+				is_object($ingredients) ? get_class($ingredients) : gettype($ingredients),
259
+				__('array of class dependencies', 'event_espresso')
260
+			);
261
+		}
262
+		$this->ingredients = array_merge($this->ingredients, $ingredients);
263
+	}
264
+
265
+
266
+	/**
267
+	 * @param string $type one of the class constants returned from CoffeeMaker::getTypes()
268
+	 */
269
+	public function setType($type = CoffeeMaker::BREW_NEW)
270
+	{
271
+		$this->type = CoffeeMaker::validateType($type);
272
+	}
273
+
274
+
275
+
276
+	/**
277
+	 * @param array $filters an array of filters where keys are the aliases and values are the FQCNs
278
+	 *                          example:
279
+	 *                          array( 'ClassInterface' => 'Fully\Qualified\ClassName' )
280
+	 */
281
+	public function setFilters(array $filters)
282
+	{
283
+		if (empty($filters)) {
284
+			return;
285
+		}
286
+		if ( ! is_array($filters)) {
287
+			throw new InvalidDataTypeException(
288
+				'$filters',
289
+				is_object($filters) ? get_class($filters) : gettype($filters),
290
+				__('array of class aliases', 'event_espresso')
291
+			);
292
+		}
293
+		$this->filters = array_merge($this->filters, $filters);
294
+	}
295
+
296
+
297
+
298
+	/**
299
+	 * Ensures incoming paths is a valid filepath, or array of valid filepaths,
300
+	 * and merges them in with any existing filepaths
301
+	 *
302
+	 * PLZ NOTE:
303
+	 *  Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not,
304
+	 *  therefore you should always call Recipe::setPaths() before Recipe::setFqcn()
305
+	 *
306
+	 * @param string|array $paths
307
+	 */
308
+	public function setPaths($paths = array())
309
+	{
310
+		if (empty($paths)) {
311
+			return;
312
+		}
313
+		if ( ! (is_string($paths) || is_array($paths))) {
314
+			throw new InvalidDataTypeException(
315
+				'$path',
316
+				is_object($paths) ? get_class($paths) : gettype($paths),
317
+				__('string or array of strings (full server filepath(s))', 'event_espresso')
318
+			);
319
+		}
320
+		$paths = (array)$paths;
321
+		foreach ($paths as $path) {
322
+			if (strpos($path, '*') === false && ! is_readable($path)) {
323
+				throw new RuntimeException(
324
+					sprintf(
325
+						__('The following filepath is not readable: "%1$s"', 'event_espresso'),
326
+						$path
327
+					)
328
+				);
329
+			}
330
+		}
331
+		$this->paths = array_merge($this->paths, $paths);
332
+	}
333 333
 
334 334
 
335 335
 
Please login to merge, or discard this patch.
core/EE_Load_Espresso_Core.core.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
4
-	exit( 'No direct script access allowed' );
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 /**
7 7
  *
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 */
53 53
 	public function __construct() {
54 54
 		// deprecated functions
55
-		espresso_load_required( 'EventEspresso\core\Factory', EE_CORE . 'Factory.php' );
55
+		espresso_load_required('EventEspresso\core\Factory', EE_CORE.'Factory.php');
56 56
 	}
57 57
 
58 58
 
@@ -68,16 +68,16 @@  discard block
 block discarded – undo
68 68
 	 * @param 	EE_Response $response
69 69
 	 * @return 	EE_Response
70 70
 	 */
71
-	public function handle_request( EE_Request $request, EE_Response $response ) {
71
+	public function handle_request(EE_Request $request, EE_Response $response) {
72 72
 		$this->request = $request;
73 73
 		$this->response = $response;
74 74
 		// info about how to load classes required by other classes
75 75
 		$this->dependency_map = $this->_load_dependency_map();
76 76
 		// central repository for classes
77 77
 		$this->registry = $this->_load_registry();
78
-		do_action( 'EE_Load_Espresso_Core__handle_request__initialize_core_loading' );
78
+		do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading');
79 79
 		// PSR4 Autoloaders
80
-		$this->registry->load_core( 'EE_Psr4AutoloaderInit' );
80
+		$this->registry->load_core('EE_Psr4AutoloaderInit');
81 81
 		// build DI container
82 82
 		$OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop();
83 83
 		$OpenCoffeeShop->addRecipes();
@@ -87,20 +87,20 @@  discard block
 block discarded – undo
87 87
 			'CommandBusInterface',
88 88
 			array(
89 89
 				null,
90
-				$this->registry->create( 'CapChecker' )
90
+				$this->registry->create('CapChecker')
91 91
 			),
92 92
 			true
93 93
 		);
94 94
 		// workarounds for PHP < 5.3
95 95
 		$this->_load_class_tools();
96 96
 		// load interfaces
97
-		espresso_load_required( 'EEI_Payment_Method_Interfaces', EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php' );
97
+		espresso_load_required('EEI_Payment_Method_Interfaces', EE_LIBRARIES.'payment_methods'.DS.'EEI_Payment_Method_Interfaces.php');
98 98
 		// deprecated functions
99
-		espresso_load_required( 'EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php' );
99
+		espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php');
100 100
 		// WP cron jobs
101
-		$this->registry->load_core( 'Cron_Tasks' );
102
-		$this->registry->load_core( 'EE_Request_Handler' );
103
-		$this->registry->load_core( 'EE_System' );
101
+		$this->registry->load_core('Cron_Tasks');
102
+		$this->registry->load_core('EE_Request_Handler');
103
+		$this->registry->load_core('EE_System');
104 104
 
105 105
 		return $this->response;
106 106
 	}
@@ -130,11 +130,11 @@  discard block
 block discarded – undo
130 130
 	 * @throws \EE_Error
131 131
 	 */
132 132
 	public function dependency_map() {
133
-		if ( ! $this->dependency_map instanceof EE_Dependency_Map ) {
133
+		if ( ! $this->dependency_map instanceof EE_Dependency_Map) {
134 134
 			throw new EE_Error(
135 135
 				sprintf(
136
-					__( 'Invalid EE_Dependency_Map: "%1$s"', 'event_espresso' ),
137
-					print_r( $this->dependency_map, true )
136
+					__('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
137
+					print_r($this->dependency_map, true)
138 138
 				)
139 139
 			);
140 140
 		}
@@ -148,11 +148,11 @@  discard block
 block discarded – undo
148 148
 	 * @throws \EE_Error
149 149
 	 */
150 150
 	public function registry() {
151
-		if ( ! $this->registry instanceof EE_Registry ) {
151
+		if ( ! $this->registry instanceof EE_Registry) {
152 152
 			throw new EE_Error(
153 153
 				sprintf(
154
-					__( 'Invalid EE_Registry: "%1$s"', 'event_espresso' ),
155
-					print_r( $this->registry, true )
154
+					__('Invalid EE_Registry: "%1$s"', 'event_espresso'),
155
+					print_r($this->registry, true)
156 156
 				)
157 157
 			);
158 158
 		}
@@ -168,15 +168,15 @@  discard block
 block discarded – undo
168 168
 	 * 	@return EE_Dependency_Map
169 169
 	 */
170 170
 	private function _load_dependency_map() {
171
-		if ( ! is_readable( EE_CORE . 'EE_Dependency_Map.core.php' ) ) {
171
+		if ( ! is_readable(EE_CORE.'EE_Dependency_Map.core.php')) {
172 172
 			EE_Error::add_error(
173
-				__( 'The EE_Dependency_Map core class could not be loaded.', 'event_espresso' ),
173
+				__('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
174 174
 				__FILE__, __FUNCTION__, __LINE__
175 175
 			);
176
-			wp_die( EE_Error::get_notices() );
176
+			wp_die(EE_Error::get_notices());
177 177
 		}
178
-		require_once( EE_CORE . 'EE_Dependency_Map.core.php' );
179
-		return EE_Dependency_Map::instance( $this->request, $this->response );
178
+		require_once(EE_CORE.'EE_Dependency_Map.core.php');
179
+		return EE_Dependency_Map::instance($this->request, $this->response);
180 180
 	}
181 181
 
182 182
 
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
 	 * 	@return EE_Registry
189 189
 	 */
190 190
 	private function _load_registry() {
191
-		if ( ! is_readable( EE_CORE . 'EE_Registry.core.php' )) {
191
+		if ( ! is_readable(EE_CORE.'EE_Registry.core.php')) {
192 192
 			EE_Error::add_error(
193
-				__( 'The EE_Registry core class could not be loaded.', 'event_espresso' ),
193
+				__('The EE_Registry core class could not be loaded.', 'event_espresso'),
194 194
 				__FILE__, __FUNCTION__, __LINE__
195 195
 			);
196
-			wp_die( EE_Error::get_notices() );
196
+			wp_die(EE_Error::get_notices());
197 197
 		}
198
-		require_once( EE_CORE . 'EE_Registry.core.php' );
199
-		return EE_Registry::instance( $this->dependency_map );
198
+		require_once(EE_CORE.'EE_Registry.core.php');
199
+		return EE_Registry::instance($this->dependency_map);
200 200
 	}
201 201
 
202 202
 
@@ -207,13 +207,13 @@  discard block
 block discarded – undo
207 207
 	 * 	@return void
208 208
 	 */
209 209
 	private function _load_class_tools() {
210
-		if ( ! is_readable( EE_HELPERS . 'EEH_Class_Tools.helper.php' )) {
210
+		if ( ! is_readable(EE_HELPERS.'EEH_Class_Tools.helper.php')) {
211 211
 			EE_Error::add_error(
212
-				__( 'The EEH_Class_Tools helper could not be loaded.', 'event_espresso' ),
212
+				__('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
213 213
 				__FILE__, __FUNCTION__, __LINE__
214 214
 			);
215 215
 		}
216
-		require_once( EE_HELPERS . 'EEH_Class_Tools.helper.php' );
216
+		require_once(EE_HELPERS.'EEH_Class_Tools.helper.php');
217 217
 	}
218 218
 
219 219
 
@@ -227,13 +227,13 @@  discard block
 block discarded – undo
227 227
 	 * @param \EE_Request $request
228 228
 	 * @param \EE_Response $response
229 229
 	 */
230
-	public function handle_response( EE_Request $request, EE_Response $response ) {
230
+	public function handle_response(EE_Request $request, EE_Response $response) {
231 231
 		//\EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 );
232 232
 		//EEH_Debug_Tools::printr( $request, '$request', __FILE__, __LINE__ );
233 233
 		//EEH_Debug_Tools::printr( $response, '$response', __FILE__, __LINE__ );
234 234
 		//die();
235
-		if ( $response->plugin_deactivated() ) {
236
-			espresso_deactivate_plugin( EE_PLUGIN_BASENAME );
235
+		if ($response->plugin_deactivated()) {
236
+			espresso_deactivate_plugin(EE_PLUGIN_BASENAME);
237 237
 		}
238 238
 	}
239 239
 
Please login to merge, or discard this patch.