@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | { |
24 | 24 | global $wpdb; |
25 | 25 | $this->_pretty_name = esc_html__('State - System Question', 'event_espresso'); |
26 | - $this->_old_table = $wpdb->prefix . 'esp_question'; |
|
26 | + $this->_old_table = $wpdb->prefix.'esp_question'; |
|
27 | 27 | $this->_extra_where_sql = "WHERE QST_system = 'state'"; |
28 | 28 | parent::__construct(); |
29 | 29 | } |
@@ -41,12 +41,12 @@ discard block |
||
41 | 41 | global $wpdb; |
42 | 42 | $success = $wpdb->update( |
43 | 43 | $this->_old_table, |
44 | - array( 'QST_type' => 'STATE' ), // data |
|
45 | - array( 'QST_ID' => $question['QST_ID'] ), // where |
|
46 | - array( '%s' ), // data format |
|
47 | - array( '%d' ) // where format |
|
44 | + array('QST_type' => 'STATE'), // data |
|
45 | + array('QST_ID' => $question['QST_ID']), // where |
|
46 | + array('%s'), // data format |
|
47 | + array('%d') // where format |
|
48 | 48 | ); |
49 | - if (! $success) { |
|
49 | + if ( ! $success) { |
|
50 | 50 | $this->add_error( |
51 | 51 | sprintf( |
52 | 52 | esc_html__('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'), |
@@ -11,48 +11,48 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_DMS_4_6_0_state_system_question extends EE_Data_Migration_Script_Stage_Table |
13 | 13 | { |
14 | - /** |
|
15 | - * Just initializes the status of the migration |
|
16 | - * |
|
17 | - * @return EE_DMS_4_6_0_state_system_question |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - global $wpdb; |
|
22 | - $this->_pretty_name = esc_html__('State - System Question', 'event_espresso'); |
|
23 | - $this->_old_table = $wpdb->prefix . 'esp_question'; |
|
24 | - $this->_extra_where_sql = "WHERE QST_system = 'state'"; |
|
25 | - parent::__construct(); |
|
26 | - } |
|
14 | + /** |
|
15 | + * Just initializes the status of the migration |
|
16 | + * |
|
17 | + * @return EE_DMS_4_6_0_state_system_question |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + global $wpdb; |
|
22 | + $this->_pretty_name = esc_html__('State - System Question', 'event_espresso'); |
|
23 | + $this->_old_table = $wpdb->prefix . 'esp_question'; |
|
24 | + $this->_extra_where_sql = "WHERE QST_system = 'state'"; |
|
25 | + parent::__construct(); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * updates the question with the new question type |
|
32 | - * @param array $question an associative array where keys are column names and values are their values. |
|
33 | - * @return null |
|
34 | - */ |
|
35 | - protected function _migrate_old_row($question) |
|
36 | - { |
|
37 | - if ($question['QST_ID'] && $question['QST_system'] == 'state') { |
|
38 | - global $wpdb; |
|
39 | - $success = $wpdb->update( |
|
40 | - $this->_old_table, |
|
41 | - array( 'QST_type' => 'STATE' ), // data |
|
42 | - array( 'QST_ID' => $question['QST_ID'] ), // where |
|
43 | - array( '%s' ), // data format |
|
44 | - array( '%d' ) // where format |
|
45 | - ); |
|
46 | - if (! $success) { |
|
47 | - $this->add_error( |
|
48 | - sprintf( |
|
49 | - esc_html__('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'), |
|
50 | - wp_json_encode($question['QST_system']), |
|
51 | - $question['QST_ID'], |
|
52 | - $wpdb->last_error |
|
53 | - ) |
|
54 | - ); |
|
55 | - } |
|
56 | - } |
|
57 | - } |
|
30 | + /** |
|
31 | + * updates the question with the new question type |
|
32 | + * @param array $question an associative array where keys are column names and values are their values. |
|
33 | + * @return null |
|
34 | + */ |
|
35 | + protected function _migrate_old_row($question) |
|
36 | + { |
|
37 | + if ($question['QST_ID'] && $question['QST_system'] == 'state') { |
|
38 | + global $wpdb; |
|
39 | + $success = $wpdb->update( |
|
40 | + $this->_old_table, |
|
41 | + array( 'QST_type' => 'STATE' ), // data |
|
42 | + array( 'QST_ID' => $question['QST_ID'] ), // where |
|
43 | + array( '%s' ), // data format |
|
44 | + array( '%d' ) // where format |
|
45 | + ); |
|
46 | + if (! $success) { |
|
47 | + $this->add_error( |
|
48 | + sprintf( |
|
49 | + esc_html__('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'), |
|
50 | + wp_json_encode($question['QST_system']), |
|
51 | + $question['QST_ID'], |
|
52 | + $wpdb->last_error |
|
53 | + ) |
|
54 | + ); |
|
55 | + } |
|
56 | + } |
|
57 | + } |
|
58 | 58 | } |
@@ -11,44 +11,44 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class EE_DMS_4_6_0_payments extends EE_Data_Migration_Script_Stage_Table |
13 | 13 | { |
14 | - protected $_payment_method_table; |
|
15 | - public function __construct() |
|
16 | - { |
|
17 | - global $wpdb; |
|
18 | - $this->_old_table = $wpdb->prefix . 'esp_payment'; |
|
19 | - $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method'; |
|
20 | - $this->_pretty_name = esc_html__('Payment-Payment Method Relations', 'event_espresso'); |
|
21 | - parent::__construct(); |
|
22 | - } |
|
23 | - protected function _migrate_old_row($payment_row) |
|
24 | - { |
|
25 | - global $wpdb; |
|
26 | - // get the payment method's ID |
|
27 | - $PMD_ID = apply_filters('FHEE__EE_DMS_4_6_0_payments__migrate_old_row__PMD_ID', $this->_get_payment_method_id_by_gateway_name($payment_row['PAY_gateway'], $payment_row['PAY_method'])); |
|
28 | - if (! $PMD_ID) { |
|
29 | - $this->add_error(sprintf(esc_html__('Could not find payment method with PMD_type = \'%1$s\' when migrating payment row %2$s so just assigned it an unknown payment method', 'event_espresso'), $payment_row['PAY_gateway'], $this->_json_encode($payment_row))); |
|
30 | - $PMD_ID = 0; |
|
31 | - } |
|
32 | - $new_values = array( |
|
33 | - 'PMD_ID' => $PMD_ID, |
|
34 | - 'PAY_source' => ( $payment_row['PAY_via_admin'] ? 'ADMIN' : 'CART' ) ); |
|
35 | - $wheres = array( 'PAY_ID' => $payment_row['PAY_ID'] ); |
|
36 | - $new_value_datatypes = array( '%d', '%s' ); |
|
37 | - $where_datatypes = array( '%d' ); |
|
38 | - $success = $wpdb->update( |
|
39 | - $this->_old_table, |
|
40 | - $new_values, |
|
41 | - $wheres, |
|
42 | - $new_value_datatypes, |
|
43 | - $where_datatypes |
|
44 | - ); |
|
45 | - if (! $success) { |
|
46 | - $this->add_error(sprintf(esc_html__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_old_table, $this->_json_encode($wheres))); |
|
47 | - } |
|
48 | - } |
|
49 | - /** |
|
50 | - * |
|
51 | - * array( |
|
14 | + protected $_payment_method_table; |
|
15 | + public function __construct() |
|
16 | + { |
|
17 | + global $wpdb; |
|
18 | + $this->_old_table = $wpdb->prefix . 'esp_payment'; |
|
19 | + $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method'; |
|
20 | + $this->_pretty_name = esc_html__('Payment-Payment Method Relations', 'event_espresso'); |
|
21 | + parent::__construct(); |
|
22 | + } |
|
23 | + protected function _migrate_old_row($payment_row) |
|
24 | + { |
|
25 | + global $wpdb; |
|
26 | + // get the payment method's ID |
|
27 | + $PMD_ID = apply_filters('FHEE__EE_DMS_4_6_0_payments__migrate_old_row__PMD_ID', $this->_get_payment_method_id_by_gateway_name($payment_row['PAY_gateway'], $payment_row['PAY_method'])); |
|
28 | + if (! $PMD_ID) { |
|
29 | + $this->add_error(sprintf(esc_html__('Could not find payment method with PMD_type = \'%1$s\' when migrating payment row %2$s so just assigned it an unknown payment method', 'event_espresso'), $payment_row['PAY_gateway'], $this->_json_encode($payment_row))); |
|
30 | + $PMD_ID = 0; |
|
31 | + } |
|
32 | + $new_values = array( |
|
33 | + 'PMD_ID' => $PMD_ID, |
|
34 | + 'PAY_source' => ( $payment_row['PAY_via_admin'] ? 'ADMIN' : 'CART' ) ); |
|
35 | + $wheres = array( 'PAY_ID' => $payment_row['PAY_ID'] ); |
|
36 | + $new_value_datatypes = array( '%d', '%s' ); |
|
37 | + $where_datatypes = array( '%d' ); |
|
38 | + $success = $wpdb->update( |
|
39 | + $this->_old_table, |
|
40 | + $new_values, |
|
41 | + $wheres, |
|
42 | + $new_value_datatypes, |
|
43 | + $where_datatypes |
|
44 | + ); |
|
45 | + if (! $success) { |
|
46 | + $this->add_error(sprintf(esc_html__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_old_table, $this->_json_encode($wheres))); |
|
47 | + } |
|
48 | + } |
|
49 | + /** |
|
50 | + * |
|
51 | + * array( |
|
52 | 52 | 'PP' => esc_html__( 'PayPal', 'event_espresso' ), |
53 | 53 | 'CC' => esc_html__( 'Credit Card', 'event_espresso' ), |
54 | 54 | 'DB'=> esc_html__("Debit Card", 'event_espresso'), |
@@ -57,44 +57,44 @@ discard block |
||
57 | 57 | 'BK'=> esc_html__("Bank", 'event_espresso'), |
58 | 58 | 'IV'=> esc_html__("Invoice", 'event_espresso'), |
59 | 59 | 'MO'=> esc_html__("Money Order", 'event_espresso'), |
60 | - * @global type $wpdb |
|
61 | - * @param int $id |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - protected function _get_payment_method_id_by_gateway_name($gateway_name, $old_pay_method_column) |
|
65 | - { |
|
66 | - global $wpdb; |
|
67 | - // convert from old known PAY_method values to their corresponding |
|
68 | - // PMD_type or default PMD_name |
|
69 | - switch ($old_pay_method_column) { |
|
70 | - case 'PP': |
|
71 | - $pmd_type = 'Paypal_Standard'; |
|
72 | - break; |
|
73 | - case 'CC': |
|
74 | - $pmd_type = 'Credit_Card'; |
|
75 | - break; |
|
76 | - case 'DB': |
|
77 | - $pmd_type = 'Debit_Card'; |
|
78 | - break; |
|
79 | - case 'CHQ': |
|
80 | - $pmd_type = 'Check'; |
|
81 | - break; |
|
82 | - case 'CSH': |
|
83 | - $pmd_type = 'Cash'; |
|
84 | - break; |
|
85 | - case 'BK': |
|
86 | - $pmd_type = 'Bank'; |
|
87 | - break; |
|
88 | - case 'IV': |
|
89 | - $pmd_type = 'Invoice'; |
|
90 | - break; |
|
91 | - case 'MO': |
|
92 | - $pmd_type = 'Money_Order'; |
|
93 | - break; |
|
94 | - default: |
|
95 | - $pmd_type = $gateway_name; |
|
96 | - } |
|
97 | - $pmd_name = str_replace("_", " ", $pmd_type); |
|
98 | - return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s OR PMD_name = %s", $pmd_type, $pmd_name)); |
|
99 | - } |
|
60 | + * @global type $wpdb |
|
61 | + * @param int $id |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + protected function _get_payment_method_id_by_gateway_name($gateway_name, $old_pay_method_column) |
|
65 | + { |
|
66 | + global $wpdb; |
|
67 | + // convert from old known PAY_method values to their corresponding |
|
68 | + // PMD_type or default PMD_name |
|
69 | + switch ($old_pay_method_column) { |
|
70 | + case 'PP': |
|
71 | + $pmd_type = 'Paypal_Standard'; |
|
72 | + break; |
|
73 | + case 'CC': |
|
74 | + $pmd_type = 'Credit_Card'; |
|
75 | + break; |
|
76 | + case 'DB': |
|
77 | + $pmd_type = 'Debit_Card'; |
|
78 | + break; |
|
79 | + case 'CHQ': |
|
80 | + $pmd_type = 'Check'; |
|
81 | + break; |
|
82 | + case 'CSH': |
|
83 | + $pmd_type = 'Cash'; |
|
84 | + break; |
|
85 | + case 'BK': |
|
86 | + $pmd_type = 'Bank'; |
|
87 | + break; |
|
88 | + case 'IV': |
|
89 | + $pmd_type = 'Invoice'; |
|
90 | + break; |
|
91 | + case 'MO': |
|
92 | + $pmd_type = 'Money_Order'; |
|
93 | + break; |
|
94 | + default: |
|
95 | + $pmd_type = $gateway_name; |
|
96 | + } |
|
97 | + $pmd_name = str_replace("_", " ", $pmd_type); |
|
98 | + return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s OR PMD_name = %s", $pmd_type, $pmd_name)); |
|
99 | + } |
|
100 | 100 | } |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | public function __construct() |
16 | 16 | { |
17 | 17 | global $wpdb; |
18 | - $this->_old_table = $wpdb->prefix . 'esp_payment'; |
|
19 | - $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method'; |
|
18 | + $this->_old_table = $wpdb->prefix.'esp_payment'; |
|
19 | + $this->_payment_method_table = $wpdb->prefix.'esp_payment_method'; |
|
20 | 20 | $this->_pretty_name = esc_html__('Payment-Payment Method Relations', 'event_espresso'); |
21 | 21 | parent::__construct(); |
22 | 22 | } |
@@ -25,16 +25,16 @@ discard block |
||
25 | 25 | global $wpdb; |
26 | 26 | // get the payment method's ID |
27 | 27 | $PMD_ID = apply_filters('FHEE__EE_DMS_4_6_0_payments__migrate_old_row__PMD_ID', $this->_get_payment_method_id_by_gateway_name($payment_row['PAY_gateway'], $payment_row['PAY_method'])); |
28 | - if (! $PMD_ID) { |
|
28 | + if ( ! $PMD_ID) { |
|
29 | 29 | $this->add_error(sprintf(esc_html__('Could not find payment method with PMD_type = \'%1$s\' when migrating payment row %2$s so just assigned it an unknown payment method', 'event_espresso'), $payment_row['PAY_gateway'], $this->_json_encode($payment_row))); |
30 | 30 | $PMD_ID = 0; |
31 | 31 | } |
32 | 32 | $new_values = array( |
33 | 33 | 'PMD_ID' => $PMD_ID, |
34 | - 'PAY_source' => ( $payment_row['PAY_via_admin'] ? 'ADMIN' : 'CART' ) ); |
|
35 | - $wheres = array( 'PAY_ID' => $payment_row['PAY_ID'] ); |
|
36 | - $new_value_datatypes = array( '%d', '%s' ); |
|
37 | - $where_datatypes = array( '%d' ); |
|
34 | + 'PAY_source' => ($payment_row['PAY_via_admin'] ? 'ADMIN' : 'CART') ); |
|
35 | + $wheres = array('PAY_ID' => $payment_row['PAY_ID']); |
|
36 | + $new_value_datatypes = array('%d', '%s'); |
|
37 | + $where_datatypes = array('%d'); |
|
38 | 38 | $success = $wpdb->update( |
39 | 39 | $this->_old_table, |
40 | 40 | $new_values, |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $new_value_datatypes, |
43 | 43 | $where_datatypes |
44 | 44 | ); |
45 | - if (! $success) { |
|
45 | + if ( ! $success) { |
|
46 | 46 | $this->add_error(sprintf(esc_html__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_old_table, $this->_json_encode($wheres))); |
47 | 47 | } |
48 | 48 | } |
@@ -95,6 +95,6 @@ discard block |
||
95 | 95 | $pmd_type = $gateway_name; |
96 | 96 | } |
97 | 97 | $pmd_name = str_replace("_", " ", $pmd_type); |
98 | - return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s OR PMD_name = %s", $pmd_type, $pmd_name)); |
|
98 | + return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM ".$wpdb->prefix."esp_payment_method WHERE PMD_type = %s OR PMD_name = %s", $pmd_type, $pmd_name)); |
|
99 | 99 | } |
100 | 100 | } |
@@ -11,51 +11,51 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_DMS_4_6_0_transactions extends EE_Data_Migration_Script_Stage_Table |
13 | 13 | { |
14 | - protected $_transaction_table; |
|
15 | - protected $_payment_method_table; |
|
16 | - public function __construct() |
|
17 | - { |
|
18 | - global $wpdb; |
|
19 | - $this->_old_table = $wpdb->prefix . 'esp_extra_meta'; |
|
20 | - $this->_transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
21 | - $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method'; |
|
22 | - $this->_pretty_name = esc_html__('Transaction Payment Method Relations', 'event_espresso'); |
|
23 | - $this->_extra_where_sql = "WHERE EXM_key = 'gateway' AND EXM_type = 'Transaction'"; |
|
24 | - parent::__construct(); |
|
25 | - } |
|
26 | - protected function _migrate_old_row($extra_meta_row) |
|
27 | - { |
|
28 | - global $wpdb; |
|
29 | - // get the payment method's ID |
|
30 | - $PMD_ID = $this->_get_payment_method_id_by_gateway_name($extra_meta_row['EXM_value']); |
|
31 | - if (! $PMD_ID) { |
|
32 | - $this->add_error(sprintf(esc_html__('Could not find payment method with PMD_type = \'%1$s\' when migrating extra meta row %2$s', 'event_espresso'), $extra_meta_row['EXM_value'], $this->_json_encode($extra_meta_row))); |
|
33 | - return; |
|
34 | - } |
|
35 | - $new_values = array( 'PMD_ID' => $PMD_ID ); |
|
36 | - $wheres = array( 'TXN_ID' => $extra_meta_row['OBJ_ID'] ); |
|
37 | - $new_value_datatypes = array( '%d' ); |
|
38 | - $where_datatypes = array( '%d' ); |
|
39 | - $success = $wpdb->update( |
|
40 | - $this->_transaction_table, |
|
41 | - $new_values, |
|
42 | - $wheres, |
|
43 | - $new_value_datatypes, |
|
44 | - $where_datatypes |
|
45 | - ); |
|
46 | - if (! $success) { |
|
47 | - $this->add_error(sprintf(esc_html__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_transaction_table, $this->_json_encode($wheres))); |
|
48 | - } |
|
49 | - } |
|
50 | - /** |
|
51 | - * |
|
52 | - * @global type $wpdb |
|
53 | - * @param int $id |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - protected function _get_payment_method_id_by_gateway_name($gateway_name) |
|
57 | - { |
|
58 | - global $wpdb; |
|
59 | - return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s", $gateway_name)); |
|
60 | - } |
|
14 | + protected $_transaction_table; |
|
15 | + protected $_payment_method_table; |
|
16 | + public function __construct() |
|
17 | + { |
|
18 | + global $wpdb; |
|
19 | + $this->_old_table = $wpdb->prefix . 'esp_extra_meta'; |
|
20 | + $this->_transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
21 | + $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method'; |
|
22 | + $this->_pretty_name = esc_html__('Transaction Payment Method Relations', 'event_espresso'); |
|
23 | + $this->_extra_where_sql = "WHERE EXM_key = 'gateway' AND EXM_type = 'Transaction'"; |
|
24 | + parent::__construct(); |
|
25 | + } |
|
26 | + protected function _migrate_old_row($extra_meta_row) |
|
27 | + { |
|
28 | + global $wpdb; |
|
29 | + // get the payment method's ID |
|
30 | + $PMD_ID = $this->_get_payment_method_id_by_gateway_name($extra_meta_row['EXM_value']); |
|
31 | + if (! $PMD_ID) { |
|
32 | + $this->add_error(sprintf(esc_html__('Could not find payment method with PMD_type = \'%1$s\' when migrating extra meta row %2$s', 'event_espresso'), $extra_meta_row['EXM_value'], $this->_json_encode($extra_meta_row))); |
|
33 | + return; |
|
34 | + } |
|
35 | + $new_values = array( 'PMD_ID' => $PMD_ID ); |
|
36 | + $wheres = array( 'TXN_ID' => $extra_meta_row['OBJ_ID'] ); |
|
37 | + $new_value_datatypes = array( '%d' ); |
|
38 | + $where_datatypes = array( '%d' ); |
|
39 | + $success = $wpdb->update( |
|
40 | + $this->_transaction_table, |
|
41 | + $new_values, |
|
42 | + $wheres, |
|
43 | + $new_value_datatypes, |
|
44 | + $where_datatypes |
|
45 | + ); |
|
46 | + if (! $success) { |
|
47 | + $this->add_error(sprintf(esc_html__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_transaction_table, $this->_json_encode($wheres))); |
|
48 | + } |
|
49 | + } |
|
50 | + /** |
|
51 | + * |
|
52 | + * @global type $wpdb |
|
53 | + * @param int $id |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + protected function _get_payment_method_id_by_gateway_name($gateway_name) |
|
57 | + { |
|
58 | + global $wpdb; |
|
59 | + return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s", $gateway_name)); |
|
60 | + } |
|
61 | 61 | } |
@@ -16,9 +16,9 @@ discard block |
||
16 | 16 | public function __construct() |
17 | 17 | { |
18 | 18 | global $wpdb; |
19 | - $this->_old_table = $wpdb->prefix . 'esp_extra_meta'; |
|
20 | - $this->_transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
21 | - $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method'; |
|
19 | + $this->_old_table = $wpdb->prefix.'esp_extra_meta'; |
|
20 | + $this->_transaction_table = $wpdb->prefix.'esp_transaction'; |
|
21 | + $this->_payment_method_table = $wpdb->prefix.'esp_payment_method'; |
|
22 | 22 | $this->_pretty_name = esc_html__('Transaction Payment Method Relations', 'event_espresso'); |
23 | 23 | $this->_extra_where_sql = "WHERE EXM_key = 'gateway' AND EXM_type = 'Transaction'"; |
24 | 24 | parent::__construct(); |
@@ -28,14 +28,14 @@ discard block |
||
28 | 28 | global $wpdb; |
29 | 29 | // get the payment method's ID |
30 | 30 | $PMD_ID = $this->_get_payment_method_id_by_gateway_name($extra_meta_row['EXM_value']); |
31 | - if (! $PMD_ID) { |
|
31 | + if ( ! $PMD_ID) { |
|
32 | 32 | $this->add_error(sprintf(esc_html__('Could not find payment method with PMD_type = \'%1$s\' when migrating extra meta row %2$s', 'event_espresso'), $extra_meta_row['EXM_value'], $this->_json_encode($extra_meta_row))); |
33 | 33 | return; |
34 | 34 | } |
35 | - $new_values = array( 'PMD_ID' => $PMD_ID ); |
|
36 | - $wheres = array( 'TXN_ID' => $extra_meta_row['OBJ_ID'] ); |
|
37 | - $new_value_datatypes = array( '%d' ); |
|
38 | - $where_datatypes = array( '%d' ); |
|
35 | + $new_values = array('PMD_ID' => $PMD_ID); |
|
36 | + $wheres = array('TXN_ID' => $extra_meta_row['OBJ_ID']); |
|
37 | + $new_value_datatypes = array('%d'); |
|
38 | + $where_datatypes = array('%d'); |
|
39 | 39 | $success = $wpdb->update( |
40 | 40 | $this->_transaction_table, |
41 | 41 | $new_values, |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $new_value_datatypes, |
44 | 44 | $where_datatypes |
45 | 45 | ); |
46 | - if (! $success) { |
|
46 | + if ( ! $success) { |
|
47 | 47 | $this->add_error(sprintf(esc_html__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_transaction_table, $this->_json_encode($wheres))); |
48 | 48 | } |
49 | 49 | } |
@@ -56,6 +56,6 @@ discard block |
||
56 | 56 | protected function _get_payment_method_id_by_gateway_name($gateway_name) |
57 | 57 | { |
58 | 58 | global $wpdb; |
59 | - return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s", $gateway_name)); |
|
59 | + return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM ".$wpdb->prefix."esp_payment_method WHERE PMD_type = %s", $gateway_name)); |
|
60 | 60 | } |
61 | 61 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | { |
24 | 24 | global $wpdb; |
25 | 25 | $this->_pretty_name = esc_html__('Country - System Question', 'event_espresso'); |
26 | - $this->_old_table = $wpdb->prefix . 'esp_question'; |
|
26 | + $this->_old_table = $wpdb->prefix.'esp_question'; |
|
27 | 27 | $this->_extra_where_sql = "WHERE QST_system = 'country'"; |
28 | 28 | parent::__construct(); |
29 | 29 | } |
@@ -41,12 +41,12 @@ discard block |
||
41 | 41 | global $wpdb; |
42 | 42 | $success = $wpdb->update( |
43 | 43 | $this->_old_table, |
44 | - array( 'QST_type' => 'COUNTRY' ), // data |
|
45 | - array( 'QST_ID' => $question['QST_ID'] ), // where |
|
46 | - array( '%s' ), // data format |
|
47 | - array( '%d' ) // where format |
|
44 | + array('QST_type' => 'COUNTRY'), // data |
|
45 | + array('QST_ID' => $question['QST_ID']), // where |
|
46 | + array('%s'), // data format |
|
47 | + array('%d') // where format |
|
48 | 48 | ); |
49 | - if (! $success) { |
|
49 | + if ( ! $success) { |
|
50 | 50 | $this->add_error( |
51 | 51 | sprintf( |
52 | 52 | esc_html__('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'), |
@@ -11,48 +11,48 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_DMS_4_6_0_country_system_question extends EE_Data_Migration_Script_Stage_Table |
13 | 13 | { |
14 | - /** |
|
15 | - * Just initializes the status of the migration |
|
16 | - * |
|
17 | - * @return EE_DMS_4_6_0_country_system_question |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - global $wpdb; |
|
22 | - $this->_pretty_name = esc_html__('Country - System Question', 'event_espresso'); |
|
23 | - $this->_old_table = $wpdb->prefix . 'esp_question'; |
|
24 | - $this->_extra_where_sql = "WHERE QST_system = 'country'"; |
|
25 | - parent::__construct(); |
|
26 | - } |
|
14 | + /** |
|
15 | + * Just initializes the status of the migration |
|
16 | + * |
|
17 | + * @return EE_DMS_4_6_0_country_system_question |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + global $wpdb; |
|
22 | + $this->_pretty_name = esc_html__('Country - System Question', 'event_espresso'); |
|
23 | + $this->_old_table = $wpdb->prefix . 'esp_question'; |
|
24 | + $this->_extra_where_sql = "WHERE QST_system = 'country'"; |
|
25 | + parent::__construct(); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * updates the question with the new question type |
|
32 | - * @param array $question an associative array where keys are column names and values are their values. |
|
33 | - * @return null |
|
34 | - */ |
|
35 | - protected function _migrate_old_row($question) |
|
36 | - { |
|
37 | - if ($question['QST_ID'] && $question['QST_system'] == 'country') { |
|
38 | - global $wpdb; |
|
39 | - $success = $wpdb->update( |
|
40 | - $this->_old_table, |
|
41 | - array( 'QST_type' => 'COUNTRY' ), // data |
|
42 | - array( 'QST_ID' => $question['QST_ID'] ), // where |
|
43 | - array( '%s' ), // data format |
|
44 | - array( '%d' ) // where format |
|
45 | - ); |
|
46 | - if (! $success) { |
|
47 | - $this->add_error( |
|
48 | - sprintf( |
|
49 | - esc_html__('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'), |
|
50 | - wp_json_encode($question['QST_system']), |
|
51 | - $question['QST_ID'], |
|
52 | - $wpdb->last_error |
|
53 | - ) |
|
54 | - ); |
|
55 | - } |
|
56 | - } |
|
57 | - } |
|
30 | + /** |
|
31 | + * updates the question with the new question type |
|
32 | + * @param array $question an associative array where keys are column names and values are their values. |
|
33 | + * @return null |
|
34 | + */ |
|
35 | + protected function _migrate_old_row($question) |
|
36 | + { |
|
37 | + if ($question['QST_ID'] && $question['QST_system'] == 'country') { |
|
38 | + global $wpdb; |
|
39 | + $success = $wpdb->update( |
|
40 | + $this->_old_table, |
|
41 | + array( 'QST_type' => 'COUNTRY' ), // data |
|
42 | + array( 'QST_ID' => $question['QST_ID'] ), // where |
|
43 | + array( '%s' ), // data format |
|
44 | + array( '%d' ) // where format |
|
45 | + ); |
|
46 | + if (! $success) { |
|
47 | + $this->add_error( |
|
48 | + sprintf( |
|
49 | + esc_html__('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'), |
|
50 | + wp_json_encode($question['QST_system']), |
|
51 | + $question['QST_ID'], |
|
52 | + $wpdb->last_error |
|
53 | + ) |
|
54 | + ); |
|
55 | + } |
|
56 | + } |
|
57 | + } |
|
58 | 58 | } |
@@ -54,11 +54,11 @@ discard block |
||
54 | 54 | protected function _migration_step($num_items = 1) |
55 | 55 | { |
56 | 56 | // if this isn't set then something is really wrong |
57 | - if (! EE_Config::instance()->gateway instanceof EE_Gateway_Config) { |
|
57 | + if ( ! EE_Config::instance()->gateway instanceof EE_Gateway_Config) { |
|
58 | 58 | throw new EE_Error(esc_html__('It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso')); |
59 | 59 | } |
60 | 60 | $invoice_settings = isset(EE_Config::instance()->gateway->payment_settings['Invoice']) ? EE_Config::instance()->gateway->payment_settings['Invoice'] : null; |
61 | - if (! $invoice_settings) { |
|
61 | + if ( ! $invoice_settings) { |
|
62 | 62 | $this->add_error(esc_html__('Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso')); |
63 | 63 | } else { |
64 | 64 | $invoice_settings['template_payment_instructions'] = $invoice_settings['pdf_instructions']; |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | ); |
94 | 94 | } |
95 | 95 | $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
96 | - $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true); |
|
97 | - $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true); |
|
96 | + $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path.'invoice_body.template.php', null, false, false, true); |
|
97 | + $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path.'receipt_body.template.php', null, false, false, true); |
|
98 | 98 | if ($overridden_invoice_body || $overridden_receipt_body) { |
99 | 99 | new PersistentAdminNotice( |
100 | 100 | 'invoice_overriding_templates', |
@@ -16,97 +16,97 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_DMS_4_5_0_invoice_settings extends EE_Data_Migration_Script_Stage |
18 | 18 | { |
19 | - /** |
|
20 | - * Just initializes the status of the migration |
|
21 | - */ |
|
22 | - public function __construct() |
|
23 | - { |
|
24 | - $this->_pretty_name = esc_html__('Update Invoice Gateway Settings', 'event_espresso'); |
|
25 | - parent::__construct(); |
|
26 | - } |
|
19 | + /** |
|
20 | + * Just initializes the status of the migration |
|
21 | + */ |
|
22 | + public function __construct() |
|
23 | + { |
|
24 | + $this->_pretty_name = esc_html__('Update Invoice Gateway Settings', 'event_espresso'); |
|
25 | + parent::__construct(); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * _count_records_to_migrate |
|
32 | - * Counts the records to migrate; the public version may cache it |
|
33 | - * |
|
34 | - * @access protected |
|
35 | - * @return int |
|
36 | - */ |
|
37 | - protected function _count_records_to_migrate() |
|
38 | - { |
|
39 | - return 1; |
|
40 | - } |
|
30 | + /** |
|
31 | + * _count_records_to_migrate |
|
32 | + * Counts the records to migrate; the public version may cache it |
|
33 | + * |
|
34 | + * @access protected |
|
35 | + * @return int |
|
36 | + */ |
|
37 | + protected function _count_records_to_migrate() |
|
38 | + { |
|
39 | + return 1; |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * _migration_step |
|
46 | - * |
|
47 | - * @access protected |
|
48 | - * @param int $num_items |
|
49 | - * @throws EE_Error |
|
50 | - * @return int number of items ACTUALLY migrated |
|
51 | - * @throws InvalidDataTypeException |
|
52 | - */ |
|
53 | - protected function _migration_step($num_items = 1) |
|
54 | - { |
|
55 | - // if this isn't set then something is really wrong |
|
56 | - if (! EE_Config::instance()->gateway instanceof EE_Gateway_Config) { |
|
57 | - throw new EE_Error(esc_html__('It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso')); |
|
58 | - } |
|
59 | - $invoice_settings = isset(EE_Config::instance()->gateway->payment_settings['Invoice']) ? EE_Config::instance()->gateway->payment_settings['Invoice'] : null; |
|
60 | - if (! $invoice_settings) { |
|
61 | - $this->add_error(esc_html__('Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso')); |
|
62 | - } else { |
|
63 | - $invoice_settings['template_payment_instructions'] = $invoice_settings['pdf_instructions']; |
|
64 | - $invoice_settings['template_invoice_payee_name'] = $invoice_settings['payable_to']; |
|
65 | - $invoice_settings['template_invoice_address'] = $invoice_settings['payment_address']; |
|
66 | - $invoice_settings['template_invoice_email'] = ''; |
|
67 | - $invoice_settings['template_invoice_tax_number'] = ''; |
|
68 | - unset($invoice_settings['pdf_instructions']); |
|
69 | - unset($invoice_settings['payable_to']); |
|
70 | - unset($invoice_settings['payment_address']); |
|
71 | - EE_Config::instance()->gateway->payment_settings['Invoice'] = $invoice_settings; |
|
72 | - EE_Config::instance()->update_espresso_config(false, false); |
|
44 | + /** |
|
45 | + * _migration_step |
|
46 | + * |
|
47 | + * @access protected |
|
48 | + * @param int $num_items |
|
49 | + * @throws EE_Error |
|
50 | + * @return int number of items ACTUALLY migrated |
|
51 | + * @throws InvalidDataTypeException |
|
52 | + */ |
|
53 | + protected function _migration_step($num_items = 1) |
|
54 | + { |
|
55 | + // if this isn't set then something is really wrong |
|
56 | + if (! EE_Config::instance()->gateway instanceof EE_Gateway_Config) { |
|
57 | + throw new EE_Error(esc_html__('It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso')); |
|
58 | + } |
|
59 | + $invoice_settings = isset(EE_Config::instance()->gateway->payment_settings['Invoice']) ? EE_Config::instance()->gateway->payment_settings['Invoice'] : null; |
|
60 | + if (! $invoice_settings) { |
|
61 | + $this->add_error(esc_html__('Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso')); |
|
62 | + } else { |
|
63 | + $invoice_settings['template_payment_instructions'] = $invoice_settings['pdf_instructions']; |
|
64 | + $invoice_settings['template_invoice_payee_name'] = $invoice_settings['payable_to']; |
|
65 | + $invoice_settings['template_invoice_address'] = $invoice_settings['payment_address']; |
|
66 | + $invoice_settings['template_invoice_email'] = ''; |
|
67 | + $invoice_settings['template_invoice_tax_number'] = ''; |
|
68 | + unset($invoice_settings['pdf_instructions']); |
|
69 | + unset($invoice_settings['payable_to']); |
|
70 | + unset($invoice_settings['payment_address']); |
|
71 | + EE_Config::instance()->gateway->payment_settings['Invoice'] = $invoice_settings; |
|
72 | + EE_Config::instance()->update_espresso_config(false, false); |
|
73 | 73 | |
74 | - // @todo: check 'invoice_css' too because we can't easily affect that so we might need to set a persistent notice |
|
75 | - // (why is it tough to change? because we want to update the receipt and invoice message template, but |
|
76 | - // message templates are only initialized AFTER migrations and those two are new in 4.5. So if we wanted to |
|
77 | - // update them from a DMS, we'd need to have the DMS create the message templates which is quite a lot of code; |
|
78 | - // also we don't want to build a dependency on the messages code because it is likely to change soon |
|
79 | - if ( |
|
80 | - isset($invoice_settings['invoice_css']) |
|
81 | - && ! in_array($invoice_settings['invoice_css'], ['', 'simple.css']) |
|
82 | - ) { |
|
83 | - new PersistentAdminNotice( |
|
84 | - 'invoice_css_not_updated', |
|
85 | - sprintf( |
|
86 | - esc_html__( |
|
87 | - 'You had previously set your Invoice Payment Method\'s stylesheet to be %1$s, but that setting has moved. PDF and HTML Invoices and Receipts are now Messages, which means you can easily modify them from your Wordpress Dashboard instead of using filters or uploading template files. Please visit Messages -> Receipt and Messages -> Invoice to change their stylesheets.', |
|
88 | - 'event_espresso' |
|
89 | - ), |
|
90 | - $invoice_settings['invoice_css'] |
|
91 | - ) |
|
92 | - ); |
|
93 | - } |
|
94 | - $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
|
95 | - $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true); |
|
96 | - $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true); |
|
97 | - if ($overridden_invoice_body || $overridden_receipt_body) { |
|
98 | - new PersistentAdminNotice( |
|
99 | - 'invoice_overriding_templates', |
|
100 | - esc_html__( |
|
101 | - 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents. We recommend deleting your old Invoice/Receipt templates and modifying the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
102 | - 'event_espresso' |
|
103 | - ), |
|
104 | - true |
|
105 | - ); |
|
106 | - } |
|
107 | - } |
|
108 | - // regardless of whether it worked or not, we ought to continue the migration |
|
109 | - $this->set_completed(); |
|
110 | - return 1; |
|
111 | - } |
|
74 | + // @todo: check 'invoice_css' too because we can't easily affect that so we might need to set a persistent notice |
|
75 | + // (why is it tough to change? because we want to update the receipt and invoice message template, but |
|
76 | + // message templates are only initialized AFTER migrations and those two are new in 4.5. So if we wanted to |
|
77 | + // update them from a DMS, we'd need to have the DMS create the message templates which is quite a lot of code; |
|
78 | + // also we don't want to build a dependency on the messages code because it is likely to change soon |
|
79 | + if ( |
|
80 | + isset($invoice_settings['invoice_css']) |
|
81 | + && ! in_array($invoice_settings['invoice_css'], ['', 'simple.css']) |
|
82 | + ) { |
|
83 | + new PersistentAdminNotice( |
|
84 | + 'invoice_css_not_updated', |
|
85 | + sprintf( |
|
86 | + esc_html__( |
|
87 | + 'You had previously set your Invoice Payment Method\'s stylesheet to be %1$s, but that setting has moved. PDF and HTML Invoices and Receipts are now Messages, which means you can easily modify them from your Wordpress Dashboard instead of using filters or uploading template files. Please visit Messages -> Receipt and Messages -> Invoice to change their stylesheets.', |
|
88 | + 'event_espresso' |
|
89 | + ), |
|
90 | + $invoice_settings['invoice_css'] |
|
91 | + ) |
|
92 | + ); |
|
93 | + } |
|
94 | + $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
|
95 | + $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true); |
|
96 | + $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true); |
|
97 | + if ($overridden_invoice_body || $overridden_receipt_body) { |
|
98 | + new PersistentAdminNotice( |
|
99 | + 'invoice_overriding_templates', |
|
100 | + esc_html__( |
|
101 | + 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents. We recommend deleting your old Invoice/Receipt templates and modifying the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
102 | + 'event_espresso' |
|
103 | + ), |
|
104 | + true |
|
105 | + ); |
|
106 | + } |
|
107 | + } |
|
108 | + // regardless of whether it worked or not, we ought to continue the migration |
|
109 | + $this->set_completed(); |
|
110 | + return 1; |
|
111 | + } |
|
112 | 112 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | { |
24 | 24 | global $wpdb; |
25 | 25 | $this->_pretty_name = esc_html__('Email - System Question', 'event_espresso'); |
26 | - $this->_old_table = $wpdb->prefix . 'esp_question'; |
|
26 | + $this->_old_table = $wpdb->prefix.'esp_question'; |
|
27 | 27 | $this->_extra_where_sql = "WHERE QST_system = 'email'"; |
28 | 28 | parent::__construct(); |
29 | 29 | } |
@@ -41,12 +41,12 @@ discard block |
||
41 | 41 | global $wpdb; |
42 | 42 | $success = $wpdb->update( |
43 | 43 | $this->_old_table, |
44 | - array( 'QST_type' => 'EMAIL' ), // data |
|
45 | - array( 'QST_ID' => $question['QST_ID'] ), // where |
|
46 | - array( '%s' ), // data format |
|
47 | - array( '%d' ) // where format |
|
44 | + array('QST_type' => 'EMAIL'), // data |
|
45 | + array('QST_ID' => $question['QST_ID']), // where |
|
46 | + array('%s'), // data format |
|
47 | + array('%d') // where format |
|
48 | 48 | ); |
49 | - if (! $success) { |
|
49 | + if ( ! $success) { |
|
50 | 50 | $this->add_error( |
51 | 51 | sprintf( |
52 | 52 | esc_html__('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'), |
@@ -11,48 +11,48 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_DMS_4_9_0_Email_System_Question extends EE_Data_Migration_Script_Stage_Table |
13 | 13 | { |
14 | - /** |
|
15 | - * Just initializes the status of the migration |
|
16 | - * |
|
17 | - * @return EE_DMS_4_9_0_Email_System_Question |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - global $wpdb; |
|
22 | - $this->_pretty_name = esc_html__('Email - System Question', 'event_espresso'); |
|
23 | - $this->_old_table = $wpdb->prefix . 'esp_question'; |
|
24 | - $this->_extra_where_sql = "WHERE QST_system = 'email'"; |
|
25 | - parent::__construct(); |
|
26 | - } |
|
14 | + /** |
|
15 | + * Just initializes the status of the migration |
|
16 | + * |
|
17 | + * @return EE_DMS_4_9_0_Email_System_Question |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + global $wpdb; |
|
22 | + $this->_pretty_name = esc_html__('Email - System Question', 'event_espresso'); |
|
23 | + $this->_old_table = $wpdb->prefix . 'esp_question'; |
|
24 | + $this->_extra_where_sql = "WHERE QST_system = 'email'"; |
|
25 | + parent::__construct(); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * updates the question with the new question type |
|
32 | - * @param array $question an associative array where keys are column names and values are their values. |
|
33 | - * @return null |
|
34 | - */ |
|
35 | - protected function _migrate_old_row($question) |
|
36 | - { |
|
37 | - if ($question['QST_ID'] && $question['QST_system'] == 'email') { |
|
38 | - global $wpdb; |
|
39 | - $success = $wpdb->update( |
|
40 | - $this->_old_table, |
|
41 | - array( 'QST_type' => 'EMAIL' ), // data |
|
42 | - array( 'QST_ID' => $question['QST_ID'] ), // where |
|
43 | - array( '%s' ), // data format |
|
44 | - array( '%d' ) // where format |
|
45 | - ); |
|
46 | - if (! $success) { |
|
47 | - $this->add_error( |
|
48 | - sprintf( |
|
49 | - esc_html__('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'), |
|
50 | - wp_json_encode($question['QST_system']), |
|
51 | - $question['QST_ID'], |
|
52 | - $wpdb->last_error |
|
53 | - ) |
|
54 | - ); |
|
55 | - } |
|
56 | - } |
|
57 | - } |
|
30 | + /** |
|
31 | + * updates the question with the new question type |
|
32 | + * @param array $question an associative array where keys are column names and values are their values. |
|
33 | + * @return null |
|
34 | + */ |
|
35 | + protected function _migrate_old_row($question) |
|
36 | + { |
|
37 | + if ($question['QST_ID'] && $question['QST_system'] == 'email') { |
|
38 | + global $wpdb; |
|
39 | + $success = $wpdb->update( |
|
40 | + $this->_old_table, |
|
41 | + array( 'QST_type' => 'EMAIL' ), // data |
|
42 | + array( 'QST_ID' => $question['QST_ID'] ), // where |
|
43 | + array( '%s' ), // data format |
|
44 | + array( '%d' ) // where format |
|
45 | + ); |
|
46 | + if (! $success) { |
|
47 | + $this->add_error( |
|
48 | + sprintf( |
|
49 | + esc_html__('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'), |
|
50 | + wp_json_encode($question['QST_system']), |
|
51 | + $question['QST_ID'], |
|
52 | + $wpdb->last_error |
|
53 | + ) |
|
54 | + ); |
|
55 | + } |
|
56 | + } |
|
57 | + } |
|
58 | 58 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | */ |
43 | 43 | public function set_group_template_id($GRP_ID = false) |
44 | 44 | { |
45 | - if (! $GRP_ID) { |
|
45 | + if ( ! $GRP_ID) { |
|
46 | 46 | throw new EE_Error(esc_html__('Missing required value for the message template group id', 'event_espresso')); |
47 | 47 | } |
48 | 48 | $this->set('GRP_ID', $GRP_ID); |
@@ -12,173 +12,173 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Message_Template extends EE_Base_Class |
14 | 14 | { |
15 | - /** |
|
16 | - * @param array $props_n_values |
|
17 | - * @param string $timezone |
|
18 | - * @return EE_Message_Template|mixed |
|
19 | - */ |
|
20 | - public static function new_instance($props_n_values = array(), $timezone = '') |
|
21 | - { |
|
22 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
23 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
24 | - } |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * @param array $props_n_values |
|
29 | - * @param string $timezone |
|
30 | - * @return EE_Message_Template |
|
31 | - */ |
|
32 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
33 | - { |
|
34 | - return new self($props_n_values, true, $timezone); |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @param bool $GRP_ID |
|
40 | - * @throws EE_Error |
|
41 | - */ |
|
42 | - public function set_group_template_id($GRP_ID = false) |
|
43 | - { |
|
44 | - if (! $GRP_ID) { |
|
45 | - throw new EE_Error(esc_html__('Missing required value for the message template group id', 'event_espresso')); |
|
46 | - } |
|
47 | - $this->set('GRP_ID', $GRP_ID); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * get Group ID |
|
53 | - * |
|
54 | - * @access public |
|
55 | - * @return int |
|
56 | - */ |
|
57 | - public function GRP_ID() |
|
58 | - { |
|
59 | - return $this->get('GRP_ID'); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * get User ID |
|
65 | - * |
|
66 | - * @access public |
|
67 | - * @return int |
|
68 | - */ |
|
69 | - public function user() |
|
70 | - { |
|
71 | - return $this->get_first_related('Message_Template_Group')->get('MTP_user_id'); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * get Message Messenger |
|
77 | - * |
|
78 | - * @access public |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function messenger() |
|
82 | - { |
|
83 | - return $this->get_first_related('Message_Template_Group')->messenger(); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * get Message Messenger OBJECT |
|
89 | - * |
|
90 | - * @access public |
|
91 | - * @return object Messenger Object for the given messenger |
|
92 | - */ |
|
93 | - public function messenger_obj() |
|
94 | - { |
|
95 | - return $this->get_first_related('Message_Template_Group')->messenger_obj(); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * get Message Type |
|
101 | - * |
|
102 | - * @access public |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - public function message_type() |
|
106 | - { |
|
107 | - return $this->get_first_related('Message_Template_Group')->message_type(); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * get Message type OBJECT |
|
113 | - * |
|
114 | - * @access public |
|
115 | - * @return object Message Type object for the given message type |
|
116 | - */ |
|
117 | - public function message_type_obj() |
|
118 | - { |
|
119 | - return $this->get_first_related('Message_Template_Group')->message_type_obj(); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * This returns the set context array configured in the message type object |
|
125 | - * |
|
126 | - * @access public |
|
127 | - * @return array array of contexts and their configuration. |
|
128 | - */ |
|
129 | - public function contexts_config() |
|
130 | - { |
|
131 | - return $this->get_first_related('Message_Template_Group')->contexts_config(); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * This returns the context_label for contexts as set in the message type object |
|
137 | - * |
|
138 | - * @access public |
|
139 | - * @return string label for "context" |
|
140 | - */ |
|
141 | - public function context_label() |
|
142 | - { |
|
143 | - return $this->get_first_related('Message_Template_Group')->context_label(); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * this returns if the template group this template belongs to is global |
|
149 | - * |
|
150 | - * @return boolean true if it is, false if it isn't |
|
151 | - */ |
|
152 | - public function is_global() |
|
153 | - { |
|
154 | - return $this->get_first_related('Message_Template_Group')->is_global(); |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
160 | - * |
|
161 | - * @return boolean true if it is, false if it isn't |
|
162 | - */ |
|
163 | - public function is_active() |
|
164 | - { |
|
165 | - return $this->get_first_related('Message_Template_Group')->is_active(); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
171 | - * this template. |
|
172 | - * |
|
173 | - * @access public |
|
174 | - * @param string $context what context we're going to return shortcodes for |
|
175 | - * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
176 | - * to be merged and returned. |
|
177 | - * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
178 | - * shortcodes found. |
|
179 | - */ |
|
180 | - public function get_shortcodes($context, $fields = array()) |
|
181 | - { |
|
182 | - return $this->get_first_related('Message_Template_Group')->get_shortcodes($context, $fields); |
|
183 | - } |
|
15 | + /** |
|
16 | + * @param array $props_n_values |
|
17 | + * @param string $timezone |
|
18 | + * @return EE_Message_Template|mixed |
|
19 | + */ |
|
20 | + public static function new_instance($props_n_values = array(), $timezone = '') |
|
21 | + { |
|
22 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
23 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
24 | + } |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * @param array $props_n_values |
|
29 | + * @param string $timezone |
|
30 | + * @return EE_Message_Template |
|
31 | + */ |
|
32 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
33 | + { |
|
34 | + return new self($props_n_values, true, $timezone); |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @param bool $GRP_ID |
|
40 | + * @throws EE_Error |
|
41 | + */ |
|
42 | + public function set_group_template_id($GRP_ID = false) |
|
43 | + { |
|
44 | + if (! $GRP_ID) { |
|
45 | + throw new EE_Error(esc_html__('Missing required value for the message template group id', 'event_espresso')); |
|
46 | + } |
|
47 | + $this->set('GRP_ID', $GRP_ID); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * get Group ID |
|
53 | + * |
|
54 | + * @access public |
|
55 | + * @return int |
|
56 | + */ |
|
57 | + public function GRP_ID() |
|
58 | + { |
|
59 | + return $this->get('GRP_ID'); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * get User ID |
|
65 | + * |
|
66 | + * @access public |
|
67 | + * @return int |
|
68 | + */ |
|
69 | + public function user() |
|
70 | + { |
|
71 | + return $this->get_first_related('Message_Template_Group')->get('MTP_user_id'); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * get Message Messenger |
|
77 | + * |
|
78 | + * @access public |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function messenger() |
|
82 | + { |
|
83 | + return $this->get_first_related('Message_Template_Group')->messenger(); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * get Message Messenger OBJECT |
|
89 | + * |
|
90 | + * @access public |
|
91 | + * @return object Messenger Object for the given messenger |
|
92 | + */ |
|
93 | + public function messenger_obj() |
|
94 | + { |
|
95 | + return $this->get_first_related('Message_Template_Group')->messenger_obj(); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * get Message Type |
|
101 | + * |
|
102 | + * @access public |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + public function message_type() |
|
106 | + { |
|
107 | + return $this->get_first_related('Message_Template_Group')->message_type(); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * get Message type OBJECT |
|
113 | + * |
|
114 | + * @access public |
|
115 | + * @return object Message Type object for the given message type |
|
116 | + */ |
|
117 | + public function message_type_obj() |
|
118 | + { |
|
119 | + return $this->get_first_related('Message_Template_Group')->message_type_obj(); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * This returns the set context array configured in the message type object |
|
125 | + * |
|
126 | + * @access public |
|
127 | + * @return array array of contexts and their configuration. |
|
128 | + */ |
|
129 | + public function contexts_config() |
|
130 | + { |
|
131 | + return $this->get_first_related('Message_Template_Group')->contexts_config(); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * This returns the context_label for contexts as set in the message type object |
|
137 | + * |
|
138 | + * @access public |
|
139 | + * @return string label for "context" |
|
140 | + */ |
|
141 | + public function context_label() |
|
142 | + { |
|
143 | + return $this->get_first_related('Message_Template_Group')->context_label(); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * this returns if the template group this template belongs to is global |
|
149 | + * |
|
150 | + * @return boolean true if it is, false if it isn't |
|
151 | + */ |
|
152 | + public function is_global() |
|
153 | + { |
|
154 | + return $this->get_first_related('Message_Template_Group')->is_global(); |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
160 | + * |
|
161 | + * @return boolean true if it is, false if it isn't |
|
162 | + */ |
|
163 | + public function is_active() |
|
164 | + { |
|
165 | + return $this->get_first_related('Message_Template_Group')->is_active(); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
171 | + * this template. |
|
172 | + * |
|
173 | + * @access public |
|
174 | + * @param string $context what context we're going to return shortcodes for |
|
175 | + * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
176 | + * to be merged and returned. |
|
177 | + * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
178 | + * shortcodes found. |
|
179 | + */ |
|
180 | + public function get_shortcodes($context, $fields = array()) |
|
181 | + { |
|
182 | + return $this->get_first_related('Message_Template_Group')->get_shortcodes($context, $fields); |
|
183 | + } |
|
184 | 184 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | public static function validateType($type) |
69 | 69 | { |
70 | 70 | $types = CoffeeMaker::getTypes(); |
71 | - if (! in_array($type, $types, true)) { |
|
71 | + if ( ! in_array($type, $types, true)) { |
|
72 | 72 | throw new InvalidIdentifierException( |
73 | 73 | is_object($type) ? get_class($type) : gettype($type), |
74 | 74 | esc_html__( |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | protected function resolveClassAndFilepath(RecipeInterface $recipe) |
152 | 152 | { |
153 | 153 | $paths = $recipe->paths(); |
154 | - if (! empty($paths)) { |
|
154 | + if ( ! empty($paths)) { |
|
155 | 155 | foreach ($paths as $path) { |
156 | 156 | if (strpos($path, '*') === false && is_readable($path)) { |
157 | 157 | require_once($path); |
@@ -17,156 +17,156 @@ |
||
17 | 17 | */ |
18 | 18 | abstract class CoffeeMaker implements CoffeeMakerInterface |
19 | 19 | { |
20 | - /** |
|
21 | - * Indicates that CoffeeMaker should construct a NEW entity instance from the provided arguments (if given) |
|
22 | - */ |
|
23 | - const BREW_NEW = 'new'; |
|
24 | - |
|
25 | - /** |
|
26 | - * Indicates that CoffeeMaker should always return a SHARED instance |
|
27 | - */ |
|
28 | - const BREW_SHARED = 'shared'; |
|
29 | - |
|
30 | - /** |
|
31 | - * Indicates that CoffeeMaker should only load the file/class/interface but NOT instantiate |
|
32 | - */ |
|
33 | - const BREW_LOAD_ONLY = 'load_only'; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @var CoffeePotInterface $coffee_pot |
|
38 | - */ |
|
39 | - private $coffee_pot; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var DependencyInjector $injector |
|
43 | - */ |
|
44 | - private $injector; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * @return array |
|
49 | - */ |
|
50 | - public static function getTypes() |
|
51 | - { |
|
52 | - return (array) apply_filters( |
|
53 | - 'FHEE__EventEspresso\core\services\container\CoffeeMaker__getTypes', |
|
54 | - array( |
|
55 | - CoffeeMaker::BREW_NEW, |
|
56 | - CoffeeMaker::BREW_SHARED, |
|
57 | - CoffeeMaker::BREW_LOAD_ONLY, |
|
58 | - ) |
|
59 | - ); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @param $type |
|
65 | - * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
66 | - */ |
|
67 | - public static function validateType($type) |
|
68 | - { |
|
69 | - $types = CoffeeMaker::getTypes(); |
|
70 | - if (! in_array($type, $types, true)) { |
|
71 | - throw new InvalidIdentifierException( |
|
72 | - is_object($type) ? get_class($type) : gettype($type), |
|
73 | - esc_html__( |
|
74 | - 'recipe type (one of the class constants on \EventEspresso\core\services\container\CoffeeMaker)', |
|
75 | - 'event_espresso' |
|
76 | - ) |
|
77 | - ); |
|
78 | - } |
|
79 | - return $type; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * CoffeeMaker constructor. |
|
85 | - * |
|
86 | - * @param CoffeePotInterface $coffee_pot |
|
87 | - * @param InjectorInterface $injector |
|
88 | - */ |
|
89 | - public function __construct(CoffeePotInterface $coffee_pot, InjectorInterface $injector) |
|
90 | - { |
|
91 | - $this->coffee_pot = $coffee_pot; |
|
92 | - $this->injector = $injector; |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @return \EventEspresso\core\services\container\CoffeePotInterface |
|
98 | - */ |
|
99 | - protected function coffeePot() |
|
100 | - { |
|
101 | - return $this->coffee_pot; |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @return \EventEspresso\core\services\container\DependencyInjector |
|
107 | - */ |
|
108 | - protected function injector() |
|
109 | - { |
|
110 | - return $this->injector; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * Examines the constructor to determine which method should be used for instantiation |
|
116 | - * |
|
117 | - * @param \ReflectionClass $reflector |
|
118 | - * @return mixed |
|
119 | - * @throws InstantiationException |
|
120 | - */ |
|
121 | - protected function resolveInstantiationMethod(\ReflectionClass $reflector) |
|
122 | - { |
|
123 | - if ($reflector->getConstructor() === null) { |
|
124 | - return 'NewInstance'; |
|
125 | - } |
|
126 | - if ($reflector->isInstantiable()) { |
|
127 | - return 'NewInstanceArgs'; |
|
128 | - } |
|
129 | - if (method_exists($reflector->getName(), 'instance')) { |
|
130 | - return 'instance'; |
|
131 | - } |
|
132 | - if (method_exists($reflector->getName(), 'new_instance')) { |
|
133 | - return 'new_instance'; |
|
134 | - } |
|
135 | - if (method_exists($reflector->getName(), 'new_instance_from_db')) { |
|
136 | - return 'new_instance_from_db'; |
|
137 | - } |
|
138 | - throw new InstantiationException($reflector->getName()); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * Ensures files for classes that are not PSR-4 compatible are loaded |
|
144 | - * and then verifies that classes exist where applicable |
|
145 | - * |
|
146 | - * @param RecipeInterface $recipe |
|
147 | - * @return bool |
|
148 | - * @throws InvalidClassException |
|
149 | - */ |
|
150 | - protected function resolveClassAndFilepath(RecipeInterface $recipe) |
|
151 | - { |
|
152 | - $paths = $recipe->paths(); |
|
153 | - if (! empty($paths)) { |
|
154 | - foreach ($paths as $path) { |
|
155 | - if (strpos($path, '*') === false && is_readable($path)) { |
|
156 | - require_once($path); |
|
157 | - } |
|
158 | - } |
|
159 | - } |
|
160 | - // re: using "false" for class_exists() second param: |
|
161 | - // if a class name is not already known to PHP, then class_exists() will run through |
|
162 | - // all of the registered spl_autoload functions until it either finds the class, |
|
163 | - // or gets to the end of the registered spl_autoload functions. |
|
164 | - // When the second parameter is true, it will also attempt to load the class file, |
|
165 | - // but it will also trigger an error if the class can not be loaded. |
|
166 | - // We don't want that extra error in the mix, so we have set the second param to "false" |
|
167 | - if ($recipe->type() !== CoffeeMaker::BREW_LOAD_ONLY && ! class_exists($recipe->fqcn(), false)) { |
|
168 | - throw new InvalidClassException($recipe->identifier()); |
|
169 | - } |
|
170 | - return true; |
|
171 | - } |
|
20 | + /** |
|
21 | + * Indicates that CoffeeMaker should construct a NEW entity instance from the provided arguments (if given) |
|
22 | + */ |
|
23 | + const BREW_NEW = 'new'; |
|
24 | + |
|
25 | + /** |
|
26 | + * Indicates that CoffeeMaker should always return a SHARED instance |
|
27 | + */ |
|
28 | + const BREW_SHARED = 'shared'; |
|
29 | + |
|
30 | + /** |
|
31 | + * Indicates that CoffeeMaker should only load the file/class/interface but NOT instantiate |
|
32 | + */ |
|
33 | + const BREW_LOAD_ONLY = 'load_only'; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @var CoffeePotInterface $coffee_pot |
|
38 | + */ |
|
39 | + private $coffee_pot; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var DependencyInjector $injector |
|
43 | + */ |
|
44 | + private $injector; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * @return array |
|
49 | + */ |
|
50 | + public static function getTypes() |
|
51 | + { |
|
52 | + return (array) apply_filters( |
|
53 | + 'FHEE__EventEspresso\core\services\container\CoffeeMaker__getTypes', |
|
54 | + array( |
|
55 | + CoffeeMaker::BREW_NEW, |
|
56 | + CoffeeMaker::BREW_SHARED, |
|
57 | + CoffeeMaker::BREW_LOAD_ONLY, |
|
58 | + ) |
|
59 | + ); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @param $type |
|
65 | + * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
66 | + */ |
|
67 | + public static function validateType($type) |
|
68 | + { |
|
69 | + $types = CoffeeMaker::getTypes(); |
|
70 | + if (! in_array($type, $types, true)) { |
|
71 | + throw new InvalidIdentifierException( |
|
72 | + is_object($type) ? get_class($type) : gettype($type), |
|
73 | + esc_html__( |
|
74 | + 'recipe type (one of the class constants on \EventEspresso\core\services\container\CoffeeMaker)', |
|
75 | + 'event_espresso' |
|
76 | + ) |
|
77 | + ); |
|
78 | + } |
|
79 | + return $type; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * CoffeeMaker constructor. |
|
85 | + * |
|
86 | + * @param CoffeePotInterface $coffee_pot |
|
87 | + * @param InjectorInterface $injector |
|
88 | + */ |
|
89 | + public function __construct(CoffeePotInterface $coffee_pot, InjectorInterface $injector) |
|
90 | + { |
|
91 | + $this->coffee_pot = $coffee_pot; |
|
92 | + $this->injector = $injector; |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @return \EventEspresso\core\services\container\CoffeePotInterface |
|
98 | + */ |
|
99 | + protected function coffeePot() |
|
100 | + { |
|
101 | + return $this->coffee_pot; |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @return \EventEspresso\core\services\container\DependencyInjector |
|
107 | + */ |
|
108 | + protected function injector() |
|
109 | + { |
|
110 | + return $this->injector; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * Examines the constructor to determine which method should be used for instantiation |
|
116 | + * |
|
117 | + * @param \ReflectionClass $reflector |
|
118 | + * @return mixed |
|
119 | + * @throws InstantiationException |
|
120 | + */ |
|
121 | + protected function resolveInstantiationMethod(\ReflectionClass $reflector) |
|
122 | + { |
|
123 | + if ($reflector->getConstructor() === null) { |
|
124 | + return 'NewInstance'; |
|
125 | + } |
|
126 | + if ($reflector->isInstantiable()) { |
|
127 | + return 'NewInstanceArgs'; |
|
128 | + } |
|
129 | + if (method_exists($reflector->getName(), 'instance')) { |
|
130 | + return 'instance'; |
|
131 | + } |
|
132 | + if (method_exists($reflector->getName(), 'new_instance')) { |
|
133 | + return 'new_instance'; |
|
134 | + } |
|
135 | + if (method_exists($reflector->getName(), 'new_instance_from_db')) { |
|
136 | + return 'new_instance_from_db'; |
|
137 | + } |
|
138 | + throw new InstantiationException($reflector->getName()); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * Ensures files for classes that are not PSR-4 compatible are loaded |
|
144 | + * and then verifies that classes exist where applicable |
|
145 | + * |
|
146 | + * @param RecipeInterface $recipe |
|
147 | + * @return bool |
|
148 | + * @throws InvalidClassException |
|
149 | + */ |
|
150 | + protected function resolveClassAndFilepath(RecipeInterface $recipe) |
|
151 | + { |
|
152 | + $paths = $recipe->paths(); |
|
153 | + if (! empty($paths)) { |
|
154 | + foreach ($paths as $path) { |
|
155 | + if (strpos($path, '*') === false && is_readable($path)) { |
|
156 | + require_once($path); |
|
157 | + } |
|
158 | + } |
|
159 | + } |
|
160 | + // re: using "false" for class_exists() second param: |
|
161 | + // if a class name is not already known to PHP, then class_exists() will run through |
|
162 | + // all of the registered spl_autoload functions until it either finds the class, |
|
163 | + // or gets to the end of the registered spl_autoload functions. |
|
164 | + // When the second parameter is true, it will also attempt to load the class file, |
|
165 | + // but it will also trigger an error if the class can not be loaded. |
|
166 | + // We don't want that extra error in the mix, so we have set the second param to "false" |
|
167 | + if ($recipe->type() !== CoffeeMaker::BREW_LOAD_ONLY && ! class_exists($recipe->fqcn(), false)) { |
|
168 | + throw new InvalidClassException($recipe->identifier()); |
|
169 | + } |
|
170 | + return true; |
|
171 | + } |
|
172 | 172 | } |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | */ |
190 | 190 | public function setIdentifier($identifier) |
191 | 191 | { |
192 | - if (! is_string($identifier) || empty($identifier)) { |
|
192 | + if ( ! is_string($identifier) || empty($identifier)) { |
|
193 | 193 | throw new InvalidIdentifierException( |
194 | 194 | is_object($identifier) ? get_class($identifier) : gettype($identifier), |
195 | 195 | esc_html__('class identifier (typically a \Fully\Qualified\ClassName)', 'event_espresso') |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | public function setFqcn($fqcn) |
217 | 217 | { |
218 | 218 | $fqcn = ! empty($fqcn) ? $fqcn : $this->identifier; |
219 | - if (! is_string($fqcn)) { |
|
219 | + if ( ! is_string($fqcn)) { |
|
220 | 220 | throw new InvalidDataTypeException( |
221 | 221 | '$fqcn', |
222 | 222 | is_object($fqcn) ? get_class($fqcn) : gettype($fqcn), |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | if (empty($ingredients)) { |
248 | 248 | return; |
249 | 249 | } |
250 | - if (! is_array($ingredients)) { |
|
250 | + if ( ! is_array($ingredients)) { |
|
251 | 251 | throw new InvalidDataTypeException( |
252 | 252 | '$ingredients', |
253 | 253 | is_object($ingredients) ? get_class($ingredients) : gettype($ingredients), |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | if (empty($filters)) { |
280 | 280 | return; |
281 | 281 | } |
282 | - if (! is_array($filters)) { |
|
282 | + if ( ! is_array($filters)) { |
|
283 | 283 | throw new InvalidDataTypeException( |
284 | 284 | '$filters', |
285 | 285 | is_object($filters) ? get_class($filters) : gettype($filters), |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | if (empty($paths)) { |
307 | 307 | return; |
308 | 308 | } |
309 | - if (! (is_string($paths) || is_array($paths))) { |
|
309 | + if ( ! (is_string($paths) || is_array($paths))) { |
|
310 | 310 | throw new InvalidDataTypeException( |
311 | 311 | '$path', |
312 | 312 | is_object($paths) ? get_class($paths) : gettype($paths), |
@@ -18,311 +18,311 @@ |
||
18 | 18 | */ |
19 | 19 | class Recipe implements RecipeInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * A default Recipe to use if none is specified for a class |
|
23 | - */ |
|
24 | - const DEFAULT_ID = '*'; |
|
25 | - |
|
26 | - /** |
|
27 | - * Identifier for the entity class to be constructed. |
|
28 | - * Typically a Fully Qualified Class Name |
|
29 | - * |
|
30 | - * @var string $identifier |
|
31 | - */ |
|
32 | - private $identifier; |
|
33 | - |
|
34 | - /** |
|
35 | - * Fully Qualified Class Name |
|
36 | - * |
|
37 | - * @var string $fqcn |
|
38 | - */ |
|
39 | - private $fqcn; |
|
40 | - |
|
41 | - /** |
|
42 | - * a dependency class map array |
|
43 | - * If a Recipe is for a single class (or group of classes that shares the EXACT SAME constructor arguments), |
|
44 | - * and that class type hints for an interface, then this property allows you to configure what dependencies |
|
45 | - * get used when instantiating the class. |
|
46 | - * For example: |
|
47 | - * There's a class called Coffee, and one of its constructor arguments is BeanInterface |
|
48 | - * There are two implementations of BeanInterface: HonduranBean, and KenyanBean |
|
49 | - * We want one Coffee object to use HonduranBean for its BeanInterface, |
|
50 | - * and the 2nd Coffee object to use KenyanBean for its BeanInterface. |
|
51 | - * To do this, we need to create two Recipes: |
|
52 | - * one with an identifier of 'HonduranCoffee' using the following ingredients : |
|
53 | - * array('BeanInterface' => 'HonduranBean') |
|
54 | - * and the other with an identifier of 'KenyanCoffee' using the following ingredients : |
|
55 | - * array('BeanInterface' => 'KenyanBean') |
|
56 | - * Then, whenever the CoffeeShop brews an instance of HonduranCoffee, |
|
57 | - * an instance of HonduranBean will get injected for the BeanInterface dependency, |
|
58 | - * and whenever the CoffeeShop brews an instance of KenyanCoffee, |
|
59 | - * an instance of KenyanBean will get injected for the BeanInterface dependency |
|
60 | - * |
|
61 | - * @var array $ingredients |
|
62 | - */ |
|
63 | - private $ingredients = array(); |
|
64 | - |
|
65 | - /** |
|
66 | - * one of the class constants from CoffeeShop: |
|
67 | - * CoffeeMaker::BREW_NEW - creates a new instance |
|
68 | - * CoffeeMaker::BREW_SHARED - creates a shared instance |
|
69 | - * CoffeeMaker::BREW_LOAD_ONLY - loads but does not instantiate |
|
70 | - * |
|
71 | - * @var string $type |
|
72 | - */ |
|
73 | - private $type; |
|
74 | - |
|
75 | - /** |
|
76 | - * class name aliases - typically a Fully Qualified Interface that the class implements |
|
77 | - * identifiers passed to the CoffeeShop will be run through the filters to find the correct class name |
|
78 | - * |
|
79 | - * @var array $filters |
|
80 | - */ |
|
81 | - private $filters = array(); |
|
82 | - |
|
83 | - /** |
|
84 | - * array of full server filepaths to files that may contain the class |
|
85 | - * |
|
86 | - * @var array $paths |
|
87 | - */ |
|
88 | - private $paths = array(); |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * Recipe constructor. |
|
93 | - * |
|
94 | - * @param string $identifier class identifier, can be an alias, or FQCN, or whatever |
|
95 | - * @param string $fqcn \Fully\Qualified\ClassName, optional if $identifier is FQCN |
|
96 | - * @param array $ingredients array of dependencies that can not be resolved automatically, |
|
97 | - * used for resolving concrete classes for type hinted interfaces |
|
98 | - * for the dependencies of THIS class |
|
99 | - * @param string $type recipe type: one of the class constants on |
|
100 | - * \EventEspresso\core\services\container\CoffeeMaker |
|
101 | - * @param array $filters array of class aliases, or class interfaces |
|
102 | - * this works somewhat opposite to the $ingredients array above, |
|
103 | - * in that this array specifies interfaces or aliases |
|
104 | - * that this Recipe can be used for when resolving OTHER class's dependencies |
|
105 | - * @param array $paths if class can not be loaded via PSR-4 autoloading, |
|
106 | - * then supply a filepath, or array of filepaths, so that it can be included |
|
107 | - * @throws InvalidIdentifierException |
|
108 | - * @throws RuntimeException |
|
109 | - * @throws InvalidInterfaceException |
|
110 | - * @throws InvalidClassException |
|
111 | - * @throws InvalidDataTypeException |
|
112 | - */ |
|
113 | - public function __construct( |
|
114 | - $identifier, |
|
115 | - $fqcn = '', |
|
116 | - array $filters = array(), |
|
117 | - array $ingredients = array(), |
|
118 | - $type = CoffeeMaker::BREW_NEW, |
|
119 | - array $paths = array() |
|
120 | - ) { |
|
121 | - $this->setIdentifier($identifier); |
|
122 | - $this->setFilters($filters); |
|
123 | - $this->setIngredients($ingredients); |
|
124 | - $this->setType($type); |
|
125 | - $this->setPaths($paths); |
|
126 | - $this->setFqcn($fqcn); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function identifier() |
|
134 | - { |
|
135 | - return $this->identifier; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public function fqcn() |
|
143 | - { |
|
144 | - return $this->fqcn; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @return array |
|
150 | - */ |
|
151 | - public function filters() |
|
152 | - { |
|
153 | - return $this->filters; |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @return array |
|
159 | - */ |
|
160 | - public function ingredients() |
|
161 | - { |
|
162 | - return $this->ingredients; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * @return string |
|
168 | - */ |
|
169 | - public function type() |
|
170 | - { |
|
171 | - return $this->type; |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @return array |
|
177 | - */ |
|
178 | - public function paths() |
|
179 | - { |
|
180 | - return $this->paths; |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * @param string $identifier Identifier for the entity class that the Recipe applies to |
|
186 | - * Typically a Fully Qualified Class Name |
|
187 | - * @throws InvalidIdentifierException |
|
188 | - */ |
|
189 | - public function setIdentifier($identifier) |
|
190 | - { |
|
191 | - if (! is_string($identifier) || empty($identifier)) { |
|
192 | - throw new InvalidIdentifierException( |
|
193 | - is_object($identifier) ? get_class($identifier) : gettype($identifier), |
|
194 | - esc_html__('class identifier (typically a \Fully\Qualified\ClassName)', 'event_espresso') |
|
195 | - ); |
|
196 | - } |
|
197 | - $this->identifier = $identifier; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * Ensures incoming string is a valid Fully Qualified Class Name, |
|
203 | - * except if this is the default wildcard Recipe ( * ), |
|
204 | - * or it's NOT an actual FQCN because the Recipe is using filepaths |
|
205 | - * for classes that are not PSR-4 compatible |
|
206 | - * PLZ NOTE: |
|
207 | - * Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not, |
|
208 | - * therefore you should always call Recipe::setPaths() before Recipe::setFqcn() |
|
209 | - * |
|
210 | - * @param string $fqcn |
|
211 | - * @throws InvalidDataTypeException |
|
212 | - * @throws InvalidClassException |
|
213 | - * @throws InvalidInterfaceException |
|
214 | - */ |
|
215 | - public function setFqcn($fqcn) |
|
216 | - { |
|
217 | - $fqcn = ! empty($fqcn) ? $fqcn : $this->identifier; |
|
218 | - if (! is_string($fqcn)) { |
|
219 | - throw new InvalidDataTypeException( |
|
220 | - '$fqcn', |
|
221 | - is_object($fqcn) ? get_class($fqcn) : gettype($fqcn), |
|
222 | - esc_html__('string (Fully\Qualified\ClassName)', 'event_espresso') |
|
223 | - ); |
|
224 | - } |
|
225 | - $fqcn = ltrim($fqcn, '\\'); |
|
226 | - if ( |
|
227 | - $fqcn !== Recipe::DEFAULT_ID |
|
228 | - && ! empty($fqcn) |
|
229 | - && empty($this->paths) |
|
230 | - && ! (class_exists($fqcn) || interface_exists($fqcn)) |
|
231 | - ) { |
|
232 | - throw new InvalidClassException($fqcn); |
|
233 | - } |
|
234 | - $this->fqcn = $fqcn; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @param array $ingredients an array of dependencies where keys are the aliases and values are the FQCNs |
|
240 | - * example: |
|
241 | - * array( 'ClassInterface' => 'Fully\Qualified\ClassName' ) |
|
242 | - * @throws InvalidDataTypeException |
|
243 | - */ |
|
244 | - public function setIngredients(array $ingredients) |
|
245 | - { |
|
246 | - if (empty($ingredients)) { |
|
247 | - return; |
|
248 | - } |
|
249 | - if (! is_array($ingredients)) { |
|
250 | - throw new InvalidDataTypeException( |
|
251 | - '$ingredients', |
|
252 | - is_object($ingredients) ? get_class($ingredients) : gettype($ingredients), |
|
253 | - esc_html__('array of class dependencies', 'event_espresso') |
|
254 | - ); |
|
255 | - } |
|
256 | - $this->ingredients = array_merge($this->ingredients, $ingredients); |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * @param string $type one of the class constants returned from CoffeeMaker::getTypes() |
|
262 | - * @throws InvalidIdentifierException |
|
263 | - */ |
|
264 | - public function setType($type = CoffeeMaker::BREW_NEW) |
|
265 | - { |
|
266 | - $this->type = CoffeeMaker::validateType($type); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * @param array $filters an array of filters where keys are the aliases and values are the FQCNs |
|
272 | - * example: |
|
273 | - * array( 'ClassInterface' => 'Fully\Qualified\ClassName' ) |
|
274 | - * @throws InvalidDataTypeException |
|
275 | - */ |
|
276 | - public function setFilters(array $filters) |
|
277 | - { |
|
278 | - if (empty($filters)) { |
|
279 | - return; |
|
280 | - } |
|
281 | - if (! is_array($filters)) { |
|
282 | - throw new InvalidDataTypeException( |
|
283 | - '$filters', |
|
284 | - is_object($filters) ? get_class($filters) : gettype($filters), |
|
285 | - esc_html__('array of class aliases', 'event_espresso') |
|
286 | - ); |
|
287 | - } |
|
288 | - $this->filters = array_merge($this->filters, $filters); |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * Ensures incoming paths is a valid filepath, or array of valid filepaths, |
|
294 | - * and merges them in with any existing filepaths |
|
295 | - * PLZ NOTE: |
|
296 | - * Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not, |
|
297 | - * therefore you should always call Recipe::setPaths() before Recipe::setFqcn() |
|
298 | - * |
|
299 | - * @param string|array $paths |
|
300 | - * @throws RuntimeException |
|
301 | - * @throws InvalidDataTypeException |
|
302 | - */ |
|
303 | - public function setPaths($paths = array()) |
|
304 | - { |
|
305 | - if (empty($paths)) { |
|
306 | - return; |
|
307 | - } |
|
308 | - if (! (is_string($paths) || is_array($paths))) { |
|
309 | - throw new InvalidDataTypeException( |
|
310 | - '$path', |
|
311 | - is_object($paths) ? get_class($paths) : gettype($paths), |
|
312 | - esc_html__('string or array of strings (full server filepath(s))', 'event_espresso') |
|
313 | - ); |
|
314 | - } |
|
315 | - $paths = (array) $paths; |
|
316 | - foreach ($paths as $path) { |
|
317 | - if (strpos($path, '*') === false && ! is_readable($path)) { |
|
318 | - throw new RuntimeException( |
|
319 | - sprintf( |
|
320 | - esc_html__('The following filepath is not readable: "%1$s"', 'event_espresso'), |
|
321 | - $path |
|
322 | - ) |
|
323 | - ); |
|
324 | - } |
|
325 | - } |
|
326 | - $this->paths = array_merge($this->paths, $paths); |
|
327 | - } |
|
21 | + /** |
|
22 | + * A default Recipe to use if none is specified for a class |
|
23 | + */ |
|
24 | + const DEFAULT_ID = '*'; |
|
25 | + |
|
26 | + /** |
|
27 | + * Identifier for the entity class to be constructed. |
|
28 | + * Typically a Fully Qualified Class Name |
|
29 | + * |
|
30 | + * @var string $identifier |
|
31 | + */ |
|
32 | + private $identifier; |
|
33 | + |
|
34 | + /** |
|
35 | + * Fully Qualified Class Name |
|
36 | + * |
|
37 | + * @var string $fqcn |
|
38 | + */ |
|
39 | + private $fqcn; |
|
40 | + |
|
41 | + /** |
|
42 | + * a dependency class map array |
|
43 | + * If a Recipe is for a single class (or group of classes that shares the EXACT SAME constructor arguments), |
|
44 | + * and that class type hints for an interface, then this property allows you to configure what dependencies |
|
45 | + * get used when instantiating the class. |
|
46 | + * For example: |
|
47 | + * There's a class called Coffee, and one of its constructor arguments is BeanInterface |
|
48 | + * There are two implementations of BeanInterface: HonduranBean, and KenyanBean |
|
49 | + * We want one Coffee object to use HonduranBean for its BeanInterface, |
|
50 | + * and the 2nd Coffee object to use KenyanBean for its BeanInterface. |
|
51 | + * To do this, we need to create two Recipes: |
|
52 | + * one with an identifier of 'HonduranCoffee' using the following ingredients : |
|
53 | + * array('BeanInterface' => 'HonduranBean') |
|
54 | + * and the other with an identifier of 'KenyanCoffee' using the following ingredients : |
|
55 | + * array('BeanInterface' => 'KenyanBean') |
|
56 | + * Then, whenever the CoffeeShop brews an instance of HonduranCoffee, |
|
57 | + * an instance of HonduranBean will get injected for the BeanInterface dependency, |
|
58 | + * and whenever the CoffeeShop brews an instance of KenyanCoffee, |
|
59 | + * an instance of KenyanBean will get injected for the BeanInterface dependency |
|
60 | + * |
|
61 | + * @var array $ingredients |
|
62 | + */ |
|
63 | + private $ingredients = array(); |
|
64 | + |
|
65 | + /** |
|
66 | + * one of the class constants from CoffeeShop: |
|
67 | + * CoffeeMaker::BREW_NEW - creates a new instance |
|
68 | + * CoffeeMaker::BREW_SHARED - creates a shared instance |
|
69 | + * CoffeeMaker::BREW_LOAD_ONLY - loads but does not instantiate |
|
70 | + * |
|
71 | + * @var string $type |
|
72 | + */ |
|
73 | + private $type; |
|
74 | + |
|
75 | + /** |
|
76 | + * class name aliases - typically a Fully Qualified Interface that the class implements |
|
77 | + * identifiers passed to the CoffeeShop will be run through the filters to find the correct class name |
|
78 | + * |
|
79 | + * @var array $filters |
|
80 | + */ |
|
81 | + private $filters = array(); |
|
82 | + |
|
83 | + /** |
|
84 | + * array of full server filepaths to files that may contain the class |
|
85 | + * |
|
86 | + * @var array $paths |
|
87 | + */ |
|
88 | + private $paths = array(); |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * Recipe constructor. |
|
93 | + * |
|
94 | + * @param string $identifier class identifier, can be an alias, or FQCN, or whatever |
|
95 | + * @param string $fqcn \Fully\Qualified\ClassName, optional if $identifier is FQCN |
|
96 | + * @param array $ingredients array of dependencies that can not be resolved automatically, |
|
97 | + * used for resolving concrete classes for type hinted interfaces |
|
98 | + * for the dependencies of THIS class |
|
99 | + * @param string $type recipe type: one of the class constants on |
|
100 | + * \EventEspresso\core\services\container\CoffeeMaker |
|
101 | + * @param array $filters array of class aliases, or class interfaces |
|
102 | + * this works somewhat opposite to the $ingredients array above, |
|
103 | + * in that this array specifies interfaces or aliases |
|
104 | + * that this Recipe can be used for when resolving OTHER class's dependencies |
|
105 | + * @param array $paths if class can not be loaded via PSR-4 autoloading, |
|
106 | + * then supply a filepath, or array of filepaths, so that it can be included |
|
107 | + * @throws InvalidIdentifierException |
|
108 | + * @throws RuntimeException |
|
109 | + * @throws InvalidInterfaceException |
|
110 | + * @throws InvalidClassException |
|
111 | + * @throws InvalidDataTypeException |
|
112 | + */ |
|
113 | + public function __construct( |
|
114 | + $identifier, |
|
115 | + $fqcn = '', |
|
116 | + array $filters = array(), |
|
117 | + array $ingredients = array(), |
|
118 | + $type = CoffeeMaker::BREW_NEW, |
|
119 | + array $paths = array() |
|
120 | + ) { |
|
121 | + $this->setIdentifier($identifier); |
|
122 | + $this->setFilters($filters); |
|
123 | + $this->setIngredients($ingredients); |
|
124 | + $this->setType($type); |
|
125 | + $this->setPaths($paths); |
|
126 | + $this->setFqcn($fqcn); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function identifier() |
|
134 | + { |
|
135 | + return $this->identifier; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public function fqcn() |
|
143 | + { |
|
144 | + return $this->fqcn; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @return array |
|
150 | + */ |
|
151 | + public function filters() |
|
152 | + { |
|
153 | + return $this->filters; |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @return array |
|
159 | + */ |
|
160 | + public function ingredients() |
|
161 | + { |
|
162 | + return $this->ingredients; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * @return string |
|
168 | + */ |
|
169 | + public function type() |
|
170 | + { |
|
171 | + return $this->type; |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @return array |
|
177 | + */ |
|
178 | + public function paths() |
|
179 | + { |
|
180 | + return $this->paths; |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * @param string $identifier Identifier for the entity class that the Recipe applies to |
|
186 | + * Typically a Fully Qualified Class Name |
|
187 | + * @throws InvalidIdentifierException |
|
188 | + */ |
|
189 | + public function setIdentifier($identifier) |
|
190 | + { |
|
191 | + if (! is_string($identifier) || empty($identifier)) { |
|
192 | + throw new InvalidIdentifierException( |
|
193 | + is_object($identifier) ? get_class($identifier) : gettype($identifier), |
|
194 | + esc_html__('class identifier (typically a \Fully\Qualified\ClassName)', 'event_espresso') |
|
195 | + ); |
|
196 | + } |
|
197 | + $this->identifier = $identifier; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * Ensures incoming string is a valid Fully Qualified Class Name, |
|
203 | + * except if this is the default wildcard Recipe ( * ), |
|
204 | + * or it's NOT an actual FQCN because the Recipe is using filepaths |
|
205 | + * for classes that are not PSR-4 compatible |
|
206 | + * PLZ NOTE: |
|
207 | + * Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not, |
|
208 | + * therefore you should always call Recipe::setPaths() before Recipe::setFqcn() |
|
209 | + * |
|
210 | + * @param string $fqcn |
|
211 | + * @throws InvalidDataTypeException |
|
212 | + * @throws InvalidClassException |
|
213 | + * @throws InvalidInterfaceException |
|
214 | + */ |
|
215 | + public function setFqcn($fqcn) |
|
216 | + { |
|
217 | + $fqcn = ! empty($fqcn) ? $fqcn : $this->identifier; |
|
218 | + if (! is_string($fqcn)) { |
|
219 | + throw new InvalidDataTypeException( |
|
220 | + '$fqcn', |
|
221 | + is_object($fqcn) ? get_class($fqcn) : gettype($fqcn), |
|
222 | + esc_html__('string (Fully\Qualified\ClassName)', 'event_espresso') |
|
223 | + ); |
|
224 | + } |
|
225 | + $fqcn = ltrim($fqcn, '\\'); |
|
226 | + if ( |
|
227 | + $fqcn !== Recipe::DEFAULT_ID |
|
228 | + && ! empty($fqcn) |
|
229 | + && empty($this->paths) |
|
230 | + && ! (class_exists($fqcn) || interface_exists($fqcn)) |
|
231 | + ) { |
|
232 | + throw new InvalidClassException($fqcn); |
|
233 | + } |
|
234 | + $this->fqcn = $fqcn; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @param array $ingredients an array of dependencies where keys are the aliases and values are the FQCNs |
|
240 | + * example: |
|
241 | + * array( 'ClassInterface' => 'Fully\Qualified\ClassName' ) |
|
242 | + * @throws InvalidDataTypeException |
|
243 | + */ |
|
244 | + public function setIngredients(array $ingredients) |
|
245 | + { |
|
246 | + if (empty($ingredients)) { |
|
247 | + return; |
|
248 | + } |
|
249 | + if (! is_array($ingredients)) { |
|
250 | + throw new InvalidDataTypeException( |
|
251 | + '$ingredients', |
|
252 | + is_object($ingredients) ? get_class($ingredients) : gettype($ingredients), |
|
253 | + esc_html__('array of class dependencies', 'event_espresso') |
|
254 | + ); |
|
255 | + } |
|
256 | + $this->ingredients = array_merge($this->ingredients, $ingredients); |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * @param string $type one of the class constants returned from CoffeeMaker::getTypes() |
|
262 | + * @throws InvalidIdentifierException |
|
263 | + */ |
|
264 | + public function setType($type = CoffeeMaker::BREW_NEW) |
|
265 | + { |
|
266 | + $this->type = CoffeeMaker::validateType($type); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * @param array $filters an array of filters where keys are the aliases and values are the FQCNs |
|
272 | + * example: |
|
273 | + * array( 'ClassInterface' => 'Fully\Qualified\ClassName' ) |
|
274 | + * @throws InvalidDataTypeException |
|
275 | + */ |
|
276 | + public function setFilters(array $filters) |
|
277 | + { |
|
278 | + if (empty($filters)) { |
|
279 | + return; |
|
280 | + } |
|
281 | + if (! is_array($filters)) { |
|
282 | + throw new InvalidDataTypeException( |
|
283 | + '$filters', |
|
284 | + is_object($filters) ? get_class($filters) : gettype($filters), |
|
285 | + esc_html__('array of class aliases', 'event_espresso') |
|
286 | + ); |
|
287 | + } |
|
288 | + $this->filters = array_merge($this->filters, $filters); |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * Ensures incoming paths is a valid filepath, or array of valid filepaths, |
|
294 | + * and merges them in with any existing filepaths |
|
295 | + * PLZ NOTE: |
|
296 | + * Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not, |
|
297 | + * therefore you should always call Recipe::setPaths() before Recipe::setFqcn() |
|
298 | + * |
|
299 | + * @param string|array $paths |
|
300 | + * @throws RuntimeException |
|
301 | + * @throws InvalidDataTypeException |
|
302 | + */ |
|
303 | + public function setPaths($paths = array()) |
|
304 | + { |
|
305 | + if (empty($paths)) { |
|
306 | + return; |
|
307 | + } |
|
308 | + if (! (is_string($paths) || is_array($paths))) { |
|
309 | + throw new InvalidDataTypeException( |
|
310 | + '$path', |
|
311 | + is_object($paths) ? get_class($paths) : gettype($paths), |
|
312 | + esc_html__('string or array of strings (full server filepath(s))', 'event_espresso') |
|
313 | + ); |
|
314 | + } |
|
315 | + $paths = (array) $paths; |
|
316 | + foreach ($paths as $path) { |
|
317 | + if (strpos($path, '*') === false && ! is_readable($path)) { |
|
318 | + throw new RuntimeException( |
|
319 | + sprintf( |
|
320 | + esc_html__('The following filepath is not readable: "%1$s"', 'event_espresso'), |
|
321 | + $path |
|
322 | + ) |
|
323 | + ); |
|
324 | + } |
|
325 | + } |
|
326 | + $this->paths = array_merge($this->paths, $paths); |
|
327 | + } |
|
328 | 328 | } |