@@ -14,72 +14,72 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | abstract class ConstantsAbstract |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Equivalent to `__FILE__` for main plugin file. |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - private static $plugin_file =''; |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * String indicating version for plugin |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - private static $version = ''; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Initializes internal static properties. |
|
| 33 | - * @param $plugin_file |
|
| 34 | - * @param $version |
|
| 35 | - */ |
|
| 36 | - public static function init($plugin_file, $version) |
|
| 37 | - { |
|
| 38 | - self::$plugin_file = $plugin_file; |
|
| 39 | - self::$version = $version; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @return string |
|
| 45 | - */ |
|
| 46 | - public static function pluginFile() |
|
| 47 | - { |
|
| 48 | - return self::$plugin_file; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @return string |
|
| 53 | - */ |
|
| 54 | - public static function pluginBasename() |
|
| 55 | - { |
|
| 56 | - return plugin_basename(self::$plugin_file); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @return string |
|
| 61 | - */ |
|
| 62 | - public static function pluginPath() |
|
| 63 | - { |
|
| 64 | - return plugin_dir_path(self::$plugin_file); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @return string |
|
| 70 | - */ |
|
| 71 | - public static function pluginUrl() |
|
| 72 | - { |
|
| 73 | - return plugin_dir_url(self::$plugin_file); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @return string |
|
| 79 | - */ |
|
| 80 | - public static function version() |
|
| 81 | - { |
|
| 82 | - return self::$version; |
|
| 83 | - } |
|
| 17 | + /** |
|
| 18 | + * Equivalent to `__FILE__` for main plugin file. |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + private static $plugin_file =''; |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * String indicating version for plugin |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + private static $version = ''; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Initializes internal static properties. |
|
| 33 | + * @param $plugin_file |
|
| 34 | + * @param $version |
|
| 35 | + */ |
|
| 36 | + public static function init($plugin_file, $version) |
|
| 37 | + { |
|
| 38 | + self::$plugin_file = $plugin_file; |
|
| 39 | + self::$version = $version; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @return string |
|
| 45 | + */ |
|
| 46 | + public static function pluginFile() |
|
| 47 | + { |
|
| 48 | + return self::$plugin_file; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @return string |
|
| 53 | + */ |
|
| 54 | + public static function pluginBasename() |
|
| 55 | + { |
|
| 56 | + return plugin_basename(self::$plugin_file); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @return string |
|
| 61 | + */ |
|
| 62 | + public static function pluginPath() |
|
| 63 | + { |
|
| 64 | + return plugin_dir_path(self::$plugin_file); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @return string |
|
| 70 | + */ |
|
| 71 | + public static function pluginUrl() |
|
| 72 | + { |
|
| 73 | + return plugin_dir_url(self::$plugin_file); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @return string |
|
| 79 | + */ |
|
| 80 | + public static function version() |
|
| 81 | + { |
|
| 82 | + return self::$version; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | 85 | } |
| 86 | 86 | \ No newline at end of file |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | * Equivalent to `__FILE__` for main plugin file. |
| 19 | 19 | * @var string |
| 20 | 20 | */ |
| 21 | - private static $plugin_file =''; |
|
| 21 | + private static $plugin_file = ''; |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -577,7 +577,7 @@ |
||
| 577 | 577 | |
| 578 | 578 | /** |
| 579 | 579 | * @param EE_State[] $state_options |
| 580 | - * @return array |
|
| 580 | + * @return EE_State[] |
|
| 581 | 581 | * @throws EE_Error |
| 582 | 582 | */ |
| 583 | 583 | public static function state_options($state_options = array()) |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -16,620 +16,620 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @return EED_Module|EED_Add_New_State |
|
| 21 | - */ |
|
| 22 | - public static function instance() |
|
| 23 | - { |
|
| 24 | - return parent::get_instance(__CLASS__); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 31 | - * |
|
| 32 | - * @return void |
|
| 33 | - */ |
|
| 34 | - public static function set_hooks() |
|
| 35 | - { |
|
| 36 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 37 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
| 38 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
| 39 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 40 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 41 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 42 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 43 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 44 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 45 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 46 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 47 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 48 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 49 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 50 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 51 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 52 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 59 | - * |
|
| 60 | - * @return void |
|
| 61 | - */ |
|
| 62 | - public static function set_hooks_admin() |
|
| 63 | - { |
|
| 64 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 65 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 66 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 67 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 68 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 69 | - add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 70 | - add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 71 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 72 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 73 | - add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 74 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 75 | - add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 76 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 77 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 78 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 79 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 80 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 81 | - add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 82 | - array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
| 83 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 84 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 85 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 86 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @return void |
|
| 93 | - */ |
|
| 94 | - public static function set_definitions() |
|
| 95 | - { |
|
| 96 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 97 | - define('ANS_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param WP $WP |
|
| 104 | - * @return void |
|
| 105 | - */ |
|
| 106 | - public function run($WP) |
|
| 107 | - { |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @return void |
|
| 114 | - */ |
|
| 115 | - public static function translate_js_strings() |
|
| 116 | - { |
|
| 117 | - EE_Registry::$i18n_js_strings['ans_no_country'] = __('In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 118 | - 'event_espresso'); |
|
| 119 | - EE_Registry::$i18n_js_strings['ans_no_name'] = __('In order to proceed, you need to enter the name of your State/Province.', |
|
| 120 | - 'event_espresso'); |
|
| 121 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = __('In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 122 | - 'event_espresso'); |
|
| 123 | - EE_Registry::$i18n_js_strings['ans_save_success'] = __('The new state was successfully saved to the database.', |
|
| 124 | - 'event_espresso'); |
|
| 125 | - EE_Registry::$i18n_js_strings['ans_server_save_error'] = __('An unknown error has occurred on the server while saving the new state to the database.', |
|
| 126 | - 'event_espresso'); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @return void |
|
| 133 | - */ |
|
| 134 | - public static function wp_enqueue_scripts() |
|
| 135 | - { |
|
| 136 | - if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 137 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
| 138 | - array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
| 139 | - wp_enqueue_script('add_new_state'); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * display_add_new_state_micro_form |
|
| 147 | - * |
|
| 148 | - * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 149 | - * @return string |
|
| 150 | - * @throws EE_Error |
|
| 151 | - */ |
|
| 152 | - // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
| 153 | - public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 154 | - { |
|
| 155 | - // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 156 | - // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 157 | - $action = EE_Registry::instance()->REQ->get('action', ''); |
|
| 158 | - // is the "state" question in this form section? |
|
| 159 | - $input = $question_group_reg_form->get_subsection('state'); |
|
| 160 | - if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 161 | - //ok then all we need to do is make sure the input's HTML name is consistent |
|
| 162 | - //by forcing it to set it now, like it did while getting the form for display |
|
| 163 | - if ($input instanceof EE_State_Select_Input) { |
|
| 164 | - $input->html_name(); |
|
| 165 | - } |
|
| 166 | - return $question_group_reg_form; |
|
| 167 | - } |
|
| 168 | - // we're only doing this for state select inputs |
|
| 169 | - if ($input instanceof EE_State_Select_Input) { |
|
| 170 | - // grab any set values from the request |
|
| 171 | - $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 172 | - $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 173 | - $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 174 | - $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 175 | - $country_options = array(); |
|
| 176 | - $countries = EEM_Country::instance()->get_all_countries(); |
|
| 177 | - if (! empty($countries)) { |
|
| 178 | - foreach ($countries as $country) { |
|
| 179 | - if ($country instanceof EE_Country) { |
|
| 180 | - $country_options[$country->ID()] = $country->name(); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 185 | - array( |
|
| 186 | - 'name' => 'new_state_micro_form', |
|
| 187 | - 'html_id' => 'new_state_micro_form', |
|
| 188 | - 'layout_strategy' => new EE_No_Layout(), |
|
| 189 | - 'subsections' => array( |
|
| 190 | - // add hidden input to indicate that a new state is being added |
|
| 191 | - 'add_new_state' => new EE_Hidden_Input( |
|
| 192 | - array( |
|
| 193 | - 'html_name' => str_replace('state', 'nsmf_add_new_state', $input->html_name()), |
|
| 194 | - 'html_id' => str_replace('state', 'nsmf_add_new_state', $input->html_id()), |
|
| 195 | - 'default' => 0, |
|
| 196 | - ) |
|
| 197 | - ), |
|
| 198 | - // add link for displaying hidden container |
|
| 199 | - 'click_here_link' => new EE_Form_Section_HTML( |
|
| 200 | - apply_filters( |
|
| 201 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 202 | - EEH_HTML::link( |
|
| 203 | - '', |
|
| 204 | - __('click here to add a new state/province', 'event_espresso'), |
|
| 205 | - '', |
|
| 206 | - 'display-' . $input->html_id(), |
|
| 207 | - 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 208 | - '', |
|
| 209 | - 'data-target="' . $input->html_id() . '"' |
|
| 210 | - ) |
|
| 211 | - ) |
|
| 212 | - ), |
|
| 213 | - // add initial html for hidden container |
|
| 214 | - 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 215 | - apply_filters( |
|
| 216 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 217 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
| 218 | - 'display: none;') . |
|
| 219 | - EEH_HTML::h6(__('If your State/Province does not appear in the list above, you can easily add it by doing the following:', |
|
| 220 | - 'event_espresso')) . |
|
| 221 | - EEH_HTML::ul() . |
|
| 222 | - EEH_HTML::li(__('first select the Country that your State/Province belongs to', |
|
| 223 | - 'event_espresso')) . |
|
| 224 | - EEH_HTML::li(__('enter the name of your State/Province', 'event_espresso')) . |
|
| 225 | - EEH_HTML::li(__('enter a two to six letter abbreviation for the name of your State/Province', |
|
| 226 | - 'event_espresso')) . |
|
| 227 | - EEH_HTML::li(__('click the ADD button', 'event_espresso')) . |
|
| 228 | - EEH_HTML::ulx() |
|
| 229 | - ) |
|
| 230 | - ), |
|
| 231 | - // NEW STATE COUNTRY |
|
| 232 | - 'new_state_country' => new EE_Country_Select_Input( |
|
| 233 | - $country_options, |
|
| 234 | - array( |
|
| 235 | - 'html_name' => $country_name, |
|
| 236 | - 'html_id' => str_replace('state', 'nsmf_new_state_country', $input->html_id()), |
|
| 237 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
| 238 | - 'html_label_text' => __('New State/Province Country', 'event_espresso'), |
|
| 239 | - 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
| 240 | - 'required' => false, |
|
| 241 | - ) |
|
| 242 | - ), |
|
| 243 | - // NEW STATE NAME |
|
| 244 | - 'new_state_name' => new EE_Text_Input( |
|
| 245 | - array( |
|
| 246 | - 'html_name' => $state_name, |
|
| 247 | - 'html_id' => str_replace('state', 'nsmf_new_state_name', $input->html_id()), |
|
| 248 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
| 249 | - 'html_label_text' => __('New State/Province Name', 'event_espresso'), |
|
| 250 | - 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
| 251 | - 'required' => false, |
|
| 252 | - ) |
|
| 253 | - ), |
|
| 254 | - 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
| 255 | - // NEW STATE NAME |
|
| 256 | - 'new_state_abbrv' => new EE_Text_Input( |
|
| 257 | - array( |
|
| 258 | - 'html_name' => $abbrv_name, |
|
| 259 | - 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
| 260 | - $input->html_id()), |
|
| 261 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 262 | - 'html_label_text' => __('New State/Province Abbreviation', 'event_espresso'), |
|
| 263 | - 'html_other_attributes' => 'size="24"', |
|
| 264 | - 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
| 265 | - 'required' => false, |
|
| 266 | - ) |
|
| 267 | - ), |
|
| 268 | - // "submit" button |
|
| 269 | - 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 270 | - apply_filters( |
|
| 271 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 272 | - EEH_HTML::nbsp(3) . |
|
| 273 | - EEH_HTML::link( |
|
| 274 | - '', |
|
| 275 | - __('ADD', 'event_espresso'), |
|
| 276 | - '', |
|
| 277 | - 'submit-' . $new_state_submit_id, |
|
| 278 | - 'ee-form-add-new-state-submit button button-secondary', |
|
| 279 | - '', |
|
| 280 | - 'data-target="' . $new_state_submit_id . '"' |
|
| 281 | - ) |
|
| 282 | - ) |
|
| 283 | - ), |
|
| 284 | - // extra info |
|
| 285 | - 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 286 | - apply_filters( |
|
| 287 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 288 | - EEH_HTML::br(2) |
|
| 289 | - . |
|
| 290 | - EEH_HTML::div('', '', 'small-text') |
|
| 291 | - . |
|
| 292 | - EEH_HTML::strong(__('Don\'t know your State/Province Abbreviation?', 'event_espresso')) |
|
| 293 | - . |
|
| 294 | - EEH_HTML::br() |
|
| 295 | - . |
|
| 296 | - sprintf( |
|
| 297 | - __('You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 298 | - 'event_espresso'), |
|
| 299 | - EEH_HTML::link('http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 300 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', '', '', |
|
| 301 | - 'ee-form-add-new-state-wiki-lnk') |
|
| 302 | - ) |
|
| 303 | - . |
|
| 304 | - EEH_HTML::divx() |
|
| 305 | - . |
|
| 306 | - EEH_HTML::br() |
|
| 307 | - . |
|
| 308 | - EEH_HTML::link('', __('cancel new state/province', 'event_espresso'), '', |
|
| 309 | - 'hide-' . $input->html_id(), 'ee-form-cancel-new-state-lnk smaller-text', '', |
|
| 310 | - 'data-target="' . $input->html_id() . '"') |
|
| 311 | - . |
|
| 312 | - EEH_HTML::divx() |
|
| 313 | - . |
|
| 314 | - EEH_HTML::br() |
|
| 315 | - ) |
|
| 316 | - ), |
|
| 317 | - ), |
|
| 318 | - ) |
|
| 319 | - ); |
|
| 320 | - $question_group_reg_form->add_subsections(array('new_state_micro_form' => $new_state_micro_form), 'state', |
|
| 321 | - false); |
|
| 322 | - } |
|
| 323 | - return $question_group_reg_form; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * set_new_state_input_width |
|
| 330 | - * |
|
| 331 | - * @return int|string |
|
| 332 | - * @throws EE_Error |
|
| 333 | - */ |
|
| 334 | - public static function add_new_state() |
|
| 335 | - { |
|
| 336 | - $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
| 337 | - if ( absint($REQ->get('nsmf_add_new_state')) === 1 ) { |
|
| 338 | - EE_Registry::instance()->load_model('State'); |
|
| 339 | - // grab country ISO code, new state name, and new state abbreviation |
|
| 340 | - $state_country = $REQ->is_set('nsmf_new_state_country') |
|
| 341 | - ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
| 342 | - : false; |
|
| 343 | - $state_name = $REQ->is_set('nsmf_new_state_name') |
|
| 344 | - ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
| 345 | - : false; |
|
| 346 | - $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
| 347 | - ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
| 348 | - : false; |
|
| 349 | - if ($state_country && $state_name && $state_abbr) { |
|
| 350 | - $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
| 351 | - 'CNT_ISO' => strtoupper($state_country), |
|
| 352 | - 'STA_abbrev' => strtoupper($state_abbr), |
|
| 353 | - 'STA_name' => ucwords($state_name), |
|
| 354 | - 'STA_active' => false, |
|
| 355 | - )); |
|
| 356 | - if ($new_state instanceof EE_State) { |
|
| 357 | - // clean house |
|
| 358 | - EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
| 359 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
| 360 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
| 361 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
| 362 | - // get any existing new states |
|
| 363 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 364 | - 'nsmf_new_states' |
|
| 365 | - ); |
|
| 366 | - $new_states[$new_state->ID()] = $new_state; |
|
| 367 | - EE_Registry::instance()->SSN->set_session_data( |
|
| 368 | - array('nsmf_new_states' => $new_states) |
|
| 369 | - ); |
|
| 370 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 371 | - echo wp_json_encode(array( |
|
| 372 | - 'success' => true, |
|
| 373 | - 'id' => $new_state->ID(), |
|
| 374 | - 'name' => $new_state->name(), |
|
| 375 | - 'abbrev' => $new_state->abbrev(), |
|
| 376 | - 'country_iso' => $new_state->country_iso(), |
|
| 377 | - 'country_name' => $new_state->country()->name(), |
|
| 378 | - )); |
|
| 379 | - exit(); |
|
| 380 | - } |
|
| 381 | - return $new_state->ID(); |
|
| 382 | - } |
|
| 383 | - } else { |
|
| 384 | - $error = __('A new State/Province could not be added because invalid or missing data was received.', |
|
| 385 | - 'event_espresso'); |
|
| 386 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 387 | - echo wp_json_encode(array('error' => $error)); |
|
| 388 | - exit(); |
|
| 389 | - } |
|
| 390 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - return false; |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * recursively drills down through request params to remove any that were added by this module |
|
| 400 | - * |
|
| 401 | - * @param array $request_params |
|
| 402 | - * @return array |
|
| 403 | - */ |
|
| 404 | - public static function filter_checkout_request_params($request_params) |
|
| 405 | - { |
|
| 406 | - foreach ($request_params as $form_section) { |
|
| 407 | - if (is_array($form_section)) { |
|
| 408 | - EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 409 | - EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - return $request_params; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * @param array $request_params |
|
| 419 | - * @return array |
|
| 420 | - */ |
|
| 421 | - public static function unset_new_state_request_params($request_params) |
|
| 422 | - { |
|
| 423 | - unset( |
|
| 424 | - $request_params['new_state_micro_form'], |
|
| 425 | - $request_params['new_state_micro_add_new_state'], |
|
| 426 | - $request_params['new_state_micro_new_state_country'], |
|
| 427 | - $request_params['new_state_micro_new_state_name'], |
|
| 428 | - $request_params['new_state_micro_new_state_abbrv'] |
|
| 429 | - ); |
|
| 430 | - return $request_params; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * @param array $props_n_values |
|
| 437 | - * @return bool |
|
| 438 | - * @throws EE_Error |
|
| 439 | - */ |
|
| 440 | - public static function save_new_state_to_db($props_n_values = array()) |
|
| 441 | - { |
|
| 442 | - $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
| 443 | - if (! empty($existing_state)) { |
|
| 444 | - return array_pop($existing_state); |
|
| 445 | - } |
|
| 446 | - $new_state = EE_State::new_instance($props_n_values); |
|
| 447 | - if ($new_state instanceof EE_State) { |
|
| 448 | - // if not non-ajax admin |
|
| 449 | - $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
| 450 | - $new_state_notice = sprintf( |
|
| 451 | - __('A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
| 452 | - 'event_espresso'), |
|
| 453 | - '<b>' . $new_state->name() . '</b>', |
|
| 454 | - '<b>' . $new_state->abbrev() . '</b>', |
|
| 455 | - '<b>' . $new_state->country()->name() . '</b>', |
|
| 456 | - '<a href="' . add_query_arg(array( |
|
| 457 | - 'page' => 'espresso_general_settings', |
|
| 458 | - 'action' => 'country_settings', |
|
| 459 | - 'country' => $new_state->country_iso(), |
|
| 460 | - ), admin_url('admin.php')) . '">' . __('Event Espresso - General Settings > Countries Tab', |
|
| 461 | - 'event_espresso') . '</a>', |
|
| 462 | - '<br />' |
|
| 463 | - ); |
|
| 464 | - EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
|
| 465 | - $new_state->save(); |
|
| 466 | - EEM_State::instance()->reset_cached_states(); |
|
| 467 | - return $new_state; |
|
| 468 | - } |
|
| 469 | - return false; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * @param string $CNT_ISO |
|
| 476 | - * @param string $STA_ID |
|
| 477 | - * @param array $cols_n_values |
|
| 478 | - * @return void |
|
| 479 | - */ |
|
| 480 | - public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
| 481 | - { |
|
| 482 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : false; |
|
| 483 | - if (! $CNT_ISO) { |
|
| 484 | - EE_Error::add_error(__('An invalid or missing Country ISO Code was received.', 'event_espresso'), __FILE__, |
|
| 485 | - __FUNCTION__, __LINE__); |
|
| 486 | - } |
|
| 487 | - $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 488 | - : false; |
|
| 489 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 490 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 491 | - if ($state instanceof EE_State) { |
|
| 492 | - $STA_abbrev = $state->abbrev(); |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - if (! $STA_abbrev) { |
|
| 496 | - EE_Error::add_error(__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 497 | - __FILE__, __FUNCTION__, __LINE__); |
|
| 498 | - } |
|
| 499 | - EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * @param EE_State[] $state_options |
|
| 506 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 507 | - * @param EE_Registration $registration |
|
| 508 | - * @param EE_Question $question |
|
| 509 | - * @param $answer |
|
| 510 | - * @return array |
|
| 511 | - */ |
|
| 512 | - public static function inject_new_reg_state_into_options( |
|
| 513 | - $state_options = array(), |
|
| 514 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 515 | - EE_Registration $registration, |
|
| 516 | - EE_Question $question, |
|
| 517 | - $answer |
|
| 518 | - ) { |
|
| 519 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 520 | - && $question->type() |
|
| 521 | - === EEM_Question::QST_type_state |
|
| 522 | - ) { |
|
| 523 | - $STA_ID = $answer->value(); |
|
| 524 | - if (! empty($STA_ID)) { |
|
| 525 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 526 | - if ($state instanceof EE_State) { |
|
| 527 | - $country = $state->country(); |
|
| 528 | - if ($country instanceof EE_Country) { |
|
| 529 | - if (! isset($state_options[$country->name()])) { |
|
| 530 | - $state_options[$country->name()] = array(); |
|
| 531 | - } |
|
| 532 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
| 533 | - $state_options[$country->name()][$STA_ID] = $state->name(); |
|
| 534 | - } |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - return $state_options; |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * @param EE_Country[] $country_options |
|
| 546 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 547 | - * @param EE_Registration $registration |
|
| 548 | - * @param EE_Question $question |
|
| 549 | - * @param $answer |
|
| 550 | - * @return array |
|
| 551 | - */ |
|
| 552 | - public static function inject_new_reg_country_into_options( |
|
| 553 | - $country_options = array(), |
|
| 554 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 555 | - EE_Registration $registration, |
|
| 556 | - EE_Question $question, |
|
| 557 | - $answer |
|
| 558 | - ) { |
|
| 559 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 560 | - && $question->type() |
|
| 561 | - === EEM_Question::QST_type_country |
|
| 562 | - ) { |
|
| 563 | - $CNT_ISO = $answer->value(); |
|
| 564 | - if (! empty($CNT_ISO)) { |
|
| 565 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 566 | - if ($country instanceof EE_Country) { |
|
| 567 | - if (! isset($country_options[$CNT_ISO])) { |
|
| 568 | - $country_options[$CNT_ISO] = $country->name(); |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - } |
|
| 572 | - } |
|
| 573 | - return $country_options; |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * @param EE_State[] $state_options |
|
| 580 | - * @return array |
|
| 581 | - * @throws EE_Error |
|
| 582 | - */ |
|
| 583 | - public static function state_options($state_options = array()) |
|
| 584 | - { |
|
| 585 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 586 | - foreach ($new_states as $new_state) { |
|
| 587 | - if ( |
|
| 588 | - $new_state instanceof EE_State |
|
| 589 | - && $new_state->country() instanceof EE_Country |
|
| 590 | - ) { |
|
| 591 | - $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
| 592 | - } |
|
| 593 | - } |
|
| 594 | - return $state_options; |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - |
|
| 598 | - |
|
| 599 | - /** |
|
| 600 | - * @return array |
|
| 601 | - */ |
|
| 602 | - protected static function _get_new_states() |
|
| 603 | - { |
|
| 604 | - $new_states = array(); |
|
| 605 | - if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 606 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 607 | - 'nsmf_new_states' |
|
| 608 | - ); |
|
| 609 | - } |
|
| 610 | - return is_array($new_states) ? $new_states : array(); |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * @param EE_Country[] $country_options |
|
| 617 | - * @return array |
|
| 618 | - * @throws EE_Error |
|
| 619 | - */ |
|
| 620 | - public static function country_options($country_options = array()) |
|
| 621 | - { |
|
| 622 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 623 | - foreach ($new_states as $new_state) { |
|
| 624 | - if ( |
|
| 625 | - $new_state instanceof EE_State |
|
| 626 | - && $new_state->country() instanceof EE_Country |
|
| 627 | - ) { |
|
| 628 | - $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
| 629 | - } |
|
| 630 | - } |
|
| 631 | - return $country_options; |
|
| 632 | - } |
|
| 19 | + /** |
|
| 20 | + * @return EED_Module|EED_Add_New_State |
|
| 21 | + */ |
|
| 22 | + public static function instance() |
|
| 23 | + { |
|
| 24 | + return parent::get_instance(__CLASS__); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 31 | + * |
|
| 32 | + * @return void |
|
| 33 | + */ |
|
| 34 | + public static function set_hooks() |
|
| 35 | + { |
|
| 36 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 37 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
| 38 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
| 39 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 40 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 41 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 42 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 43 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 44 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 45 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 46 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 47 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 48 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 49 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 50 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 51 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 52 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 59 | + * |
|
| 60 | + * @return void |
|
| 61 | + */ |
|
| 62 | + public static function set_hooks_admin() |
|
| 63 | + { |
|
| 64 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 65 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 66 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 67 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 68 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 69 | + add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 70 | + add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 71 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 72 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 73 | + add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 74 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 75 | + add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 76 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 77 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 78 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 79 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 80 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 81 | + add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 82 | + array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
| 83 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 84 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 85 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 86 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @return void |
|
| 93 | + */ |
|
| 94 | + public static function set_definitions() |
|
| 95 | + { |
|
| 96 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 97 | + define('ANS_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param WP $WP |
|
| 104 | + * @return void |
|
| 105 | + */ |
|
| 106 | + public function run($WP) |
|
| 107 | + { |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @return void |
|
| 114 | + */ |
|
| 115 | + public static function translate_js_strings() |
|
| 116 | + { |
|
| 117 | + EE_Registry::$i18n_js_strings['ans_no_country'] = __('In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 118 | + 'event_espresso'); |
|
| 119 | + EE_Registry::$i18n_js_strings['ans_no_name'] = __('In order to proceed, you need to enter the name of your State/Province.', |
|
| 120 | + 'event_espresso'); |
|
| 121 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = __('In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 122 | + 'event_espresso'); |
|
| 123 | + EE_Registry::$i18n_js_strings['ans_save_success'] = __('The new state was successfully saved to the database.', |
|
| 124 | + 'event_espresso'); |
|
| 125 | + EE_Registry::$i18n_js_strings['ans_server_save_error'] = __('An unknown error has occurred on the server while saving the new state to the database.', |
|
| 126 | + 'event_espresso'); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @return void |
|
| 133 | + */ |
|
| 134 | + public static function wp_enqueue_scripts() |
|
| 135 | + { |
|
| 136 | + if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 137 | + wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
| 138 | + array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
| 139 | + wp_enqueue_script('add_new_state'); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * display_add_new_state_micro_form |
|
| 147 | + * |
|
| 148 | + * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 149 | + * @return string |
|
| 150 | + * @throws EE_Error |
|
| 151 | + */ |
|
| 152 | + // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
| 153 | + public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 154 | + { |
|
| 155 | + // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 156 | + // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 157 | + $action = EE_Registry::instance()->REQ->get('action', ''); |
|
| 158 | + // is the "state" question in this form section? |
|
| 159 | + $input = $question_group_reg_form->get_subsection('state'); |
|
| 160 | + if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 161 | + //ok then all we need to do is make sure the input's HTML name is consistent |
|
| 162 | + //by forcing it to set it now, like it did while getting the form for display |
|
| 163 | + if ($input instanceof EE_State_Select_Input) { |
|
| 164 | + $input->html_name(); |
|
| 165 | + } |
|
| 166 | + return $question_group_reg_form; |
|
| 167 | + } |
|
| 168 | + // we're only doing this for state select inputs |
|
| 169 | + if ($input instanceof EE_State_Select_Input) { |
|
| 170 | + // grab any set values from the request |
|
| 171 | + $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 172 | + $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 173 | + $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 174 | + $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 175 | + $country_options = array(); |
|
| 176 | + $countries = EEM_Country::instance()->get_all_countries(); |
|
| 177 | + if (! empty($countries)) { |
|
| 178 | + foreach ($countries as $country) { |
|
| 179 | + if ($country instanceof EE_Country) { |
|
| 180 | + $country_options[$country->ID()] = $country->name(); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 185 | + array( |
|
| 186 | + 'name' => 'new_state_micro_form', |
|
| 187 | + 'html_id' => 'new_state_micro_form', |
|
| 188 | + 'layout_strategy' => new EE_No_Layout(), |
|
| 189 | + 'subsections' => array( |
|
| 190 | + // add hidden input to indicate that a new state is being added |
|
| 191 | + 'add_new_state' => new EE_Hidden_Input( |
|
| 192 | + array( |
|
| 193 | + 'html_name' => str_replace('state', 'nsmf_add_new_state', $input->html_name()), |
|
| 194 | + 'html_id' => str_replace('state', 'nsmf_add_new_state', $input->html_id()), |
|
| 195 | + 'default' => 0, |
|
| 196 | + ) |
|
| 197 | + ), |
|
| 198 | + // add link for displaying hidden container |
|
| 199 | + 'click_here_link' => new EE_Form_Section_HTML( |
|
| 200 | + apply_filters( |
|
| 201 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 202 | + EEH_HTML::link( |
|
| 203 | + '', |
|
| 204 | + __('click here to add a new state/province', 'event_espresso'), |
|
| 205 | + '', |
|
| 206 | + 'display-' . $input->html_id(), |
|
| 207 | + 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 208 | + '', |
|
| 209 | + 'data-target="' . $input->html_id() . '"' |
|
| 210 | + ) |
|
| 211 | + ) |
|
| 212 | + ), |
|
| 213 | + // add initial html for hidden container |
|
| 214 | + 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 215 | + apply_filters( |
|
| 216 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 217 | + EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
| 218 | + 'display: none;') . |
|
| 219 | + EEH_HTML::h6(__('If your State/Province does not appear in the list above, you can easily add it by doing the following:', |
|
| 220 | + 'event_espresso')) . |
|
| 221 | + EEH_HTML::ul() . |
|
| 222 | + EEH_HTML::li(__('first select the Country that your State/Province belongs to', |
|
| 223 | + 'event_espresso')) . |
|
| 224 | + EEH_HTML::li(__('enter the name of your State/Province', 'event_espresso')) . |
|
| 225 | + EEH_HTML::li(__('enter a two to six letter abbreviation for the name of your State/Province', |
|
| 226 | + 'event_espresso')) . |
|
| 227 | + EEH_HTML::li(__('click the ADD button', 'event_espresso')) . |
|
| 228 | + EEH_HTML::ulx() |
|
| 229 | + ) |
|
| 230 | + ), |
|
| 231 | + // NEW STATE COUNTRY |
|
| 232 | + 'new_state_country' => new EE_Country_Select_Input( |
|
| 233 | + $country_options, |
|
| 234 | + array( |
|
| 235 | + 'html_name' => $country_name, |
|
| 236 | + 'html_id' => str_replace('state', 'nsmf_new_state_country', $input->html_id()), |
|
| 237 | + 'html_class' => $input->html_class() . ' new-state-country', |
|
| 238 | + 'html_label_text' => __('New State/Province Country', 'event_espresso'), |
|
| 239 | + 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
| 240 | + 'required' => false, |
|
| 241 | + ) |
|
| 242 | + ), |
|
| 243 | + // NEW STATE NAME |
|
| 244 | + 'new_state_name' => new EE_Text_Input( |
|
| 245 | + array( |
|
| 246 | + 'html_name' => $state_name, |
|
| 247 | + 'html_id' => str_replace('state', 'nsmf_new_state_name', $input->html_id()), |
|
| 248 | + 'html_class' => $input->html_class() . ' new-state-state', |
|
| 249 | + 'html_label_text' => __('New State/Province Name', 'event_espresso'), |
|
| 250 | + 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
| 251 | + 'required' => false, |
|
| 252 | + ) |
|
| 253 | + ), |
|
| 254 | + 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
| 255 | + // NEW STATE NAME |
|
| 256 | + 'new_state_abbrv' => new EE_Text_Input( |
|
| 257 | + array( |
|
| 258 | + 'html_name' => $abbrv_name, |
|
| 259 | + 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
| 260 | + $input->html_id()), |
|
| 261 | + 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 262 | + 'html_label_text' => __('New State/Province Abbreviation', 'event_espresso'), |
|
| 263 | + 'html_other_attributes' => 'size="24"', |
|
| 264 | + 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
| 265 | + 'required' => false, |
|
| 266 | + ) |
|
| 267 | + ), |
|
| 268 | + // "submit" button |
|
| 269 | + 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 270 | + apply_filters( |
|
| 271 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 272 | + EEH_HTML::nbsp(3) . |
|
| 273 | + EEH_HTML::link( |
|
| 274 | + '', |
|
| 275 | + __('ADD', 'event_espresso'), |
|
| 276 | + '', |
|
| 277 | + 'submit-' . $new_state_submit_id, |
|
| 278 | + 'ee-form-add-new-state-submit button button-secondary', |
|
| 279 | + '', |
|
| 280 | + 'data-target="' . $new_state_submit_id . '"' |
|
| 281 | + ) |
|
| 282 | + ) |
|
| 283 | + ), |
|
| 284 | + // extra info |
|
| 285 | + 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 286 | + apply_filters( |
|
| 287 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 288 | + EEH_HTML::br(2) |
|
| 289 | + . |
|
| 290 | + EEH_HTML::div('', '', 'small-text') |
|
| 291 | + . |
|
| 292 | + EEH_HTML::strong(__('Don\'t know your State/Province Abbreviation?', 'event_espresso')) |
|
| 293 | + . |
|
| 294 | + EEH_HTML::br() |
|
| 295 | + . |
|
| 296 | + sprintf( |
|
| 297 | + __('You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 298 | + 'event_espresso'), |
|
| 299 | + EEH_HTML::link('http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 300 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', '', '', |
|
| 301 | + 'ee-form-add-new-state-wiki-lnk') |
|
| 302 | + ) |
|
| 303 | + . |
|
| 304 | + EEH_HTML::divx() |
|
| 305 | + . |
|
| 306 | + EEH_HTML::br() |
|
| 307 | + . |
|
| 308 | + EEH_HTML::link('', __('cancel new state/province', 'event_espresso'), '', |
|
| 309 | + 'hide-' . $input->html_id(), 'ee-form-cancel-new-state-lnk smaller-text', '', |
|
| 310 | + 'data-target="' . $input->html_id() . '"') |
|
| 311 | + . |
|
| 312 | + EEH_HTML::divx() |
|
| 313 | + . |
|
| 314 | + EEH_HTML::br() |
|
| 315 | + ) |
|
| 316 | + ), |
|
| 317 | + ), |
|
| 318 | + ) |
|
| 319 | + ); |
|
| 320 | + $question_group_reg_form->add_subsections(array('new_state_micro_form' => $new_state_micro_form), 'state', |
|
| 321 | + false); |
|
| 322 | + } |
|
| 323 | + return $question_group_reg_form; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * set_new_state_input_width |
|
| 330 | + * |
|
| 331 | + * @return int|string |
|
| 332 | + * @throws EE_Error |
|
| 333 | + */ |
|
| 334 | + public static function add_new_state() |
|
| 335 | + { |
|
| 336 | + $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
| 337 | + if ( absint($REQ->get('nsmf_add_new_state')) === 1 ) { |
|
| 338 | + EE_Registry::instance()->load_model('State'); |
|
| 339 | + // grab country ISO code, new state name, and new state abbreviation |
|
| 340 | + $state_country = $REQ->is_set('nsmf_new_state_country') |
|
| 341 | + ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
| 342 | + : false; |
|
| 343 | + $state_name = $REQ->is_set('nsmf_new_state_name') |
|
| 344 | + ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
| 345 | + : false; |
|
| 346 | + $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
| 347 | + ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
| 348 | + : false; |
|
| 349 | + if ($state_country && $state_name && $state_abbr) { |
|
| 350 | + $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
| 351 | + 'CNT_ISO' => strtoupper($state_country), |
|
| 352 | + 'STA_abbrev' => strtoupper($state_abbr), |
|
| 353 | + 'STA_name' => ucwords($state_name), |
|
| 354 | + 'STA_active' => false, |
|
| 355 | + )); |
|
| 356 | + if ($new_state instanceof EE_State) { |
|
| 357 | + // clean house |
|
| 358 | + EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
| 359 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
| 360 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
| 361 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
| 362 | + // get any existing new states |
|
| 363 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 364 | + 'nsmf_new_states' |
|
| 365 | + ); |
|
| 366 | + $new_states[$new_state->ID()] = $new_state; |
|
| 367 | + EE_Registry::instance()->SSN->set_session_data( |
|
| 368 | + array('nsmf_new_states' => $new_states) |
|
| 369 | + ); |
|
| 370 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 371 | + echo wp_json_encode(array( |
|
| 372 | + 'success' => true, |
|
| 373 | + 'id' => $new_state->ID(), |
|
| 374 | + 'name' => $new_state->name(), |
|
| 375 | + 'abbrev' => $new_state->abbrev(), |
|
| 376 | + 'country_iso' => $new_state->country_iso(), |
|
| 377 | + 'country_name' => $new_state->country()->name(), |
|
| 378 | + )); |
|
| 379 | + exit(); |
|
| 380 | + } |
|
| 381 | + return $new_state->ID(); |
|
| 382 | + } |
|
| 383 | + } else { |
|
| 384 | + $error = __('A new State/Province could not be added because invalid or missing data was received.', |
|
| 385 | + 'event_espresso'); |
|
| 386 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 387 | + echo wp_json_encode(array('error' => $error)); |
|
| 388 | + exit(); |
|
| 389 | + } |
|
| 390 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + return false; |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * recursively drills down through request params to remove any that were added by this module |
|
| 400 | + * |
|
| 401 | + * @param array $request_params |
|
| 402 | + * @return array |
|
| 403 | + */ |
|
| 404 | + public static function filter_checkout_request_params($request_params) |
|
| 405 | + { |
|
| 406 | + foreach ($request_params as $form_section) { |
|
| 407 | + if (is_array($form_section)) { |
|
| 408 | + EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 409 | + EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + return $request_params; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * @param array $request_params |
|
| 419 | + * @return array |
|
| 420 | + */ |
|
| 421 | + public static function unset_new_state_request_params($request_params) |
|
| 422 | + { |
|
| 423 | + unset( |
|
| 424 | + $request_params['new_state_micro_form'], |
|
| 425 | + $request_params['new_state_micro_add_new_state'], |
|
| 426 | + $request_params['new_state_micro_new_state_country'], |
|
| 427 | + $request_params['new_state_micro_new_state_name'], |
|
| 428 | + $request_params['new_state_micro_new_state_abbrv'] |
|
| 429 | + ); |
|
| 430 | + return $request_params; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * @param array $props_n_values |
|
| 437 | + * @return bool |
|
| 438 | + * @throws EE_Error |
|
| 439 | + */ |
|
| 440 | + public static function save_new_state_to_db($props_n_values = array()) |
|
| 441 | + { |
|
| 442 | + $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
| 443 | + if (! empty($existing_state)) { |
|
| 444 | + return array_pop($existing_state); |
|
| 445 | + } |
|
| 446 | + $new_state = EE_State::new_instance($props_n_values); |
|
| 447 | + if ($new_state instanceof EE_State) { |
|
| 448 | + // if not non-ajax admin |
|
| 449 | + $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
| 450 | + $new_state_notice = sprintf( |
|
| 451 | + __('A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
| 452 | + 'event_espresso'), |
|
| 453 | + '<b>' . $new_state->name() . '</b>', |
|
| 454 | + '<b>' . $new_state->abbrev() . '</b>', |
|
| 455 | + '<b>' . $new_state->country()->name() . '</b>', |
|
| 456 | + '<a href="' . add_query_arg(array( |
|
| 457 | + 'page' => 'espresso_general_settings', |
|
| 458 | + 'action' => 'country_settings', |
|
| 459 | + 'country' => $new_state->country_iso(), |
|
| 460 | + ), admin_url('admin.php')) . '">' . __('Event Espresso - General Settings > Countries Tab', |
|
| 461 | + 'event_espresso') . '</a>', |
|
| 462 | + '<br />' |
|
| 463 | + ); |
|
| 464 | + EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
|
| 465 | + $new_state->save(); |
|
| 466 | + EEM_State::instance()->reset_cached_states(); |
|
| 467 | + return $new_state; |
|
| 468 | + } |
|
| 469 | + return false; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * @param string $CNT_ISO |
|
| 476 | + * @param string $STA_ID |
|
| 477 | + * @param array $cols_n_values |
|
| 478 | + * @return void |
|
| 479 | + */ |
|
| 480 | + public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
| 481 | + { |
|
| 482 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : false; |
|
| 483 | + if (! $CNT_ISO) { |
|
| 484 | + EE_Error::add_error(__('An invalid or missing Country ISO Code was received.', 'event_espresso'), __FILE__, |
|
| 485 | + __FUNCTION__, __LINE__); |
|
| 486 | + } |
|
| 487 | + $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 488 | + : false; |
|
| 489 | + if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 490 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 491 | + if ($state instanceof EE_State) { |
|
| 492 | + $STA_abbrev = $state->abbrev(); |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + if (! $STA_abbrev) { |
|
| 496 | + EE_Error::add_error(__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 497 | + __FILE__, __FUNCTION__, __LINE__); |
|
| 498 | + } |
|
| 499 | + EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * @param EE_State[] $state_options |
|
| 506 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 507 | + * @param EE_Registration $registration |
|
| 508 | + * @param EE_Question $question |
|
| 509 | + * @param $answer |
|
| 510 | + * @return array |
|
| 511 | + */ |
|
| 512 | + public static function inject_new_reg_state_into_options( |
|
| 513 | + $state_options = array(), |
|
| 514 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 515 | + EE_Registration $registration, |
|
| 516 | + EE_Question $question, |
|
| 517 | + $answer |
|
| 518 | + ) { |
|
| 519 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 520 | + && $question->type() |
|
| 521 | + === EEM_Question::QST_type_state |
|
| 522 | + ) { |
|
| 523 | + $STA_ID = $answer->value(); |
|
| 524 | + if (! empty($STA_ID)) { |
|
| 525 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 526 | + if ($state instanceof EE_State) { |
|
| 527 | + $country = $state->country(); |
|
| 528 | + if ($country instanceof EE_Country) { |
|
| 529 | + if (! isset($state_options[$country->name()])) { |
|
| 530 | + $state_options[$country->name()] = array(); |
|
| 531 | + } |
|
| 532 | + if (! isset($state_options[$country->name()][$STA_ID])) { |
|
| 533 | + $state_options[$country->name()][$STA_ID] = $state->name(); |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + return $state_options; |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * @param EE_Country[] $country_options |
|
| 546 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 547 | + * @param EE_Registration $registration |
|
| 548 | + * @param EE_Question $question |
|
| 549 | + * @param $answer |
|
| 550 | + * @return array |
|
| 551 | + */ |
|
| 552 | + public static function inject_new_reg_country_into_options( |
|
| 553 | + $country_options = array(), |
|
| 554 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 555 | + EE_Registration $registration, |
|
| 556 | + EE_Question $question, |
|
| 557 | + $answer |
|
| 558 | + ) { |
|
| 559 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 560 | + && $question->type() |
|
| 561 | + === EEM_Question::QST_type_country |
|
| 562 | + ) { |
|
| 563 | + $CNT_ISO = $answer->value(); |
|
| 564 | + if (! empty($CNT_ISO)) { |
|
| 565 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 566 | + if ($country instanceof EE_Country) { |
|
| 567 | + if (! isset($country_options[$CNT_ISO])) { |
|
| 568 | + $country_options[$CNT_ISO] = $country->name(); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + } |
|
| 572 | + } |
|
| 573 | + return $country_options; |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * @param EE_State[] $state_options |
|
| 580 | + * @return array |
|
| 581 | + * @throws EE_Error |
|
| 582 | + */ |
|
| 583 | + public static function state_options($state_options = array()) |
|
| 584 | + { |
|
| 585 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 586 | + foreach ($new_states as $new_state) { |
|
| 587 | + if ( |
|
| 588 | + $new_state instanceof EE_State |
|
| 589 | + && $new_state->country() instanceof EE_Country |
|
| 590 | + ) { |
|
| 591 | + $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
| 592 | + } |
|
| 593 | + } |
|
| 594 | + return $state_options; |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + |
|
| 598 | + |
|
| 599 | + /** |
|
| 600 | + * @return array |
|
| 601 | + */ |
|
| 602 | + protected static function _get_new_states() |
|
| 603 | + { |
|
| 604 | + $new_states = array(); |
|
| 605 | + if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 606 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 607 | + 'nsmf_new_states' |
|
| 608 | + ); |
|
| 609 | + } |
|
| 610 | + return is_array($new_states) ? $new_states : array(); |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * @param EE_Country[] $country_options |
|
| 617 | + * @return array |
|
| 618 | + * @throws EE_Error |
|
| 619 | + */ |
|
| 620 | + public static function country_options($country_options = array()) |
|
| 621 | + { |
|
| 622 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 623 | + foreach ($new_states as $new_state) { |
|
| 624 | + if ( |
|
| 625 | + $new_state instanceof EE_State |
|
| 626 | + && $new_state->country() instanceof EE_Country |
|
| 627 | + ) { |
|
| 628 | + $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
| 629 | + } |
|
| 630 | + } |
|
| 631 | + return $country_options; |
|
| 632 | + } |
|
| 633 | 633 | |
| 634 | 634 | |
| 635 | 635 | |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | 2 | exit('No direct script access allowed'); |
| 3 | 3 | } |
| 4 | 4 | |
@@ -93,8 +93,8 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public static function set_definitions() |
| 95 | 95 | { |
| 96 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 97 | - define('ANS_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS); |
|
| 96 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
| 97 | + define('ANS_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | public static function wp_enqueue_scripts() |
| 135 | 135 | { |
| 136 | 136 | if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
| 137 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
| 137 | + wp_register_script('add_new_state', ANS_ASSETS_URL.'add_new_state.js', |
|
| 138 | 138 | array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
| 139 | 139 | wp_enqueue_script('add_new_state'); |
| 140 | 140 | } |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
| 175 | 175 | $country_options = array(); |
| 176 | 176 | $countries = EEM_Country::instance()->get_all_countries(); |
| 177 | - if (! empty($countries)) { |
|
| 177 | + if ( ! empty($countries)) { |
|
| 178 | 178 | foreach ($countries as $country) { |
| 179 | 179 | if ($country instanceof EE_Country) { |
| 180 | 180 | $country_options[$country->ID()] = $country->name(); |
@@ -203,10 +203,10 @@ discard block |
||
| 203 | 203 | '', |
| 204 | 204 | __('click here to add a new state/province', 'event_espresso'), |
| 205 | 205 | '', |
| 206 | - 'display-' . $input->html_id(), |
|
| 206 | + 'display-'.$input->html_id(), |
|
| 207 | 207 | 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
| 208 | 208 | '', |
| 209 | - 'data-target="' . $input->html_id() . '"' |
|
| 209 | + 'data-target="'.$input->html_id().'"' |
|
| 210 | 210 | ) |
| 211 | 211 | ) |
| 212 | 212 | ), |
@@ -214,17 +214,17 @@ discard block |
||
| 214 | 214 | 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
| 215 | 215 | apply_filters( |
| 216 | 216 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
| 217 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
| 218 | - 'display: none;') . |
|
| 217 | + EEH_HTML::div('', $input->html_id().'-dv', 'ee-form-add-new-state-dv', |
|
| 218 | + 'display: none;'). |
|
| 219 | 219 | EEH_HTML::h6(__('If your State/Province does not appear in the list above, you can easily add it by doing the following:', |
| 220 | - 'event_espresso')) . |
|
| 221 | - EEH_HTML::ul() . |
|
| 220 | + 'event_espresso')). |
|
| 221 | + EEH_HTML::ul(). |
|
| 222 | 222 | EEH_HTML::li(__('first select the Country that your State/Province belongs to', |
| 223 | - 'event_espresso')) . |
|
| 224 | - EEH_HTML::li(__('enter the name of your State/Province', 'event_espresso')) . |
|
| 223 | + 'event_espresso')). |
|
| 224 | + EEH_HTML::li(__('enter the name of your State/Province', 'event_espresso')). |
|
| 225 | 225 | EEH_HTML::li(__('enter a two to six letter abbreviation for the name of your State/Province', |
| 226 | - 'event_espresso')) . |
|
| 227 | - EEH_HTML::li(__('click the ADD button', 'event_espresso')) . |
|
| 226 | + 'event_espresso')). |
|
| 227 | + EEH_HTML::li(__('click the ADD button', 'event_espresso')). |
|
| 228 | 228 | EEH_HTML::ulx() |
| 229 | 229 | ) |
| 230 | 230 | ), |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | array( |
| 235 | 235 | 'html_name' => $country_name, |
| 236 | 236 | 'html_id' => str_replace('state', 'nsmf_new_state_country', $input->html_id()), |
| 237 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
| 237 | + 'html_class' => $input->html_class().' new-state-country', |
|
| 238 | 238 | 'html_label_text' => __('New State/Province Country', 'event_espresso'), |
| 239 | 239 | 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
| 240 | 240 | 'required' => false, |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | array( |
| 246 | 246 | 'html_name' => $state_name, |
| 247 | 247 | 'html_id' => str_replace('state', 'nsmf_new_state_name', $input->html_id()), |
| 248 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
| 248 | + 'html_class' => $input->html_class().' new-state-state', |
|
| 249 | 249 | 'html_label_text' => __('New State/Province Name', 'event_espresso'), |
| 250 | 250 | 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
| 251 | 251 | 'required' => false, |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | 'html_name' => $abbrv_name, |
| 259 | 259 | 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
| 260 | 260 | $input->html_id()), |
| 261 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 261 | + 'html_class' => $input->html_class().' new-state-abbrv', |
|
| 262 | 262 | 'html_label_text' => __('New State/Province Abbreviation', 'event_espresso'), |
| 263 | 263 | 'html_other_attributes' => 'size="24"', |
| 264 | 264 | 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
@@ -269,15 +269,15 @@ discard block |
||
| 269 | 269 | 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
| 270 | 270 | apply_filters( |
| 271 | 271 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
| 272 | - EEH_HTML::nbsp(3) . |
|
| 272 | + EEH_HTML::nbsp(3). |
|
| 273 | 273 | EEH_HTML::link( |
| 274 | 274 | '', |
| 275 | 275 | __('ADD', 'event_espresso'), |
| 276 | 276 | '', |
| 277 | - 'submit-' . $new_state_submit_id, |
|
| 277 | + 'submit-'.$new_state_submit_id, |
|
| 278 | 278 | 'ee-form-add-new-state-submit button button-secondary', |
| 279 | 279 | '', |
| 280 | - 'data-target="' . $new_state_submit_id . '"' |
|
| 280 | + 'data-target="'.$new_state_submit_id.'"' |
|
| 281 | 281 | ) |
| 282 | 282 | ) |
| 283 | 283 | ), |
@@ -306,8 +306,8 @@ discard block |
||
| 306 | 306 | EEH_HTML::br() |
| 307 | 307 | . |
| 308 | 308 | EEH_HTML::link('', __('cancel new state/province', 'event_espresso'), '', |
| 309 | - 'hide-' . $input->html_id(), 'ee-form-cancel-new-state-lnk smaller-text', '', |
|
| 310 | - 'data-target="' . $input->html_id() . '"') |
|
| 309 | + 'hide-'.$input->html_id(), 'ee-form-cancel-new-state-lnk smaller-text', '', |
|
| 310 | + 'data-target="'.$input->html_id().'"') |
|
| 311 | 311 | . |
| 312 | 312 | EEH_HTML::divx() |
| 313 | 313 | . |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | public static function add_new_state() |
| 335 | 335 | { |
| 336 | 336 | $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
| 337 | - if ( absint($REQ->get('nsmf_add_new_state')) === 1 ) { |
|
| 337 | + if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
| 338 | 338 | EE_Registry::instance()->load_model('State'); |
| 339 | 339 | // grab country ISO code, new state name, and new state abbreviation |
| 340 | 340 | $state_country = $REQ->is_set('nsmf_new_state_country') |
@@ -440,25 +440,25 @@ discard block |
||
| 440 | 440 | public static function save_new_state_to_db($props_n_values = array()) |
| 441 | 441 | { |
| 442 | 442 | $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
| 443 | - if (! empty($existing_state)) { |
|
| 443 | + if ( ! empty($existing_state)) { |
|
| 444 | 444 | return array_pop($existing_state); |
| 445 | 445 | } |
| 446 | 446 | $new_state = EE_State::new_instance($props_n_values); |
| 447 | 447 | if ($new_state instanceof EE_State) { |
| 448 | 448 | // if not non-ajax admin |
| 449 | - $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
| 449 | + $new_state_key = 'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev(); |
|
| 450 | 450 | $new_state_notice = sprintf( |
| 451 | 451 | __('A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
| 452 | 452 | 'event_espresso'), |
| 453 | - '<b>' . $new_state->name() . '</b>', |
|
| 454 | - '<b>' . $new_state->abbrev() . '</b>', |
|
| 455 | - '<b>' . $new_state->country()->name() . '</b>', |
|
| 456 | - '<a href="' . add_query_arg(array( |
|
| 453 | + '<b>'.$new_state->name().'</b>', |
|
| 454 | + '<b>'.$new_state->abbrev().'</b>', |
|
| 455 | + '<b>'.$new_state->country()->name().'</b>', |
|
| 456 | + '<a href="'.add_query_arg(array( |
|
| 457 | 457 | 'page' => 'espresso_general_settings', |
| 458 | 458 | 'action' => 'country_settings', |
| 459 | 459 | 'country' => $new_state->country_iso(), |
| 460 | - ), admin_url('admin.php')) . '">' . __('Event Espresso - General Settings > Countries Tab', |
|
| 461 | - 'event_espresso') . '</a>', |
|
| 460 | + ), admin_url('admin.php')).'">'.__('Event Espresso - General Settings > Countries Tab', |
|
| 461 | + 'event_espresso').'</a>', |
|
| 462 | 462 | '<br />' |
| 463 | 463 | ); |
| 464 | 464 | EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
@@ -480,23 +480,23 @@ discard block |
||
| 480 | 480 | public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
| 481 | 481 | { |
| 482 | 482 | $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : false; |
| 483 | - if (! $CNT_ISO) { |
|
| 483 | + if ( ! $CNT_ISO) { |
|
| 484 | 484 | EE_Error::add_error(__('An invalid or missing Country ISO Code was received.', 'event_espresso'), __FILE__, |
| 485 | 485 | __FUNCTION__, __LINE__); |
| 486 | 486 | } |
| 487 | 487 | $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
| 488 | 488 | : false; |
| 489 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 489 | + if ( ! $STA_abbrev && ! empty($STA_ID)) { |
|
| 490 | 490 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
| 491 | 491 | if ($state instanceof EE_State) { |
| 492 | 492 | $STA_abbrev = $state->abbrev(); |
| 493 | 493 | } |
| 494 | 494 | } |
| 495 | - if (! $STA_abbrev) { |
|
| 495 | + if ( ! $STA_abbrev) { |
|
| 496 | 496 | EE_Error::add_error(__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
| 497 | 497 | __FILE__, __FUNCTION__, __LINE__); |
| 498 | 498 | } |
| 499 | - EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 499 | + EE_Error::dismiss_persistent_admin_notice($CNT_ISO.'-'.$STA_abbrev, true, true); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | |
@@ -521,15 +521,15 @@ discard block |
||
| 521 | 521 | === EEM_Question::QST_type_state |
| 522 | 522 | ) { |
| 523 | 523 | $STA_ID = $answer->value(); |
| 524 | - if (! empty($STA_ID)) { |
|
| 524 | + if ( ! empty($STA_ID)) { |
|
| 525 | 525 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
| 526 | 526 | if ($state instanceof EE_State) { |
| 527 | 527 | $country = $state->country(); |
| 528 | 528 | if ($country instanceof EE_Country) { |
| 529 | - if (! isset($state_options[$country->name()])) { |
|
| 529 | + if ( ! isset($state_options[$country->name()])) { |
|
| 530 | 530 | $state_options[$country->name()] = array(); |
| 531 | 531 | } |
| 532 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
| 532 | + if ( ! isset($state_options[$country->name()][$STA_ID])) { |
|
| 533 | 533 | $state_options[$country->name()][$STA_ID] = $state->name(); |
| 534 | 534 | } |
| 535 | 535 | } |
@@ -561,10 +561,10 @@ discard block |
||
| 561 | 561 | === EEM_Question::QST_type_country |
| 562 | 562 | ) { |
| 563 | 563 | $CNT_ISO = $answer->value(); |
| 564 | - if (! empty($CNT_ISO)) { |
|
| 564 | + if ( ! empty($CNT_ISO)) { |
|
| 565 | 565 | $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
| 566 | 566 | if ($country instanceof EE_Country) { |
| 567 | - if (! isset($country_options[$CNT_ISO])) { |
|
| 567 | + if ( ! isset($country_options[$CNT_ISO])) { |
|
| 568 | 568 | $country_options[$CNT_ISO] = $country->name(); |
| 569 | 569 | } |
| 570 | 570 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -14,15 +14,15 @@ discard block |
||
| 14 | 14 | class EE_Credit_Card_Normalization extends EE_Text_Normalization |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @param string $value_to_normalize |
|
| 19 | - * @return mixed |
|
| 20 | - */ |
|
| 21 | - public function normalize($value_to_normalize) |
|
| 22 | - { |
|
| 23 | - $normalized_by_parent = parent::normalize($value_to_normalize); |
|
| 24 | - //we want to make it consistent, so remove whitespace from cc number |
|
| 25 | - return preg_replace('/\s+/', '', $normalized_by_parent); |
|
| 26 | - } |
|
| 17 | + /** |
|
| 18 | + * @param string $value_to_normalize |
|
| 19 | + * @return mixed |
|
| 20 | + */ |
|
| 21 | + public function normalize($value_to_normalize) |
|
| 22 | + { |
|
| 23 | + $normalized_by_parent = parent::normalize($value_to_normalize); |
|
| 24 | + //we want to make it consistent, so remove whitespace from cc number |
|
| 25 | + return preg_replace('/\s+/', '', $normalized_by_parent); |
|
| 26 | + } |
|
| 27 | 27 | } |
| 28 | 28 | // End of file EE_Credit_Card_Normalization.strategy.php |
@@ -1,4 +1,4 @@ |
||
| 1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | 2 | exit('No direct script access allowed'); |
| 3 | 3 | } |
| 4 | 4 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -14,91 +14,91 @@ discard block |
||
| 14 | 14 | class EE_Many_Valued_Normalization extends EE_Normalization_Strategy_Base |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - protected $_individual_item_normalization_strategy = array(); |
|
| 18 | - |
|
| 19 | - |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @param EE_Normalization_Strategy_Base $individual_item_normalization_strategy |
|
| 23 | - */ |
|
| 24 | - public function __construct($individual_item_normalization_strategy) |
|
| 25 | - { |
|
| 26 | - $this->_individual_item_normalization_strategy = $individual_item_normalization_strategy; |
|
| 27 | - parent::__construct(); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Normalizes the input into an array, and normalizes each item according to its |
|
| 34 | - * individual item normalization strategy |
|
| 35 | - * |
|
| 36 | - * @param array | string $value_to_normalize |
|
| 37 | - * @return array |
|
| 38 | - */ |
|
| 39 | - public function normalize($value_to_normalize) |
|
| 40 | - { |
|
| 41 | - if (is_array($value_to_normalize)) { |
|
| 42 | - $items_to_normalize = $value_to_normalize; |
|
| 43 | - } else if ($value_to_normalize !== null) { |
|
| 44 | - $items_to_normalize = array($value_to_normalize); |
|
| 45 | - } else { |
|
| 46 | - $items_to_normalize = array(); |
|
| 47 | - } |
|
| 48 | - $normalized_array_value = array(); |
|
| 49 | - foreach ($items_to_normalize as $key => $individual_item) { |
|
| 50 | - $normalized_array_value[$key] = $this->normalize_one($individual_item); |
|
| 51 | - } |
|
| 52 | - return $normalized_array_value; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Normalized the one item (called for each array item in EE_Many_values_Normalization::normalize()) |
|
| 59 | - * |
|
| 60 | - * @param string $individual_value_to_normalize but definitely NOT an array |
|
| 61 | - * @return mixed |
|
| 62 | - */ |
|
| 63 | - public function normalize_one($individual_value_to_normalize) |
|
| 64 | - { |
|
| 65 | - return $this->_individual_item_normalization_strategy->normalize($individual_value_to_normalize); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Converts the array of normalized things to an array of raw html values. |
|
| 72 | - * |
|
| 73 | - * @param array $normalized_values |
|
| 74 | - * @return string[] |
|
| 75 | - */ |
|
| 76 | - public function unnormalize($normalized_values) |
|
| 77 | - { |
|
| 78 | - if ($normalized_values === null) { |
|
| 79 | - $normalized_values = array(); |
|
| 80 | - } |
|
| 81 | - if (! is_array($normalized_values)) { |
|
| 82 | - $normalized_values = array($normalized_values); |
|
| 83 | - } |
|
| 84 | - $non_normal_values = array(); |
|
| 85 | - foreach ($normalized_values as $key => $value) { |
|
| 86 | - $non_normal_values[$key] = $this->unnormalize_one($value); |
|
| 87 | - } |
|
| 88 | - return $non_normal_values; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Unnormalizes an individual item in the array of values |
|
| 95 | - * |
|
| 96 | - * @param mixed $individual_value_to_unnormalize but certainly NOT an array |
|
| 97 | - * @return string |
|
| 98 | - */ |
|
| 99 | - public function unnormalize_one($individual_value_to_unnormalize) |
|
| 100 | - { |
|
| 101 | - return $this->_individual_item_normalization_strategy->unnormalize($individual_value_to_unnormalize); |
|
| 102 | - } |
|
| 17 | + protected $_individual_item_normalization_strategy = array(); |
|
| 18 | + |
|
| 19 | + |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @param EE_Normalization_Strategy_Base $individual_item_normalization_strategy |
|
| 23 | + */ |
|
| 24 | + public function __construct($individual_item_normalization_strategy) |
|
| 25 | + { |
|
| 26 | + $this->_individual_item_normalization_strategy = $individual_item_normalization_strategy; |
|
| 27 | + parent::__construct(); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Normalizes the input into an array, and normalizes each item according to its |
|
| 34 | + * individual item normalization strategy |
|
| 35 | + * |
|
| 36 | + * @param array | string $value_to_normalize |
|
| 37 | + * @return array |
|
| 38 | + */ |
|
| 39 | + public function normalize($value_to_normalize) |
|
| 40 | + { |
|
| 41 | + if (is_array($value_to_normalize)) { |
|
| 42 | + $items_to_normalize = $value_to_normalize; |
|
| 43 | + } else if ($value_to_normalize !== null) { |
|
| 44 | + $items_to_normalize = array($value_to_normalize); |
|
| 45 | + } else { |
|
| 46 | + $items_to_normalize = array(); |
|
| 47 | + } |
|
| 48 | + $normalized_array_value = array(); |
|
| 49 | + foreach ($items_to_normalize as $key => $individual_item) { |
|
| 50 | + $normalized_array_value[$key] = $this->normalize_one($individual_item); |
|
| 51 | + } |
|
| 52 | + return $normalized_array_value; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Normalized the one item (called for each array item in EE_Many_values_Normalization::normalize()) |
|
| 59 | + * |
|
| 60 | + * @param string $individual_value_to_normalize but definitely NOT an array |
|
| 61 | + * @return mixed |
|
| 62 | + */ |
|
| 63 | + public function normalize_one($individual_value_to_normalize) |
|
| 64 | + { |
|
| 65 | + return $this->_individual_item_normalization_strategy->normalize($individual_value_to_normalize); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Converts the array of normalized things to an array of raw html values. |
|
| 72 | + * |
|
| 73 | + * @param array $normalized_values |
|
| 74 | + * @return string[] |
|
| 75 | + */ |
|
| 76 | + public function unnormalize($normalized_values) |
|
| 77 | + { |
|
| 78 | + if ($normalized_values === null) { |
|
| 79 | + $normalized_values = array(); |
|
| 80 | + } |
|
| 81 | + if (! is_array($normalized_values)) { |
|
| 82 | + $normalized_values = array($normalized_values); |
|
| 83 | + } |
|
| 84 | + $non_normal_values = array(); |
|
| 85 | + foreach ($normalized_values as $key => $value) { |
|
| 86 | + $non_normal_values[$key] = $this->unnormalize_one($value); |
|
| 87 | + } |
|
| 88 | + return $non_normal_values; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Unnormalizes an individual item in the array of values |
|
| 95 | + * |
|
| 96 | + * @param mixed $individual_value_to_unnormalize but certainly NOT an array |
|
| 97 | + * @return string |
|
| 98 | + */ |
|
| 99 | + public function unnormalize_one($individual_value_to_unnormalize) |
|
| 100 | + { |
|
| 101 | + return $this->_individual_item_normalization_strategy->unnormalize($individual_value_to_unnormalize); |
|
| 102 | + } |
|
| 103 | 103 | } |
| 104 | 104 | // End of file EE_Many_Valued_Normalization.strategy.php |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | 2 | exit('No direct script access allowed'); |
| 3 | 3 | } |
| 4 | 4 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | if ($normalized_values === null) { |
| 79 | 79 | $normalized_values = array(); |
| 80 | 80 | } |
| 81 | - if (! is_array($normalized_values)) { |
|
| 81 | + if ( ! is_array($normalized_values)) { |
|
| 82 | 82 | $normalized_values = array($normalized_values); |
| 83 | 83 | } |
| 84 | 84 | $non_normal_values = array(); |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | 2 | exit('No direct script access allowed'); |
| 3 | 3 | } |
| 4 | 4 | |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | return null; |
| 37 | 37 | } |
| 38 | 38 | if (is_float($value_to_normalize) || is_int($value_to_normalize)) { |
| 39 | - return (float)$value_to_normalize; |
|
| 39 | + return (float) $value_to_normalize; |
|
| 40 | 40 | } |
| 41 | - if (! is_string($value_to_normalize)) { |
|
| 41 | + if ( ! is_string($value_to_normalize)) { |
|
| 42 | 42 | throw new EE_Validation_Error( |
| 43 | 43 | sprintf( |
| 44 | 44 | __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | // if first match is the negative sign, |
| 61 | 61 | // then the number needs to be multiplied by -1 to remain negative |
| 62 | 62 | return $matches[1] === '-' |
| 63 | - ? (float)$matches[2] * -1 |
|
| 64 | - : (float)$matches[2]; |
|
| 63 | + ? (float) $matches[2] * -1 |
|
| 64 | + : (float) $matches[2]; |
|
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | //find if this input has a float validation strategy |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | } |
| 75 | 75 | //this really shouldn't ever happen because fields with a float normalization strategy |
| 76 | 76 | //should also have a float validation strategy, but in case it doesn't use the default |
| 77 | - if (! $validation_error_message) { |
|
| 77 | + if ( ! $validation_error_message) { |
|
| 78 | 78 | $default_validation_strategy = new EE_Float_Validation_Strategy(); |
| 79 | 79 | $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
| 80 | 80 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -15,85 +15,85 @@ discard block |
||
| 15 | 15 | class EE_Float_Normalization extends EE_Normalization_Strategy_Base |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /* |
|
| 18 | + /* |
|
| 19 | 19 | * regex pattern that matches for the following: |
| 20 | 20 | * * optional negative sign |
| 21 | 21 | * * one or more digits or decimals |
| 22 | 22 | */ |
| 23 | - const REGEX = '/^(-?)([\d.]+)$/'; |
|
| 23 | + const REGEX = '/^(-?)([\d.]+)$/'; |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @param string $value_to_normalize |
|
| 29 | - * @return float |
|
| 30 | - * @throws \EE_Validation_Error |
|
| 31 | - */ |
|
| 32 | - public function normalize($value_to_normalize) |
|
| 33 | - { |
|
| 34 | - if ($value_to_normalize === null) { |
|
| 35 | - return null; |
|
| 36 | - } |
|
| 37 | - if (is_float($value_to_normalize) || is_int($value_to_normalize)) { |
|
| 38 | - return (float)$value_to_normalize; |
|
| 39 | - } |
|
| 40 | - if (! is_string($value_to_normalize)) { |
|
| 41 | - throw new EE_Validation_Error( |
|
| 42 | - sprintf( |
|
| 43 | - __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
| 44 | - print_r($value_to_normalize, true), |
|
| 45 | - gettype($value_to_normalize) |
|
| 46 | - ) |
|
| 47 | - ); |
|
| 48 | - } |
|
| 49 | - $normalized_value = filter_var( |
|
| 50 | - $value_to_normalize, |
|
| 51 | - FILTER_SANITIZE_NUMBER_FLOAT, |
|
| 52 | - FILTER_FLAG_ALLOW_FRACTION |
|
| 53 | - ); |
|
| 54 | - if ($normalized_value === '') { |
|
| 55 | - return null; |
|
| 56 | - } |
|
| 57 | - if (preg_match(EE_Float_Normalization::REGEX, $normalized_value, $matches)) { |
|
| 58 | - if (count($matches) === 3) { |
|
| 59 | - // if first match is the negative sign, |
|
| 60 | - // then the number needs to be multiplied by -1 to remain negative |
|
| 61 | - return $matches[1] === '-' |
|
| 62 | - ? (float)$matches[2] * -1 |
|
| 63 | - : (float)$matches[2]; |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - //find if this input has a float validation strategy |
|
| 67 | - //in which case, use its message |
|
| 68 | - $validation_error_message = null; |
|
| 69 | - foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
| 70 | - if ($validation_strategy instanceof EE_Float_Validation_Strategy) { |
|
| 71 | - $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - //this really shouldn't ever happen because fields with a float normalization strategy |
|
| 75 | - //should also have a float validation strategy, but in case it doesn't use the default |
|
| 76 | - if (! $validation_error_message) { |
|
| 77 | - $default_validation_strategy = new EE_Float_Validation_Strategy(); |
|
| 78 | - $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
| 79 | - } |
|
| 80 | - throw new EE_Validation_Error($validation_error_message, 'float_only'); |
|
| 81 | - } |
|
| 27 | + /** |
|
| 28 | + * @param string $value_to_normalize |
|
| 29 | + * @return float |
|
| 30 | + * @throws \EE_Validation_Error |
|
| 31 | + */ |
|
| 32 | + public function normalize($value_to_normalize) |
|
| 33 | + { |
|
| 34 | + if ($value_to_normalize === null) { |
|
| 35 | + return null; |
|
| 36 | + } |
|
| 37 | + if (is_float($value_to_normalize) || is_int($value_to_normalize)) { |
|
| 38 | + return (float)$value_to_normalize; |
|
| 39 | + } |
|
| 40 | + if (! is_string($value_to_normalize)) { |
|
| 41 | + throw new EE_Validation_Error( |
|
| 42 | + sprintf( |
|
| 43 | + __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
| 44 | + print_r($value_to_normalize, true), |
|
| 45 | + gettype($value_to_normalize) |
|
| 46 | + ) |
|
| 47 | + ); |
|
| 48 | + } |
|
| 49 | + $normalized_value = filter_var( |
|
| 50 | + $value_to_normalize, |
|
| 51 | + FILTER_SANITIZE_NUMBER_FLOAT, |
|
| 52 | + FILTER_FLAG_ALLOW_FRACTION |
|
| 53 | + ); |
|
| 54 | + if ($normalized_value === '') { |
|
| 55 | + return null; |
|
| 56 | + } |
|
| 57 | + if (preg_match(EE_Float_Normalization::REGEX, $normalized_value, $matches)) { |
|
| 58 | + if (count($matches) === 3) { |
|
| 59 | + // if first match is the negative sign, |
|
| 60 | + // then the number needs to be multiplied by -1 to remain negative |
|
| 61 | + return $matches[1] === '-' |
|
| 62 | + ? (float)$matches[2] * -1 |
|
| 63 | + : (float)$matches[2]; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + //find if this input has a float validation strategy |
|
| 67 | + //in which case, use its message |
|
| 68 | + $validation_error_message = null; |
|
| 69 | + foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
| 70 | + if ($validation_strategy instanceof EE_Float_Validation_Strategy) { |
|
| 71 | + $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + //this really shouldn't ever happen because fields with a float normalization strategy |
|
| 75 | + //should also have a float validation strategy, but in case it doesn't use the default |
|
| 76 | + if (! $validation_error_message) { |
|
| 77 | + $default_validation_strategy = new EE_Float_Validation_Strategy(); |
|
| 78 | + $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
| 79 | + } |
|
| 80 | + throw new EE_Validation_Error($validation_error_message, 'float_only'); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | 83 | |
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Converts a float into a string |
|
| 87 | - * |
|
| 88 | - * @param float $normalized_value |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - public function unnormalize($normalized_value) |
|
| 92 | - { |
|
| 93 | - if (empty($normalized_value)) { |
|
| 94 | - return '0.00'; |
|
| 95 | - } |
|
| 96 | - return "{$normalized_value}"; |
|
| 97 | - } |
|
| 85 | + /** |
|
| 86 | + * Converts a float into a string |
|
| 87 | + * |
|
| 88 | + * @param float $normalized_value |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + public function unnormalize($normalized_value) |
|
| 92 | + { |
|
| 93 | + if (empty($normalized_value)) { |
|
| 94 | + return '0.00'; |
|
| 95 | + } |
|
| 96 | + return "{$normalized_value}"; |
|
| 97 | + } |
|
| 98 | 98 | } |
| 99 | 99 | // End of file EE_Float_Normalization.strategy.php |
@@ -1,4 +1,4 @@ |
||
| 1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | 2 | exit('No direct script access allowed'); |
| 3 | 3 | } |
| 4 | 4 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -15,26 +15,26 @@ discard block |
||
| 15 | 15 | class EE_Slug_Normalization extends EE_Normalization_Strategy_Base |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @param string $value_to_normalize |
|
| 20 | - * @return string |
|
| 21 | - */ |
|
| 22 | - public function normalize($value_to_normalize) |
|
| 23 | - { |
|
| 24 | - return sanitize_title($value_to_normalize); |
|
| 25 | - } |
|
| 18 | + /** |
|
| 19 | + * @param string $value_to_normalize |
|
| 20 | + * @return string |
|
| 21 | + */ |
|
| 22 | + public function normalize($value_to_normalize) |
|
| 23 | + { |
|
| 24 | + return sanitize_title($value_to_normalize); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * It's hard to unnormalize this- let's just take a guess |
|
| 31 | - * |
|
| 32 | - * @param string $normalized_value |
|
| 33 | - * @return string |
|
| 34 | - */ |
|
| 35 | - public function unnormalize($normalized_value) |
|
| 36 | - { |
|
| 37 | - return str_replace("-", " ", $normalized_value); |
|
| 38 | - } |
|
| 29 | + /** |
|
| 30 | + * It's hard to unnormalize this- let's just take a guess |
|
| 31 | + * |
|
| 32 | + * @param string $normalized_value |
|
| 33 | + * @return string |
|
| 34 | + */ |
|
| 35 | + public function unnormalize($normalized_value) |
|
| 36 | + { |
|
| 37 | + return str_replace("-", " ", $normalized_value); |
|
| 38 | + } |
|
| 39 | 39 | } |
| 40 | 40 | // End of file EE_Slug_Normalization.strategy.php |
@@ -1,4 +1,4 @@ |
||
| 1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | 2 | exit('No direct script access allowed'); |
| 3 | 3 | } |
| 4 | 4 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -16,27 +16,27 @@ discard block |
||
| 16 | 16 | class EE_All_Caps_Normalization extends EE_Normalization_Strategy_Base |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @param string $value_to_normalize |
|
| 21 | - * @return string |
|
| 22 | - */ |
|
| 23 | - public function normalize($value_to_normalize) |
|
| 24 | - { |
|
| 25 | - return strtoupper($value_to_normalize); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * It's kinda hard to unnormalize this- we can't determine which parts used to be lowercase |
|
| 32 | - * so just return it as-is. |
|
| 33 | - * |
|
| 34 | - * @param string $normalized_value |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function unnormalize($normalized_value) |
|
| 38 | - { |
|
| 39 | - return $normalized_value; |
|
| 40 | - } |
|
| 19 | + /** |
|
| 20 | + * @param string $value_to_normalize |
|
| 21 | + * @return string |
|
| 22 | + */ |
|
| 23 | + public function normalize($value_to_normalize) |
|
| 24 | + { |
|
| 25 | + return strtoupper($value_to_normalize); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * It's kinda hard to unnormalize this- we can't determine which parts used to be lowercase |
|
| 32 | + * so just return it as-is. |
|
| 33 | + * |
|
| 34 | + * @param string $normalized_value |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function unnormalize($normalized_value) |
|
| 38 | + { |
|
| 39 | + return $normalized_value; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | } |
| 43 | 43 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -18,28 +18,28 @@ discard block |
||
| 18 | 18 | class EE_Boolean_Normalization extends EE_Normalization_Strategy_Base |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @param string | int | bool $value_to_normalize |
|
| 23 | - * @return boolean |
|
| 24 | - */ |
|
| 25 | - public function normalize($value_to_normalize) |
|
| 26 | - { |
|
| 27 | - return filter_var($value_to_normalize, FILTER_VALIDATE_BOOLEAN); |
|
| 28 | - } |
|
| 21 | + /** |
|
| 22 | + * @param string | int | bool $value_to_normalize |
|
| 23 | + * @return boolean |
|
| 24 | + */ |
|
| 25 | + public function normalize($value_to_normalize) |
|
| 26 | + { |
|
| 27 | + return filter_var($value_to_normalize, FILTER_VALIDATE_BOOLEAN); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @param boolean $normalized_value |
|
| 34 | - * @return string |
|
| 35 | - */ |
|
| 36 | - public function unnormalize($normalized_value) |
|
| 37 | - { |
|
| 38 | - if ($normalized_value) { |
|
| 39 | - return '1'; |
|
| 40 | - } else { |
|
| 41 | - return '0'; |
|
| 42 | - } |
|
| 43 | - } |
|
| 32 | + /** |
|
| 33 | + * @param boolean $normalized_value |
|
| 34 | + * @return string |
|
| 35 | + */ |
|
| 36 | + public function unnormalize($normalized_value) |
|
| 37 | + { |
|
| 38 | + if ($normalized_value) { |
|
| 39 | + return '1'; |
|
| 40 | + } else { |
|
| 41 | + return '0'; |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | 44 | } |
| 45 | 45 | // End of file EE_Boolean_Normalization.strategy.php |
@@ -1,4 +1,4 @@ |
||
| 1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | 2 | exit('No direct script access allowed'); |
| 3 | 3 | } |
| 4 | 4 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('No direct script access allowed'); |
|
| 3 | + exit('No direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | |
@@ -18,568 +18,568 @@ discard block |
||
| 18 | 18 | { |
| 19 | 19 | |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * This means that the requested class dependency is not present in the dependency map |
|
| 23 | - */ |
|
| 24 | - const not_registered = 0; |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 29 | - */ |
|
| 30 | - const load_new_object = 1; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 34 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 35 | - */ |
|
| 36 | - const load_from_cache = 2; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @type EE_Dependency_Map $_instance |
|
| 40 | - */ |
|
| 41 | - protected static $_instance; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @type EE_Request $request |
|
| 45 | - */ |
|
| 46 | - protected $_request; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @type EE_Response $response |
|
| 50 | - */ |
|
| 51 | - protected $_response; |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @type array $_dependency_map |
|
| 56 | - */ |
|
| 57 | - protected $_dependency_map = array(); |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @type array $_class_loaders |
|
| 61 | - */ |
|
| 62 | - protected $_class_loaders = array(); |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @type array $_aliases |
|
| 66 | - */ |
|
| 67 | - protected $_aliases = array(); |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * EE_Dependency_Map constructor. |
|
| 73 | - * |
|
| 74 | - * @param EE_Request $request |
|
| 75 | - * @param EE_Response $response |
|
| 76 | - */ |
|
| 77 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
| 78 | - { |
|
| 79 | - $this->_request = $request; |
|
| 80 | - $this->_response = $response; |
|
| 81 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 82 | - do_action('EE_Dependency_Map____construct'); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - */ |
|
| 89 | - public function initialize() |
|
| 90 | - { |
|
| 91 | - $this->_register_core_dependencies(); |
|
| 92 | - $this->_register_core_class_loaders(); |
|
| 93 | - $this->_register_core_aliases(); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @singleton method used to instantiate class object |
|
| 100 | - * @access public |
|
| 101 | - * @param EE_Request $request |
|
| 102 | - * @param EE_Response $response |
|
| 103 | - * @return EE_Dependency_Map instance |
|
| 104 | - */ |
|
| 105 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 106 | - { |
|
| 107 | - // check if class object is instantiated, and instantiated properly |
|
| 108 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 109 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 110 | - } |
|
| 111 | - return self::$_instance; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @param string $class |
|
| 118 | - * @param array $dependencies |
|
| 119 | - * @return boolean |
|
| 120 | - */ |
|
| 121 | - public static function register_dependencies($class, $dependencies) |
|
| 122 | - { |
|
| 123 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
| 124 | - // we need to make sure that any aliases used when registering a dependency |
|
| 125 | - // get resolved to the correct class name |
|
| 126 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 127 | - $alias = self::$_instance->get_alias($dependency); |
|
| 128 | - unset($dependencies[$dependency]); |
|
| 129 | - $dependencies[$alias] = $load_source; |
|
| 130 | - } |
|
| 131 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
| 132 | - return true; |
|
| 133 | - } |
|
| 134 | - return false; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param string $class_name |
|
| 141 | - * @param string $loader |
|
| 142 | - * @return bool |
|
| 143 | - * @throws EE_Error |
|
| 144 | - */ |
|
| 145 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 146 | - { |
|
| 147 | - // check that loader method starts with "load_" and exists in EE_Registry |
|
| 148 | - if ( |
|
| 149 | - ! is_callable($loader) |
|
| 150 | - && (strpos($loader, 'load_') !== 0 || ! method_exists('EE_Registry', $loader)) |
|
| 151 | - ) { |
|
| 152 | - throw new EE_Error( |
|
| 153 | - sprintf( |
|
| 154 | - __('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
| 155 | - $loader |
|
| 156 | - ) |
|
| 157 | - ); |
|
| 158 | - } |
|
| 159 | - $class_name = self::$_instance->get_alias($class_name); |
|
| 160 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 161 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 162 | - return true; |
|
| 163 | - } |
|
| 164 | - return false; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @return array |
|
| 171 | - */ |
|
| 172 | - public function dependency_map() |
|
| 173 | - { |
|
| 174 | - return $this->_dependency_map; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
| 181 | - * |
|
| 182 | - * @param string $class_name |
|
| 183 | - * @return boolean |
|
| 184 | - */ |
|
| 185 | - public function has($class_name = '') |
|
| 186 | - { |
|
| 187 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 194 | - * |
|
| 195 | - * @param string $class_name |
|
| 196 | - * @param string $dependency |
|
| 197 | - * @return bool |
|
| 198 | - */ |
|
| 199 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 200 | - { |
|
| 201 | - $dependency = $this->get_alias($dependency); |
|
| 202 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 203 | - ? true |
|
| 204 | - : false; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 211 | - * |
|
| 212 | - * @param string $class_name |
|
| 213 | - * @param string $dependency |
|
| 214 | - * @return int |
|
| 215 | - */ |
|
| 216 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 217 | - { |
|
| 218 | - $dependency = $this->get_alias($dependency); |
|
| 219 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
| 220 | - ? $this->_dependency_map[$class_name][$dependency] |
|
| 221 | - : EE_Dependency_Map::not_registered; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @param string $class_name |
|
| 228 | - * @return string | Closure |
|
| 229 | - */ |
|
| 230 | - public function class_loader($class_name) |
|
| 231 | - { |
|
| 232 | - $class_name = $this->get_alias($class_name); |
|
| 233 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @return array |
|
| 240 | - */ |
|
| 241 | - public function class_loaders() |
|
| 242 | - { |
|
| 243 | - return $this->_class_loaders; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * adds an alias for a classname |
|
| 250 | - * |
|
| 251 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 252 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 253 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 254 | - */ |
|
| 255 | - public function add_alias($class_name, $alias, $for_class = '') |
|
| 256 | - { |
|
| 257 | - if ($for_class !== '') { |
|
| 258 | - if (! isset($this->_aliases[$for_class])) { |
|
| 259 | - $this->_aliases[$for_class] = array(); |
|
| 260 | - } |
|
| 261 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
| 262 | - } |
|
| 263 | - $this->_aliases[$class_name] = $alias; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * returns TRUE if the provided class name has an alias |
|
| 270 | - * |
|
| 271 | - * @param string $class_name |
|
| 272 | - * @param string $for_class |
|
| 273 | - * @return bool |
|
| 274 | - */ |
|
| 275 | - public function has_alias($class_name = '', $for_class = '') |
|
| 276 | - { |
|
| 277 | - if (isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name])) { |
|
| 278 | - return true; |
|
| 279 | - } |
|
| 280 | - return isset($this->_aliases[$class_name]) && ! is_array($this->_aliases[$class_name]) ? true : false; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
| 287 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 288 | - * for example: |
|
| 289 | - * if the following two entries were added to the _aliases array: |
|
| 290 | - * array( |
|
| 291 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 292 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 293 | - * ) |
|
| 294 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 295 | - * to load an instance of 'some\namespace\classname' |
|
| 296 | - * |
|
| 297 | - * @param string $class_name |
|
| 298 | - * @param string $for_class |
|
| 299 | - * @return string |
|
| 300 | - */ |
|
| 301 | - public function get_alias($class_name = '', $for_class = '') |
|
| 302 | - { |
|
| 303 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 304 | - return $class_name; |
|
| 305 | - } |
|
| 306 | - if ($for_class !== '') { |
|
| 307 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 308 | - } |
|
| 309 | - return $this->get_alias($this->_aliases[$class_name]); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 316 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 317 | - * This is done by using the following class constants: |
|
| 318 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 319 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 320 | - */ |
|
| 321 | - protected function _register_core_dependencies() |
|
| 322 | - { |
|
| 323 | - $this->_dependency_map = array( |
|
| 324 | - 'EE_Request_Handler' => array( |
|
| 325 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 326 | - ), |
|
| 327 | - 'EE_System' => array( |
|
| 328 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 329 | - ), |
|
| 330 | - 'EE_Session' => array( |
|
| 331 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 332 | - ), |
|
| 333 | - 'EE_Cart' => array( |
|
| 334 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 335 | - ), |
|
| 336 | - 'EE_Front_Controller' => array( |
|
| 337 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 338 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 339 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 340 | - ), |
|
| 341 | - 'EE_Messenger_Collection_Loader' => array( |
|
| 342 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 343 | - ), |
|
| 344 | - 'EE_Message_Type_Collection_Loader' => array( |
|
| 345 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 346 | - ), |
|
| 347 | - 'EE_Message_Resource_Manager' => array( |
|
| 348 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 349 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 350 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 351 | - ), |
|
| 352 | - 'EE_Message_Factory' => array( |
|
| 353 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 354 | - ), |
|
| 355 | - 'EE_messages' => array( |
|
| 356 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 357 | - ), |
|
| 358 | - 'EE_Messages_Generator' => array( |
|
| 359 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 360 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 361 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 362 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 363 | - ), |
|
| 364 | - 'EE_Messages_Processor' => array( |
|
| 365 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 366 | - ), |
|
| 367 | - 'EE_Messages_Queue' => array( |
|
| 368 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 369 | - ), |
|
| 370 | - 'EE_Messages_Template_Defaults' => array( |
|
| 371 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 372 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 373 | - ), |
|
| 374 | - 'EE_Message_To_Generate_From_Request' => array( |
|
| 375 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 376 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 377 | - ), |
|
| 378 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 379 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 380 | - ), |
|
| 381 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 382 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 383 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 384 | - ), |
|
| 385 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 386 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 387 | - ), |
|
| 388 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 389 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 390 | - ), |
|
| 391 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 392 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 393 | - ), |
|
| 394 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 395 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 396 | - ), |
|
| 397 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 398 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 399 | - ), |
|
| 400 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 401 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 402 | - ), |
|
| 403 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 404 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 405 | - ), |
|
| 406 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 407 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 408 | - ), |
|
| 409 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 410 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 411 | - ), |
|
| 412 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 413 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 414 | - ), |
|
| 415 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 416 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 417 | - ), |
|
| 418 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 419 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 420 | - ), |
|
| 421 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
| 422 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 423 | - ), |
|
| 424 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
| 425 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 426 | - ), |
|
| 427 | - 'EE_Data_Migration_Class_Base' => array( |
|
| 428 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 429 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 430 | - ), |
|
| 431 | - 'EE_DMS_Core_4_1_0' => array( |
|
| 432 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 433 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 434 | - ), |
|
| 435 | - 'EE_DMS_Core_4_2_0' => array( |
|
| 436 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 437 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 438 | - ), |
|
| 439 | - 'EE_DMS_Core_4_3_0' => array( |
|
| 440 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 441 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 442 | - ), |
|
| 443 | - 'EE_DMS_Core_4_4_0' => array( |
|
| 444 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 445 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 446 | - ), |
|
| 447 | - 'EE_DMS_Core_4_5_0' => array( |
|
| 448 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 449 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 450 | - ), |
|
| 451 | - 'EE_DMS_Core_4_6_0' => array( |
|
| 452 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 453 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 454 | - ), |
|
| 455 | - 'EE_DMS_Core_4_7_0' => array( |
|
| 456 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 457 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 458 | - ), |
|
| 459 | - 'EE_DMS_Core_4_8_0' => array( |
|
| 460 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 461 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 462 | - ), |
|
| 463 | - 'EE_DMS_Core_4_9_0' => array( |
|
| 464 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 465 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 466 | - ), |
|
| 467 | - ); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * Registers how core classes are loaded. |
|
| 474 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 475 | - * 'EE_Request_Handler' => 'load_core' |
|
| 476 | - * 'EE_Messages_Queue' => 'load_lib' |
|
| 477 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
| 478 | - * or, if greater control is required, by providing a custom closure. For example: |
|
| 479 | - * 'Some_Class' => function () { |
|
| 480 | - * return new Some_Class(); |
|
| 481 | - * }, |
|
| 482 | - * This is required for instantiating dependencies |
|
| 483 | - * where an interface has been type hinted in a class constructor. For example: |
|
| 484 | - * 'Required_Interface' => function () { |
|
| 485 | - * return new A_Class_That_Implements_Required_Interface(); |
|
| 486 | - * }, |
|
| 487 | - */ |
|
| 488 | - protected function _register_core_class_loaders() |
|
| 489 | - { |
|
| 490 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 491 | - //be used in a closure. |
|
| 492 | - $request = &$this->_request; |
|
| 493 | - $response = &$this->_response; |
|
| 494 | - $this->_class_loaders = array( |
|
| 495 | - //load_core |
|
| 496 | - 'EE_Capabilities' => 'load_core', |
|
| 497 | - 'EE_Encryption' => 'load_core', |
|
| 498 | - 'EE_Front_Controller' => 'load_core', |
|
| 499 | - 'EE_Module_Request_Router' => 'load_core', |
|
| 500 | - 'EE_Registry' => 'load_core', |
|
| 501 | - 'EE_Request' => function () use (&$request) { |
|
| 502 | - return $request; |
|
| 503 | - }, |
|
| 504 | - 'EE_Response' => function () use (&$response) { |
|
| 505 | - return $response; |
|
| 506 | - }, |
|
| 507 | - 'EE_Request_Handler' => 'load_core', |
|
| 508 | - 'EE_Session' => 'load_core', |
|
| 509 | - 'EE_System' => 'load_core', |
|
| 510 | - //load_lib |
|
| 511 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 512 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
| 513 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 514 | - 'EE_Messenger_Collection' => 'load_lib', |
|
| 515 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 516 | - 'EE_Messages_Processor' => 'load_lib', |
|
| 517 | - 'EE_Message_Repository' => 'load_lib', |
|
| 518 | - 'EE_Messages_Queue' => 'load_lib', |
|
| 519 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 520 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 521 | - 'EE_Messages_Generator' => function () { |
|
| 522 | - return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
|
| 523 | - }, |
|
| 524 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 525 | - return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
|
| 526 | - }, |
|
| 527 | - //load_model |
|
| 528 | - 'EEM_Attendee' => 'load_model', |
|
| 529 | - 'EEM_Message_Template_Group' => 'load_model', |
|
| 530 | - 'EEM_Message_Template' => 'load_model', |
|
| 531 | - //load_helper |
|
| 532 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 533 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 534 | - return new EEH_Parse_Shortcodes(); |
|
| 535 | - } |
|
| 536 | - return null; |
|
| 537 | - }, |
|
| 538 | - ); |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * can be used for supplying alternate names for classes, |
|
| 545 | - * or for connecting interface names to instantiable classes |
|
| 546 | - */ |
|
| 547 | - protected function _register_core_aliases() |
|
| 548 | - { |
|
| 549 | - $this->_aliases = array( |
|
| 550 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 551 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 552 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 553 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 554 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 555 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 556 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 557 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 558 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 559 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 560 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 561 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 562 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 563 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 564 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 565 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 566 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 567 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 568 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 569 | - ); |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - |
|
| 573 | - |
|
| 574 | - /** |
|
| 575 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 576 | - * request Primarily used by unit tests. |
|
| 577 | - */ |
|
| 578 | - public function reset() |
|
| 579 | - { |
|
| 580 | - $this->_register_core_class_loaders(); |
|
| 581 | - $this->_register_core_dependencies(); |
|
| 582 | - } |
|
| 21 | + /** |
|
| 22 | + * This means that the requested class dependency is not present in the dependency map |
|
| 23 | + */ |
|
| 24 | + const not_registered = 0; |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 29 | + */ |
|
| 30 | + const load_new_object = 1; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 34 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 35 | + */ |
|
| 36 | + const load_from_cache = 2; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @type EE_Dependency_Map $_instance |
|
| 40 | + */ |
|
| 41 | + protected static $_instance; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @type EE_Request $request |
|
| 45 | + */ |
|
| 46 | + protected $_request; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @type EE_Response $response |
|
| 50 | + */ |
|
| 51 | + protected $_response; |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @type array $_dependency_map |
|
| 56 | + */ |
|
| 57 | + protected $_dependency_map = array(); |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @type array $_class_loaders |
|
| 61 | + */ |
|
| 62 | + protected $_class_loaders = array(); |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @type array $_aliases |
|
| 66 | + */ |
|
| 67 | + protected $_aliases = array(); |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * EE_Dependency_Map constructor. |
|
| 73 | + * |
|
| 74 | + * @param EE_Request $request |
|
| 75 | + * @param EE_Response $response |
|
| 76 | + */ |
|
| 77 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
| 78 | + { |
|
| 79 | + $this->_request = $request; |
|
| 80 | + $this->_response = $response; |
|
| 81 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 82 | + do_action('EE_Dependency_Map____construct'); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + */ |
|
| 89 | + public function initialize() |
|
| 90 | + { |
|
| 91 | + $this->_register_core_dependencies(); |
|
| 92 | + $this->_register_core_class_loaders(); |
|
| 93 | + $this->_register_core_aliases(); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @singleton method used to instantiate class object |
|
| 100 | + * @access public |
|
| 101 | + * @param EE_Request $request |
|
| 102 | + * @param EE_Response $response |
|
| 103 | + * @return EE_Dependency_Map instance |
|
| 104 | + */ |
|
| 105 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 106 | + { |
|
| 107 | + // check if class object is instantiated, and instantiated properly |
|
| 108 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 109 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 110 | + } |
|
| 111 | + return self::$_instance; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @param string $class |
|
| 118 | + * @param array $dependencies |
|
| 119 | + * @return boolean |
|
| 120 | + */ |
|
| 121 | + public static function register_dependencies($class, $dependencies) |
|
| 122 | + { |
|
| 123 | + if (! isset(self::$_instance->_dependency_map[$class])) { |
|
| 124 | + // we need to make sure that any aliases used when registering a dependency |
|
| 125 | + // get resolved to the correct class name |
|
| 126 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 127 | + $alias = self::$_instance->get_alias($dependency); |
|
| 128 | + unset($dependencies[$dependency]); |
|
| 129 | + $dependencies[$alias] = $load_source; |
|
| 130 | + } |
|
| 131 | + self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
| 132 | + return true; |
|
| 133 | + } |
|
| 134 | + return false; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param string $class_name |
|
| 141 | + * @param string $loader |
|
| 142 | + * @return bool |
|
| 143 | + * @throws EE_Error |
|
| 144 | + */ |
|
| 145 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 146 | + { |
|
| 147 | + // check that loader method starts with "load_" and exists in EE_Registry |
|
| 148 | + if ( |
|
| 149 | + ! is_callable($loader) |
|
| 150 | + && (strpos($loader, 'load_') !== 0 || ! method_exists('EE_Registry', $loader)) |
|
| 151 | + ) { |
|
| 152 | + throw new EE_Error( |
|
| 153 | + sprintf( |
|
| 154 | + __('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
| 155 | + $loader |
|
| 156 | + ) |
|
| 157 | + ); |
|
| 158 | + } |
|
| 159 | + $class_name = self::$_instance->get_alias($class_name); |
|
| 160 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 161 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 162 | + return true; |
|
| 163 | + } |
|
| 164 | + return false; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @return array |
|
| 171 | + */ |
|
| 172 | + public function dependency_map() |
|
| 173 | + { |
|
| 174 | + return $this->_dependency_map; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
| 181 | + * |
|
| 182 | + * @param string $class_name |
|
| 183 | + * @return boolean |
|
| 184 | + */ |
|
| 185 | + public function has($class_name = '') |
|
| 186 | + { |
|
| 187 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 194 | + * |
|
| 195 | + * @param string $class_name |
|
| 196 | + * @param string $dependency |
|
| 197 | + * @return bool |
|
| 198 | + */ |
|
| 199 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 200 | + { |
|
| 201 | + $dependency = $this->get_alias($dependency); |
|
| 202 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 203 | + ? true |
|
| 204 | + : false; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 211 | + * |
|
| 212 | + * @param string $class_name |
|
| 213 | + * @param string $dependency |
|
| 214 | + * @return int |
|
| 215 | + */ |
|
| 216 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 217 | + { |
|
| 218 | + $dependency = $this->get_alias($dependency); |
|
| 219 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
| 220 | + ? $this->_dependency_map[$class_name][$dependency] |
|
| 221 | + : EE_Dependency_Map::not_registered; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @param string $class_name |
|
| 228 | + * @return string | Closure |
|
| 229 | + */ |
|
| 230 | + public function class_loader($class_name) |
|
| 231 | + { |
|
| 232 | + $class_name = $this->get_alias($class_name); |
|
| 233 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @return array |
|
| 240 | + */ |
|
| 241 | + public function class_loaders() |
|
| 242 | + { |
|
| 243 | + return $this->_class_loaders; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * adds an alias for a classname |
|
| 250 | + * |
|
| 251 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 252 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 253 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 254 | + */ |
|
| 255 | + public function add_alias($class_name, $alias, $for_class = '') |
|
| 256 | + { |
|
| 257 | + if ($for_class !== '') { |
|
| 258 | + if (! isset($this->_aliases[$for_class])) { |
|
| 259 | + $this->_aliases[$for_class] = array(); |
|
| 260 | + } |
|
| 261 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
| 262 | + } |
|
| 263 | + $this->_aliases[$class_name] = $alias; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * returns TRUE if the provided class name has an alias |
|
| 270 | + * |
|
| 271 | + * @param string $class_name |
|
| 272 | + * @param string $for_class |
|
| 273 | + * @return bool |
|
| 274 | + */ |
|
| 275 | + public function has_alias($class_name = '', $for_class = '') |
|
| 276 | + { |
|
| 277 | + if (isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name])) { |
|
| 278 | + return true; |
|
| 279 | + } |
|
| 280 | + return isset($this->_aliases[$class_name]) && ! is_array($this->_aliases[$class_name]) ? true : false; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
| 287 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 288 | + * for example: |
|
| 289 | + * if the following two entries were added to the _aliases array: |
|
| 290 | + * array( |
|
| 291 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 292 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 293 | + * ) |
|
| 294 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 295 | + * to load an instance of 'some\namespace\classname' |
|
| 296 | + * |
|
| 297 | + * @param string $class_name |
|
| 298 | + * @param string $for_class |
|
| 299 | + * @return string |
|
| 300 | + */ |
|
| 301 | + public function get_alias($class_name = '', $for_class = '') |
|
| 302 | + { |
|
| 303 | + if (! $this->has_alias($class_name, $for_class)) { |
|
| 304 | + return $class_name; |
|
| 305 | + } |
|
| 306 | + if ($for_class !== '') { |
|
| 307 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 308 | + } |
|
| 309 | + return $this->get_alias($this->_aliases[$class_name]); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 316 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 317 | + * This is done by using the following class constants: |
|
| 318 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 319 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 320 | + */ |
|
| 321 | + protected function _register_core_dependencies() |
|
| 322 | + { |
|
| 323 | + $this->_dependency_map = array( |
|
| 324 | + 'EE_Request_Handler' => array( |
|
| 325 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 326 | + ), |
|
| 327 | + 'EE_System' => array( |
|
| 328 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 329 | + ), |
|
| 330 | + 'EE_Session' => array( |
|
| 331 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 332 | + ), |
|
| 333 | + 'EE_Cart' => array( |
|
| 334 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 335 | + ), |
|
| 336 | + 'EE_Front_Controller' => array( |
|
| 337 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 338 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 339 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 340 | + ), |
|
| 341 | + 'EE_Messenger_Collection_Loader' => array( |
|
| 342 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 343 | + ), |
|
| 344 | + 'EE_Message_Type_Collection_Loader' => array( |
|
| 345 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 346 | + ), |
|
| 347 | + 'EE_Message_Resource_Manager' => array( |
|
| 348 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 349 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 350 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 351 | + ), |
|
| 352 | + 'EE_Message_Factory' => array( |
|
| 353 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 354 | + ), |
|
| 355 | + 'EE_messages' => array( |
|
| 356 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 357 | + ), |
|
| 358 | + 'EE_Messages_Generator' => array( |
|
| 359 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 360 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 361 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 362 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 363 | + ), |
|
| 364 | + 'EE_Messages_Processor' => array( |
|
| 365 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 366 | + ), |
|
| 367 | + 'EE_Messages_Queue' => array( |
|
| 368 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 369 | + ), |
|
| 370 | + 'EE_Messages_Template_Defaults' => array( |
|
| 371 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 372 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 373 | + ), |
|
| 374 | + 'EE_Message_To_Generate_From_Request' => array( |
|
| 375 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 376 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 377 | + ), |
|
| 378 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 379 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 380 | + ), |
|
| 381 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 382 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 383 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 384 | + ), |
|
| 385 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 386 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 387 | + ), |
|
| 388 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 389 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 390 | + ), |
|
| 391 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 392 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 393 | + ), |
|
| 394 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 395 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 396 | + ), |
|
| 397 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 398 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 399 | + ), |
|
| 400 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 401 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 402 | + ), |
|
| 403 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 404 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 405 | + ), |
|
| 406 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 407 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 408 | + ), |
|
| 409 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 410 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 411 | + ), |
|
| 412 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 413 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 414 | + ), |
|
| 415 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 416 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 417 | + ), |
|
| 418 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 419 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 420 | + ), |
|
| 421 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
| 422 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 423 | + ), |
|
| 424 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
| 425 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 426 | + ), |
|
| 427 | + 'EE_Data_Migration_Class_Base' => array( |
|
| 428 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 429 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 430 | + ), |
|
| 431 | + 'EE_DMS_Core_4_1_0' => array( |
|
| 432 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 433 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 434 | + ), |
|
| 435 | + 'EE_DMS_Core_4_2_0' => array( |
|
| 436 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 437 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 438 | + ), |
|
| 439 | + 'EE_DMS_Core_4_3_0' => array( |
|
| 440 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 441 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 442 | + ), |
|
| 443 | + 'EE_DMS_Core_4_4_0' => array( |
|
| 444 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 445 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 446 | + ), |
|
| 447 | + 'EE_DMS_Core_4_5_0' => array( |
|
| 448 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 449 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 450 | + ), |
|
| 451 | + 'EE_DMS_Core_4_6_0' => array( |
|
| 452 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 453 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 454 | + ), |
|
| 455 | + 'EE_DMS_Core_4_7_0' => array( |
|
| 456 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 457 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 458 | + ), |
|
| 459 | + 'EE_DMS_Core_4_8_0' => array( |
|
| 460 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 461 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 462 | + ), |
|
| 463 | + 'EE_DMS_Core_4_9_0' => array( |
|
| 464 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 465 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 466 | + ), |
|
| 467 | + ); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * Registers how core classes are loaded. |
|
| 474 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 475 | + * 'EE_Request_Handler' => 'load_core' |
|
| 476 | + * 'EE_Messages_Queue' => 'load_lib' |
|
| 477 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
| 478 | + * or, if greater control is required, by providing a custom closure. For example: |
|
| 479 | + * 'Some_Class' => function () { |
|
| 480 | + * return new Some_Class(); |
|
| 481 | + * }, |
|
| 482 | + * This is required for instantiating dependencies |
|
| 483 | + * where an interface has been type hinted in a class constructor. For example: |
|
| 484 | + * 'Required_Interface' => function () { |
|
| 485 | + * return new A_Class_That_Implements_Required_Interface(); |
|
| 486 | + * }, |
|
| 487 | + */ |
|
| 488 | + protected function _register_core_class_loaders() |
|
| 489 | + { |
|
| 490 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 491 | + //be used in a closure. |
|
| 492 | + $request = &$this->_request; |
|
| 493 | + $response = &$this->_response; |
|
| 494 | + $this->_class_loaders = array( |
|
| 495 | + //load_core |
|
| 496 | + 'EE_Capabilities' => 'load_core', |
|
| 497 | + 'EE_Encryption' => 'load_core', |
|
| 498 | + 'EE_Front_Controller' => 'load_core', |
|
| 499 | + 'EE_Module_Request_Router' => 'load_core', |
|
| 500 | + 'EE_Registry' => 'load_core', |
|
| 501 | + 'EE_Request' => function () use (&$request) { |
|
| 502 | + return $request; |
|
| 503 | + }, |
|
| 504 | + 'EE_Response' => function () use (&$response) { |
|
| 505 | + return $response; |
|
| 506 | + }, |
|
| 507 | + 'EE_Request_Handler' => 'load_core', |
|
| 508 | + 'EE_Session' => 'load_core', |
|
| 509 | + 'EE_System' => 'load_core', |
|
| 510 | + //load_lib |
|
| 511 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 512 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
| 513 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 514 | + 'EE_Messenger_Collection' => 'load_lib', |
|
| 515 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 516 | + 'EE_Messages_Processor' => 'load_lib', |
|
| 517 | + 'EE_Message_Repository' => 'load_lib', |
|
| 518 | + 'EE_Messages_Queue' => 'load_lib', |
|
| 519 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 520 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 521 | + 'EE_Messages_Generator' => function () { |
|
| 522 | + return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
|
| 523 | + }, |
|
| 524 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 525 | + return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
|
| 526 | + }, |
|
| 527 | + //load_model |
|
| 528 | + 'EEM_Attendee' => 'load_model', |
|
| 529 | + 'EEM_Message_Template_Group' => 'load_model', |
|
| 530 | + 'EEM_Message_Template' => 'load_model', |
|
| 531 | + //load_helper |
|
| 532 | + 'EEH_Parse_Shortcodes' => function () { |
|
| 533 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 534 | + return new EEH_Parse_Shortcodes(); |
|
| 535 | + } |
|
| 536 | + return null; |
|
| 537 | + }, |
|
| 538 | + ); |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * can be used for supplying alternate names for classes, |
|
| 545 | + * or for connecting interface names to instantiable classes |
|
| 546 | + */ |
|
| 547 | + protected function _register_core_aliases() |
|
| 548 | + { |
|
| 549 | + $this->_aliases = array( |
|
| 550 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 551 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 552 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 553 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 554 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 555 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 556 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 557 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 558 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 559 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 560 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 561 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 562 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 563 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 564 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 565 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 566 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 567 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 568 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 569 | + ); |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + |
|
| 573 | + |
|
| 574 | + /** |
|
| 575 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 576 | + * request Primarily used by unit tests. |
|
| 577 | + */ |
|
| 578 | + public function reset() |
|
| 579 | + { |
|
| 580 | + $this->_register_core_class_loaders(); |
|
| 581 | + $this->_register_core_dependencies(); |
|
| 582 | + } |
|
| 583 | 583 | |
| 584 | 584 | |
| 585 | 585 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | 3 | exit('No direct script access allowed'); |
| 4 | 4 | } |
| 5 | 5 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | public static function instance(EE_Request $request = null, EE_Response $response = null) |
| 106 | 106 | { |
| 107 | 107 | // check if class object is instantiated, and instantiated properly |
| 108 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 108 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
| 109 | 109 | self::$_instance = new EE_Dependency_Map($request, $response); |
| 110 | 110 | } |
| 111 | 111 | return self::$_instance; |
@@ -120,15 +120,15 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public static function register_dependencies($class, $dependencies) |
| 122 | 122 | { |
| 123 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
| 123 | + if ( ! isset(self::$_instance->_dependency_map[$class])) { |
|
| 124 | 124 | // we need to make sure that any aliases used when registering a dependency |
| 125 | 125 | // get resolved to the correct class name |
| 126 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 126 | + foreach ((array) $dependencies as $dependency => $load_source) { |
|
| 127 | 127 | $alias = self::$_instance->get_alias($dependency); |
| 128 | 128 | unset($dependencies[$dependency]); |
| 129 | 129 | $dependencies[$alias] = $load_source; |
| 130 | 130 | } |
| 131 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
| 131 | + self::$_instance->_dependency_map[$class] = (array) $dependencies; |
|
| 132 | 132 | return true; |
| 133 | 133 | } |
| 134 | 134 | return false; |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | ); |
| 158 | 158 | } |
| 159 | 159 | $class_name = self::$_instance->get_alias($class_name); |
| 160 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 160 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 161 | 161 | self::$_instance->_class_loaders[$class_name] = $loader; |
| 162 | 162 | return true; |
| 163 | 163 | } |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | public function add_alias($class_name, $alias, $for_class = '') |
| 256 | 256 | { |
| 257 | 257 | if ($for_class !== '') { |
| 258 | - if (! isset($this->_aliases[$for_class])) { |
|
| 258 | + if ( ! isset($this->_aliases[$for_class])) { |
|
| 259 | 259 | $this->_aliases[$for_class] = array(); |
| 260 | 260 | } |
| 261 | 261 | $this->_aliases[$for_class][$class_name] = $alias; |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | */ |
| 301 | 301 | public function get_alias($class_name = '', $for_class = '') |
| 302 | 302 | { |
| 303 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 303 | + if ( ! $this->has_alias($class_name, $for_class)) { |
|
| 304 | 304 | return $class_name; |
| 305 | 305 | } |
| 306 | 306 | if ($for_class !== '') { |
@@ -498,10 +498,10 @@ discard block |
||
| 498 | 498 | 'EE_Front_Controller' => 'load_core', |
| 499 | 499 | 'EE_Module_Request_Router' => 'load_core', |
| 500 | 500 | 'EE_Registry' => 'load_core', |
| 501 | - 'EE_Request' => function () use (&$request) { |
|
| 501 | + 'EE_Request' => function() use (&$request) { |
|
| 502 | 502 | return $request; |
| 503 | 503 | }, |
| 504 | - 'EE_Response' => function () use (&$response) { |
|
| 504 | + 'EE_Response' => function() use (&$response) { |
|
| 505 | 505 | return $response; |
| 506 | 506 | }, |
| 507 | 507 | 'EE_Request_Handler' => 'load_core', |
@@ -518,10 +518,10 @@ discard block |
||
| 518 | 518 | 'EE_Messages_Queue' => 'load_lib', |
| 519 | 519 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
| 520 | 520 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
| 521 | - 'EE_Messages_Generator' => function () { |
|
| 521 | + 'EE_Messages_Generator' => function() { |
|
| 522 | 522 | return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
| 523 | 523 | }, |
| 524 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 524 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
| 525 | 525 | return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
| 526 | 526 | }, |
| 527 | 527 | //load_model |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | 'EEM_Message_Template_Group' => 'load_model', |
| 530 | 530 | 'EEM_Message_Template' => 'load_model', |
| 531 | 531 | //load_helper |
| 532 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 532 | + 'EEH_Parse_Shortcodes' => function() { |
|
| 533 | 533 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
| 534 | 534 | return new EEH_Parse_Shortcodes(); |
| 535 | 535 | } |