@@ -22,744 +22,744 @@ |
||
| 22 | 22 | |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @return EED_Module|EED_Add_New_State |
|
| 27 | - */ |
|
| 28 | - public static function instance() |
|
| 29 | - { |
|
| 30 | - return parent::get_instance(__CLASS__); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 37 | - * |
|
| 38 | - * @return void |
|
| 39 | - */ |
|
| 40 | - public static function set_hooks() |
|
| 41 | - { |
|
| 42 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 43 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
| 44 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
| 45 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 46 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 47 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 48 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 49 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 50 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 51 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 52 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 53 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 54 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 55 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 56 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 57 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 58 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 65 | - * |
|
| 66 | - * @return void |
|
| 67 | - */ |
|
| 68 | - public static function set_hooks_admin() |
|
| 69 | - { |
|
| 70 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 71 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 72 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 73 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 74 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 75 | - add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 76 | - add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 77 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 78 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 79 | - add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 80 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 81 | - add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 82 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 83 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 84 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 85 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 86 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 87 | - add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 88 | - array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
| 89 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 90 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 91 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 92 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @return void |
|
| 99 | - */ |
|
| 100 | - public static function set_definitions() |
|
| 101 | - { |
|
| 102 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 103 | - define('ANS_TEMPLATES_PATH', str_replace( |
|
| 104 | - '\\', |
|
| 105 | - DS, |
|
| 106 | - plugin_dir_path(__FILE__)) . 'templates' . DS |
|
| 107 | - ); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @param WP $WP |
|
| 114 | - * @return void |
|
| 115 | - */ |
|
| 116 | - public function run($WP) |
|
| 117 | - { |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @return void |
|
| 124 | - */ |
|
| 125 | - public static function translate_js_strings() |
|
| 126 | - { |
|
| 127 | - EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 128 | - 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 129 | - 'event_espresso' |
|
| 130 | - ); |
|
| 131 | - EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 132 | - 'In order to proceed, you need to enter the name of your State/Province.', |
|
| 133 | - 'event_espresso' |
|
| 134 | - ); |
|
| 135 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 136 | - 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 137 | - 'event_espresso' |
|
| 138 | - ); |
|
| 139 | - EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 140 | - 'The new state was successfully saved to the database.', |
|
| 141 | - 'event_espresso' |
|
| 142 | - ); |
|
| 143 | - EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
| 144 | - 'An unknown error has occurred on the server while saving the new state to the database.', |
|
| 145 | - 'event_espresso' |
|
| 146 | - ); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @return void |
|
| 153 | - */ |
|
| 154 | - public static function wp_enqueue_scripts() |
|
| 155 | - { |
|
| 156 | - if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 157 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
| 158 | - array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
| 159 | - wp_enqueue_script('add_new_state'); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * display_add_new_state_micro_form |
|
| 167 | - * |
|
| 168 | - * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 169 | - * @return string |
|
| 170 | - * @throws EE_Error |
|
| 171 | - * @throws InvalidArgumentException |
|
| 172 | - * @throws InvalidDataTypeException |
|
| 173 | - * @throws InvalidInterfaceException |
|
| 174 | - */ |
|
| 175 | - // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
| 176 | - public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 177 | - { |
|
| 178 | - // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 179 | - // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 180 | - $action = EE_Registry::instance()->REQ->get('action', ''); |
|
| 181 | - // is the "state" question in this form section? |
|
| 182 | - $input = $question_group_reg_form->get_subsection('state'); |
|
| 183 | - if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 184 | - //ok then all we need to do is make sure the input's HTML name is consistent |
|
| 185 | - //by forcing it to set it now, like it did while getting the form for display |
|
| 186 | - if ($input instanceof EE_State_Select_Input) { |
|
| 187 | - $input->html_name(); |
|
| 188 | - } |
|
| 189 | - return $question_group_reg_form; |
|
| 190 | - } |
|
| 191 | - // we're only doing this for state select inputs |
|
| 192 | - if ($input instanceof EE_State_Select_Input && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 193 | - // grab any set values from the request |
|
| 194 | - $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 195 | - $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 196 | - $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 197 | - $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 198 | - $country_options = array(); |
|
| 199 | - $countries = EEM_Country::instance()->get_all_countries(); |
|
| 200 | - if (! empty($countries)) { |
|
| 201 | - foreach ($countries as $country) { |
|
| 202 | - if ($country instanceof EE_Country) { |
|
| 203 | - $country_options[$country->ID()] = $country->name(); |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 208 | - array( |
|
| 209 | - 'name' => 'new_state_micro_form', |
|
| 210 | - 'html_id' => 'new_state_micro_form', |
|
| 211 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 212 | - 'subsections' => array( |
|
| 213 | - // add hidden input to indicate that a new state is being added |
|
| 214 | - 'add_new_state' => new EE_Hidden_Input( |
|
| 215 | - array( |
|
| 216 | - 'html_name' => str_replace( |
|
| 217 | - 'state', |
|
| 218 | - 'nsmf_add_new_state', |
|
| 219 | - $input->html_name() |
|
| 220 | - ), |
|
| 221 | - 'html_id' => str_replace( |
|
| 222 | - 'state', |
|
| 223 | - 'nsmf_add_new_state', |
|
| 224 | - $input->html_id() |
|
| 225 | - ), |
|
| 226 | - 'default' => 0, |
|
| 227 | - ) |
|
| 228 | - ), |
|
| 229 | - // add link for displaying hidden container |
|
| 230 | - 'click_here_link' => new EE_Form_Section_HTML( |
|
| 231 | - apply_filters( |
|
| 232 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 233 | - EEH_HTML::link( |
|
| 234 | - '', |
|
| 235 | - esc_html__('click here to add a new state/province', 'event_espresso'), |
|
| 236 | - '', |
|
| 237 | - 'display-' . $input->html_id(), |
|
| 238 | - 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 239 | - '', |
|
| 240 | - 'data-target="' . $input->html_id() . '"' |
|
| 241 | - ) |
|
| 242 | - ) |
|
| 243 | - ), |
|
| 244 | - // add initial html for hidden container |
|
| 245 | - 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 246 | - apply_filters( |
|
| 247 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 248 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
| 249 | - 'display: none;') . |
|
| 250 | - EEH_HTML::h6( |
|
| 251 | - esc_html__( |
|
| 252 | - 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
| 253 | - 'event_espresso' |
|
| 254 | - ) |
|
| 255 | - ) . |
|
| 256 | - EEH_HTML::ul() . |
|
| 257 | - EEH_HTML::li( |
|
| 258 | - esc_html__( |
|
| 259 | - 'first select the Country that your State/Province belongs to', |
|
| 260 | - 'event_espresso' |
|
| 261 | - ) |
|
| 262 | - ) . |
|
| 263 | - EEH_HTML::li( |
|
| 264 | - esc_html__('enter the name of your State/Province', 'event_espresso') |
|
| 265 | - ) . |
|
| 266 | - EEH_HTML::li( |
|
| 267 | - esc_html__( |
|
| 268 | - 'enter a two to six letter abbreviation for the name of your State/Province', |
|
| 269 | - 'event_espresso' |
|
| 270 | - ) |
|
| 271 | - ) . |
|
| 272 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 273 | - EEH_HTML::ulx() |
|
| 274 | - ) |
|
| 275 | - ), |
|
| 276 | - // NEW STATE COUNTRY |
|
| 277 | - 'new_state_country' => new EE_Country_Select_Input( |
|
| 278 | - $country_options, |
|
| 279 | - array( |
|
| 280 | - 'html_name' => $country_name, |
|
| 281 | - 'html_id' => str_replace( |
|
| 282 | - 'state', |
|
| 283 | - 'nsmf_new_state_country', $input->html_id() |
|
| 284 | - ), |
|
| 285 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
| 286 | - 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
| 287 | - 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
| 288 | - 'required' => false, |
|
| 289 | - ) |
|
| 290 | - ), |
|
| 291 | - // NEW STATE NAME |
|
| 292 | - 'new_state_name' => new EE_Text_Input( |
|
| 293 | - array( |
|
| 294 | - 'html_name' => $state_name, |
|
| 295 | - 'html_id' => str_replace( |
|
| 296 | - 'state', |
|
| 297 | - 'nsmf_new_state_name', $input->html_id() |
|
| 298 | - ), |
|
| 299 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
| 300 | - 'html_label_text' => esc_html__('New State/Province Name', |
|
| 301 | - 'event_espresso'), |
|
| 302 | - 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
| 303 | - 'required' => false, |
|
| 304 | - ) |
|
| 305 | - ), |
|
| 306 | - 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
| 307 | - // NEW STATE NAME |
|
| 308 | - 'new_state_abbrv' => new EE_Text_Input( |
|
| 309 | - array( |
|
| 310 | - 'html_name' => $abbrv_name, |
|
| 311 | - 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
| 312 | - $input->html_id()), |
|
| 313 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 314 | - 'html_label_text' => esc_html__( |
|
| 315 | - 'New State/Province Abbreviation', |
|
| 316 | - 'event_espresso' |
|
| 317 | - ) . ' *', |
|
| 318 | - 'html_other_attributes' => 'size="24"', |
|
| 319 | - 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
| 320 | - 'required' => false, |
|
| 321 | - ) |
|
| 322 | - ), |
|
| 323 | - // "submit" button |
|
| 324 | - 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 325 | - apply_filters( |
|
| 326 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 327 | - EEH_HTML::nbsp(3) . |
|
| 328 | - EEH_HTML::link( |
|
| 329 | - '', |
|
| 330 | - esc_html__('ADD', 'event_espresso'), |
|
| 331 | - '', |
|
| 332 | - 'submit-' . $new_state_submit_id, |
|
| 333 | - 'ee-form-add-new-state-submit button button-secondary', |
|
| 334 | - '', |
|
| 335 | - 'data-target="' . $new_state_submit_id . '"' |
|
| 336 | - ) |
|
| 337 | - ) |
|
| 338 | - ), |
|
| 339 | - // extra info |
|
| 340 | - 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 341 | - apply_filters( |
|
| 342 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 343 | - EEH_HTML::br(2) |
|
| 344 | - . |
|
| 345 | - EEH_HTML::div('', '', 'small-text') |
|
| 346 | - . |
|
| 347 | - EEH_HTML::strong( |
|
| 348 | - '* ' . |
|
| 349 | - esc_html__( |
|
| 350 | - 'Don\'t know your State/Province Abbreviation?', |
|
| 351 | - 'event_espresso' |
|
| 352 | - ) |
|
| 353 | - ) |
|
| 354 | - . |
|
| 355 | - EEH_HTML::br() |
|
| 356 | - . |
|
| 357 | - sprintf( |
|
| 358 | - esc_html__( |
|
| 359 | - 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 360 | - 'event_espresso' |
|
| 361 | - ), |
|
| 362 | - EEH_HTML::link( |
|
| 363 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 364 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 365 | - '', |
|
| 366 | - '', |
|
| 367 | - 'ee-form-add-new-state-wiki-lnk', |
|
| 368 | - '', |
|
| 369 | - 'target="_blank"' |
|
| 370 | - ) |
|
| 371 | - ) |
|
| 372 | - . |
|
| 373 | - EEH_HTML::divx() |
|
| 374 | - . |
|
| 375 | - EEH_HTML::br() |
|
| 376 | - . |
|
| 377 | - EEH_HTML::link( |
|
| 378 | - '', |
|
| 379 | - esc_html__('cancel new State/Province', 'event_espresso'), |
|
| 380 | - '', |
|
| 381 | - 'hide-' . $input->html_id(), |
|
| 382 | - 'ee-form-cancel-new-state-lnk smaller-text', |
|
| 383 | - '', |
|
| 384 | - 'data-target="' . $input->html_id() . '"' |
|
| 385 | - ) |
|
| 386 | - . |
|
| 387 | - EEH_HTML::divx() |
|
| 388 | - . |
|
| 389 | - EEH_HTML::br() |
|
| 390 | - ) |
|
| 391 | - ), |
|
| 392 | - ), |
|
| 393 | - ) |
|
| 394 | - ); |
|
| 395 | - $question_group_reg_form->add_subsections( |
|
| 396 | - array('new_state_micro_form' => $new_state_micro_form), |
|
| 397 | - 'state', |
|
| 398 | - false |
|
| 399 | - ); |
|
| 400 | - } |
|
| 401 | - return $question_group_reg_form; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * set_new_state_input_width |
|
| 408 | - * |
|
| 409 | - * @return int|string |
|
| 410 | - * @throws EE_Error |
|
| 411 | - * @throws InvalidArgumentException |
|
| 412 | - * @throws InvalidDataTypeException |
|
| 413 | - * @throws InvalidInterfaceException |
|
| 414 | - * @throws ReflectionException |
|
| 415 | - */ |
|
| 416 | - public static function add_new_state() |
|
| 417 | - { |
|
| 418 | - $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
| 419 | - if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
| 420 | - EE_Registry::instance()->load_model('State'); |
|
| 421 | - // grab country ISO code, new state name, and new state abbreviation |
|
| 422 | - $state_country = $REQ->is_set('nsmf_new_state_country') |
|
| 423 | - ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
| 424 | - : false; |
|
| 425 | - $state_name = $REQ->is_set('nsmf_new_state_name') |
|
| 426 | - ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
| 427 | - : false; |
|
| 428 | - $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
| 429 | - ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
| 430 | - : false; |
|
| 431 | - if ($state_country && $state_name && $state_abbr) { |
|
| 432 | - $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
| 433 | - 'CNT_ISO' => strtoupper($state_country), |
|
| 434 | - 'STA_abbrev' => strtoupper($state_abbr), |
|
| 435 | - 'STA_name' => ucwords($state_name), |
|
| 436 | - 'STA_active' => false, |
|
| 437 | - )); |
|
| 438 | - if ($new_state instanceof EE_State) { |
|
| 439 | - // clean house |
|
| 440 | - EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
| 441 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
| 442 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
| 443 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
| 444 | - // get any existing new states |
|
| 445 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 446 | - 'nsmf_new_states' |
|
| 447 | - ); |
|
| 448 | - $new_states[$new_state->ID()] = $new_state; |
|
| 449 | - EE_Registry::instance()->SSN->set_session_data( |
|
| 450 | - array('nsmf_new_states' => $new_states) |
|
| 451 | - ); |
|
| 452 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 453 | - echo wp_json_encode(array( |
|
| 454 | - 'success' => true, |
|
| 455 | - 'id' => $new_state->ID(), |
|
| 456 | - 'name' => $new_state->name(), |
|
| 457 | - 'abbrev' => $new_state->abbrev(), |
|
| 458 | - 'country_iso' => $new_state->country_iso(), |
|
| 459 | - 'country_name' => $new_state->country()->name(), |
|
| 460 | - )); |
|
| 461 | - exit(); |
|
| 462 | - } |
|
| 463 | - return $new_state->ID(); |
|
| 464 | - } |
|
| 465 | - } else { |
|
| 466 | - $error = esc_html__( |
|
| 467 | - 'A new State/Province could not be added because invalid or missing data was received.', |
|
| 468 | - 'event_espresso' |
|
| 469 | - ); |
|
| 470 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 471 | - echo wp_json_encode(array('error' => $error)); |
|
| 472 | - exit(); |
|
| 473 | - } |
|
| 474 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - return false; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * recursively drills down through request params to remove any that were added by this module |
|
| 484 | - * |
|
| 485 | - * @param array $request_params |
|
| 486 | - * @return array |
|
| 487 | - */ |
|
| 488 | - public static function filter_checkout_request_params($request_params) |
|
| 489 | - { |
|
| 490 | - foreach ($request_params as $form_section) { |
|
| 491 | - if (is_array($form_section)) { |
|
| 492 | - EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 493 | - EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - return $request_params; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * @param array $request_params |
|
| 503 | - * @return array |
|
| 504 | - */ |
|
| 505 | - public static function unset_new_state_request_params($request_params) |
|
| 506 | - { |
|
| 507 | - unset( |
|
| 508 | - $request_params['new_state_micro_form'], |
|
| 509 | - $request_params['new_state_micro_add_new_state'], |
|
| 510 | - $request_params['new_state_micro_new_state_country'], |
|
| 511 | - $request_params['new_state_micro_new_state_name'], |
|
| 512 | - $request_params['new_state_micro_new_state_abbrv'] |
|
| 513 | - ); |
|
| 514 | - return $request_params; |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - |
|
| 518 | - |
|
| 519 | - /** |
|
| 520 | - * @param array $props_n_values |
|
| 521 | - * @return bool |
|
| 522 | - * @throws EE_Error |
|
| 523 | - * @throws InvalidArgumentException |
|
| 524 | - * @throws InvalidDataTypeException |
|
| 525 | - * @throws InvalidInterfaceException |
|
| 526 | - */ |
|
| 527 | - public static function save_new_state_to_db($props_n_values = array()) |
|
| 528 | - { |
|
| 529 | - $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
| 530 | - if (! empty($existing_state)) { |
|
| 531 | - return array_pop($existing_state); |
|
| 532 | - } |
|
| 533 | - $new_state = EE_State::new_instance($props_n_values); |
|
| 534 | - if ($new_state instanceof EE_State) { |
|
| 535 | - $country_settings_url = add_query_arg( |
|
| 536 | - array( |
|
| 537 | - 'page' => 'espresso_general_settings', |
|
| 538 | - 'action' => 'country_settings', |
|
| 539 | - 'country' => $new_state->country_iso(), |
|
| 540 | - ), |
|
| 541 | - admin_url('admin.php') |
|
| 542 | - ); |
|
| 543 | - // if not non-ajax admin |
|
| 544 | - new PersistentAdminNotice( |
|
| 545 | - 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
| 546 | - sprintf( |
|
| 547 | - esc_html__( |
|
| 548 | - '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.', |
|
| 549 | - 'event_espresso' |
|
| 550 | - ), |
|
| 551 | - '<b>' . $new_state->name() . '</b>', |
|
| 552 | - '<b>' . $new_state->abbrev() . '</b>', |
|
| 553 | - '<b>' . $new_state->country()->name() . '</b>', |
|
| 554 | - '<a href="' |
|
| 555 | - . $country_settings_url |
|
| 556 | - . '">' |
|
| 557 | - . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
| 558 | - 'event_espresso') |
|
| 559 | - . '</a>', |
|
| 560 | - '<br />' |
|
| 561 | - ) |
|
| 562 | - ); |
|
| 563 | - $new_state->save(); |
|
| 564 | - EEM_State::instance()->reset_cached_states(); |
|
| 565 | - return $new_state; |
|
| 566 | - } |
|
| 567 | - return false; |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * @param string $CNT_ISO |
|
| 574 | - * @param string $STA_ID |
|
| 575 | - * @param array $cols_n_values |
|
| 576 | - * @return void |
|
| 577 | - * @throws DomainException |
|
| 578 | - * @throws EE_Error |
|
| 579 | - * @throws InvalidArgumentException |
|
| 580 | - * @throws InvalidDataTypeException |
|
| 581 | - * @throws InvalidInterfaceException |
|
| 582 | - */ |
|
| 583 | - public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
| 584 | - { |
|
| 585 | - if (! $CNT_ISO) { |
|
| 586 | - EE_Error::add_error( |
|
| 587 | - esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
| 588 | - __FILE__, |
|
| 589 | - __FUNCTION__, |
|
| 590 | - __LINE__ |
|
| 591 | - ); |
|
| 592 | - } |
|
| 593 | - $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 594 | - : false; |
|
| 595 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 596 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 597 | - if ($state instanceof EE_State) { |
|
| 598 | - $STA_abbrev = $state->abbrev(); |
|
| 599 | - } |
|
| 600 | - } |
|
| 601 | - if (! $STA_abbrev) { |
|
| 602 | - EE_Error::add_error( |
|
| 603 | - esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 604 | - __FILE__, |
|
| 605 | - __FUNCTION__, |
|
| 606 | - __LINE__ |
|
| 607 | - ); |
|
| 608 | - } |
|
| 609 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 610 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 611 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 612 | - ); |
|
| 613 | - $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * @param EE_State[] $state_options |
|
| 620 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 621 | - * @param EE_Registration $registration |
|
| 622 | - * @param EE_Question $question |
|
| 623 | - * @param $answer |
|
| 624 | - * @return array |
|
| 625 | - * @throws EE_Error |
|
| 626 | - * @throws InvalidArgumentException |
|
| 627 | - * @throws InvalidDataTypeException |
|
| 628 | - * @throws InvalidInterfaceException |
|
| 629 | - */ |
|
| 630 | - public static function inject_new_reg_state_into_options( |
|
| 631 | - $state_options = array(), |
|
| 632 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 633 | - EE_Registration $registration, |
|
| 634 | - EE_Question $question, |
|
| 635 | - $answer |
|
| 636 | - ) { |
|
| 637 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 638 | - && $question->type() === EEM_Question::QST_type_state |
|
| 639 | - ) { |
|
| 640 | - $STA_ID = $answer->value(); |
|
| 641 | - if (! empty($STA_ID)) { |
|
| 642 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 643 | - if ($state instanceof EE_State) { |
|
| 644 | - $country = $state->country(); |
|
| 645 | - if ($country instanceof EE_Country) { |
|
| 646 | - if (! isset($state_options[$country->name()])) { |
|
| 647 | - $state_options[$country->name()] = array(); |
|
| 648 | - } |
|
| 649 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
| 650 | - $state_options[$country->name()][$STA_ID] = $state->name(); |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - } |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - return $state_options; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * @param EE_Country[] $country_options |
|
| 663 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 664 | - * @param EE_Registration $registration |
|
| 665 | - * @param EE_Question $question |
|
| 666 | - * @param $answer |
|
| 667 | - * @return array |
|
| 668 | - * @throws EE_Error |
|
| 669 | - * @throws InvalidArgumentException |
|
| 670 | - * @throws InvalidDataTypeException |
|
| 671 | - * @throws InvalidInterfaceException |
|
| 672 | - */ |
|
| 673 | - public static function inject_new_reg_country_into_options( |
|
| 674 | - $country_options = array(), |
|
| 675 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 676 | - EE_Registration $registration, |
|
| 677 | - EE_Question $question, |
|
| 678 | - $answer |
|
| 679 | - ) { |
|
| 680 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 681 | - && $question->type() |
|
| 682 | - === EEM_Question::QST_type_country |
|
| 683 | - ) { |
|
| 684 | - $CNT_ISO = $answer->value(); |
|
| 685 | - if (! empty($CNT_ISO)) { |
|
| 686 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 687 | - if ($country instanceof EE_Country) { |
|
| 688 | - if (! isset($country_options[$CNT_ISO])) { |
|
| 689 | - $country_options[$CNT_ISO] = $country->name(); |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - } |
|
| 693 | - } |
|
| 694 | - return $country_options; |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * @param EE_State[] $state_options |
|
| 701 | - * @return array |
|
| 702 | - * @throws EE_Error |
|
| 703 | - * @throws InvalidArgumentException |
|
| 704 | - * @throws InvalidDataTypeException |
|
| 705 | - * @throws InvalidInterfaceException |
|
| 706 | - */ |
|
| 707 | - public static function state_options($state_options = array()) |
|
| 708 | - { |
|
| 709 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 710 | - foreach ($new_states as $new_state) { |
|
| 711 | - if ( |
|
| 712 | - $new_state instanceof EE_State |
|
| 713 | - && $new_state->country() instanceof EE_Country |
|
| 714 | - ) { |
|
| 715 | - $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
| 716 | - } |
|
| 717 | - } |
|
| 718 | - return $state_options; |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - |
|
| 722 | - |
|
| 723 | - /** |
|
| 724 | - * @return array |
|
| 725 | - * @throws InvalidArgumentException |
|
| 726 | - * @throws InvalidDataTypeException |
|
| 727 | - * @throws InvalidInterfaceException |
|
| 728 | - */ |
|
| 729 | - protected static function _get_new_states() |
|
| 730 | - { |
|
| 731 | - $new_states = array(); |
|
| 732 | - if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 733 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 734 | - 'nsmf_new_states' |
|
| 735 | - ); |
|
| 736 | - } |
|
| 737 | - return is_array($new_states) ? $new_states : array(); |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - |
|
| 741 | - |
|
| 742 | - /** |
|
| 743 | - * @param EE_Country[] $country_options |
|
| 744 | - * @return array |
|
| 745 | - * @throws EE_Error |
|
| 746 | - * @throws InvalidArgumentException |
|
| 747 | - * @throws InvalidDataTypeException |
|
| 748 | - * @throws InvalidInterfaceException |
|
| 749 | - */ |
|
| 750 | - public static function country_options($country_options = array()) |
|
| 751 | - { |
|
| 752 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 753 | - foreach ($new_states as $new_state) { |
|
| 754 | - if ( |
|
| 755 | - $new_state instanceof EE_State |
|
| 756 | - && $new_state->country() instanceof EE_Country |
|
| 757 | - ) { |
|
| 758 | - $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
| 759 | - } |
|
| 760 | - } |
|
| 761 | - return $country_options; |
|
| 762 | - } |
|
| 25 | + /** |
|
| 26 | + * @return EED_Module|EED_Add_New_State |
|
| 27 | + */ |
|
| 28 | + public static function instance() |
|
| 29 | + { |
|
| 30 | + return parent::get_instance(__CLASS__); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 37 | + * |
|
| 38 | + * @return void |
|
| 39 | + */ |
|
| 40 | + public static function set_hooks() |
|
| 41 | + { |
|
| 42 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 43 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
| 44 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
| 45 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 46 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 47 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 48 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 49 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 50 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 51 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 52 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 53 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 54 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 55 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 56 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 57 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 58 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 65 | + * |
|
| 66 | + * @return void |
|
| 67 | + */ |
|
| 68 | + public static function set_hooks_admin() |
|
| 69 | + { |
|
| 70 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 71 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 72 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 73 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 74 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 75 | + add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 76 | + add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 77 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 78 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 79 | + add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 80 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 81 | + add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 82 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 83 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 84 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 85 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 86 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 87 | + add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 88 | + array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
| 89 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 90 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 91 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 92 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @return void |
|
| 99 | + */ |
|
| 100 | + public static function set_definitions() |
|
| 101 | + { |
|
| 102 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 103 | + define('ANS_TEMPLATES_PATH', str_replace( |
|
| 104 | + '\\', |
|
| 105 | + DS, |
|
| 106 | + plugin_dir_path(__FILE__)) . 'templates' . DS |
|
| 107 | + ); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @param WP $WP |
|
| 114 | + * @return void |
|
| 115 | + */ |
|
| 116 | + public function run($WP) |
|
| 117 | + { |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @return void |
|
| 124 | + */ |
|
| 125 | + public static function translate_js_strings() |
|
| 126 | + { |
|
| 127 | + EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 128 | + 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 129 | + 'event_espresso' |
|
| 130 | + ); |
|
| 131 | + EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 132 | + 'In order to proceed, you need to enter the name of your State/Province.', |
|
| 133 | + 'event_espresso' |
|
| 134 | + ); |
|
| 135 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 136 | + 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 137 | + 'event_espresso' |
|
| 138 | + ); |
|
| 139 | + EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 140 | + 'The new state was successfully saved to the database.', |
|
| 141 | + 'event_espresso' |
|
| 142 | + ); |
|
| 143 | + EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
| 144 | + 'An unknown error has occurred on the server while saving the new state to the database.', |
|
| 145 | + 'event_espresso' |
|
| 146 | + ); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @return void |
|
| 153 | + */ |
|
| 154 | + public static function wp_enqueue_scripts() |
|
| 155 | + { |
|
| 156 | + if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 157 | + wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
| 158 | + array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
| 159 | + wp_enqueue_script('add_new_state'); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * display_add_new_state_micro_form |
|
| 167 | + * |
|
| 168 | + * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 169 | + * @return string |
|
| 170 | + * @throws EE_Error |
|
| 171 | + * @throws InvalidArgumentException |
|
| 172 | + * @throws InvalidDataTypeException |
|
| 173 | + * @throws InvalidInterfaceException |
|
| 174 | + */ |
|
| 175 | + // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
| 176 | + public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 177 | + { |
|
| 178 | + // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 179 | + // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 180 | + $action = EE_Registry::instance()->REQ->get('action', ''); |
|
| 181 | + // is the "state" question in this form section? |
|
| 182 | + $input = $question_group_reg_form->get_subsection('state'); |
|
| 183 | + if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 184 | + //ok then all we need to do is make sure the input's HTML name is consistent |
|
| 185 | + //by forcing it to set it now, like it did while getting the form for display |
|
| 186 | + if ($input instanceof EE_State_Select_Input) { |
|
| 187 | + $input->html_name(); |
|
| 188 | + } |
|
| 189 | + return $question_group_reg_form; |
|
| 190 | + } |
|
| 191 | + // we're only doing this for state select inputs |
|
| 192 | + if ($input instanceof EE_State_Select_Input && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 193 | + // grab any set values from the request |
|
| 194 | + $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 195 | + $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 196 | + $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 197 | + $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 198 | + $country_options = array(); |
|
| 199 | + $countries = EEM_Country::instance()->get_all_countries(); |
|
| 200 | + if (! empty($countries)) { |
|
| 201 | + foreach ($countries as $country) { |
|
| 202 | + if ($country instanceof EE_Country) { |
|
| 203 | + $country_options[$country->ID()] = $country->name(); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 208 | + array( |
|
| 209 | + 'name' => 'new_state_micro_form', |
|
| 210 | + 'html_id' => 'new_state_micro_form', |
|
| 211 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 212 | + 'subsections' => array( |
|
| 213 | + // add hidden input to indicate that a new state is being added |
|
| 214 | + 'add_new_state' => new EE_Hidden_Input( |
|
| 215 | + array( |
|
| 216 | + 'html_name' => str_replace( |
|
| 217 | + 'state', |
|
| 218 | + 'nsmf_add_new_state', |
|
| 219 | + $input->html_name() |
|
| 220 | + ), |
|
| 221 | + 'html_id' => str_replace( |
|
| 222 | + 'state', |
|
| 223 | + 'nsmf_add_new_state', |
|
| 224 | + $input->html_id() |
|
| 225 | + ), |
|
| 226 | + 'default' => 0, |
|
| 227 | + ) |
|
| 228 | + ), |
|
| 229 | + // add link for displaying hidden container |
|
| 230 | + 'click_here_link' => new EE_Form_Section_HTML( |
|
| 231 | + apply_filters( |
|
| 232 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 233 | + EEH_HTML::link( |
|
| 234 | + '', |
|
| 235 | + esc_html__('click here to add a new state/province', 'event_espresso'), |
|
| 236 | + '', |
|
| 237 | + 'display-' . $input->html_id(), |
|
| 238 | + 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 239 | + '', |
|
| 240 | + 'data-target="' . $input->html_id() . '"' |
|
| 241 | + ) |
|
| 242 | + ) |
|
| 243 | + ), |
|
| 244 | + // add initial html for hidden container |
|
| 245 | + 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 246 | + apply_filters( |
|
| 247 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 248 | + EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
| 249 | + 'display: none;') . |
|
| 250 | + EEH_HTML::h6( |
|
| 251 | + esc_html__( |
|
| 252 | + 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
| 253 | + 'event_espresso' |
|
| 254 | + ) |
|
| 255 | + ) . |
|
| 256 | + EEH_HTML::ul() . |
|
| 257 | + EEH_HTML::li( |
|
| 258 | + esc_html__( |
|
| 259 | + 'first select the Country that your State/Province belongs to', |
|
| 260 | + 'event_espresso' |
|
| 261 | + ) |
|
| 262 | + ) . |
|
| 263 | + EEH_HTML::li( |
|
| 264 | + esc_html__('enter the name of your State/Province', 'event_espresso') |
|
| 265 | + ) . |
|
| 266 | + EEH_HTML::li( |
|
| 267 | + esc_html__( |
|
| 268 | + 'enter a two to six letter abbreviation for the name of your State/Province', |
|
| 269 | + 'event_espresso' |
|
| 270 | + ) |
|
| 271 | + ) . |
|
| 272 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 273 | + EEH_HTML::ulx() |
|
| 274 | + ) |
|
| 275 | + ), |
|
| 276 | + // NEW STATE COUNTRY |
|
| 277 | + 'new_state_country' => new EE_Country_Select_Input( |
|
| 278 | + $country_options, |
|
| 279 | + array( |
|
| 280 | + 'html_name' => $country_name, |
|
| 281 | + 'html_id' => str_replace( |
|
| 282 | + 'state', |
|
| 283 | + 'nsmf_new_state_country', $input->html_id() |
|
| 284 | + ), |
|
| 285 | + 'html_class' => $input->html_class() . ' new-state-country', |
|
| 286 | + 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
| 287 | + 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
| 288 | + 'required' => false, |
|
| 289 | + ) |
|
| 290 | + ), |
|
| 291 | + // NEW STATE NAME |
|
| 292 | + 'new_state_name' => new EE_Text_Input( |
|
| 293 | + array( |
|
| 294 | + 'html_name' => $state_name, |
|
| 295 | + 'html_id' => str_replace( |
|
| 296 | + 'state', |
|
| 297 | + 'nsmf_new_state_name', $input->html_id() |
|
| 298 | + ), |
|
| 299 | + 'html_class' => $input->html_class() . ' new-state-state', |
|
| 300 | + 'html_label_text' => esc_html__('New State/Province Name', |
|
| 301 | + 'event_espresso'), |
|
| 302 | + 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
| 303 | + 'required' => false, |
|
| 304 | + ) |
|
| 305 | + ), |
|
| 306 | + 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
| 307 | + // NEW STATE NAME |
|
| 308 | + 'new_state_abbrv' => new EE_Text_Input( |
|
| 309 | + array( |
|
| 310 | + 'html_name' => $abbrv_name, |
|
| 311 | + 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
| 312 | + $input->html_id()), |
|
| 313 | + 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 314 | + 'html_label_text' => esc_html__( |
|
| 315 | + 'New State/Province Abbreviation', |
|
| 316 | + 'event_espresso' |
|
| 317 | + ) . ' *', |
|
| 318 | + 'html_other_attributes' => 'size="24"', |
|
| 319 | + 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
| 320 | + 'required' => false, |
|
| 321 | + ) |
|
| 322 | + ), |
|
| 323 | + // "submit" button |
|
| 324 | + 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 325 | + apply_filters( |
|
| 326 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 327 | + EEH_HTML::nbsp(3) . |
|
| 328 | + EEH_HTML::link( |
|
| 329 | + '', |
|
| 330 | + esc_html__('ADD', 'event_espresso'), |
|
| 331 | + '', |
|
| 332 | + 'submit-' . $new_state_submit_id, |
|
| 333 | + 'ee-form-add-new-state-submit button button-secondary', |
|
| 334 | + '', |
|
| 335 | + 'data-target="' . $new_state_submit_id . '"' |
|
| 336 | + ) |
|
| 337 | + ) |
|
| 338 | + ), |
|
| 339 | + // extra info |
|
| 340 | + 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 341 | + apply_filters( |
|
| 342 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 343 | + EEH_HTML::br(2) |
|
| 344 | + . |
|
| 345 | + EEH_HTML::div('', '', 'small-text') |
|
| 346 | + . |
|
| 347 | + EEH_HTML::strong( |
|
| 348 | + '* ' . |
|
| 349 | + esc_html__( |
|
| 350 | + 'Don\'t know your State/Province Abbreviation?', |
|
| 351 | + 'event_espresso' |
|
| 352 | + ) |
|
| 353 | + ) |
|
| 354 | + . |
|
| 355 | + EEH_HTML::br() |
|
| 356 | + . |
|
| 357 | + sprintf( |
|
| 358 | + esc_html__( |
|
| 359 | + 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 360 | + 'event_espresso' |
|
| 361 | + ), |
|
| 362 | + EEH_HTML::link( |
|
| 363 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 364 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 365 | + '', |
|
| 366 | + '', |
|
| 367 | + 'ee-form-add-new-state-wiki-lnk', |
|
| 368 | + '', |
|
| 369 | + 'target="_blank"' |
|
| 370 | + ) |
|
| 371 | + ) |
|
| 372 | + . |
|
| 373 | + EEH_HTML::divx() |
|
| 374 | + . |
|
| 375 | + EEH_HTML::br() |
|
| 376 | + . |
|
| 377 | + EEH_HTML::link( |
|
| 378 | + '', |
|
| 379 | + esc_html__('cancel new State/Province', 'event_espresso'), |
|
| 380 | + '', |
|
| 381 | + 'hide-' . $input->html_id(), |
|
| 382 | + 'ee-form-cancel-new-state-lnk smaller-text', |
|
| 383 | + '', |
|
| 384 | + 'data-target="' . $input->html_id() . '"' |
|
| 385 | + ) |
|
| 386 | + . |
|
| 387 | + EEH_HTML::divx() |
|
| 388 | + . |
|
| 389 | + EEH_HTML::br() |
|
| 390 | + ) |
|
| 391 | + ), |
|
| 392 | + ), |
|
| 393 | + ) |
|
| 394 | + ); |
|
| 395 | + $question_group_reg_form->add_subsections( |
|
| 396 | + array('new_state_micro_form' => $new_state_micro_form), |
|
| 397 | + 'state', |
|
| 398 | + false |
|
| 399 | + ); |
|
| 400 | + } |
|
| 401 | + return $question_group_reg_form; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * set_new_state_input_width |
|
| 408 | + * |
|
| 409 | + * @return int|string |
|
| 410 | + * @throws EE_Error |
|
| 411 | + * @throws InvalidArgumentException |
|
| 412 | + * @throws InvalidDataTypeException |
|
| 413 | + * @throws InvalidInterfaceException |
|
| 414 | + * @throws ReflectionException |
|
| 415 | + */ |
|
| 416 | + public static function add_new_state() |
|
| 417 | + { |
|
| 418 | + $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
| 419 | + if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
| 420 | + EE_Registry::instance()->load_model('State'); |
|
| 421 | + // grab country ISO code, new state name, and new state abbreviation |
|
| 422 | + $state_country = $REQ->is_set('nsmf_new_state_country') |
|
| 423 | + ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
| 424 | + : false; |
|
| 425 | + $state_name = $REQ->is_set('nsmf_new_state_name') |
|
| 426 | + ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
| 427 | + : false; |
|
| 428 | + $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
| 429 | + ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
| 430 | + : false; |
|
| 431 | + if ($state_country && $state_name && $state_abbr) { |
|
| 432 | + $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
| 433 | + 'CNT_ISO' => strtoupper($state_country), |
|
| 434 | + 'STA_abbrev' => strtoupper($state_abbr), |
|
| 435 | + 'STA_name' => ucwords($state_name), |
|
| 436 | + 'STA_active' => false, |
|
| 437 | + )); |
|
| 438 | + if ($new_state instanceof EE_State) { |
|
| 439 | + // clean house |
|
| 440 | + EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
| 441 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
| 442 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
| 443 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
| 444 | + // get any existing new states |
|
| 445 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 446 | + 'nsmf_new_states' |
|
| 447 | + ); |
|
| 448 | + $new_states[$new_state->ID()] = $new_state; |
|
| 449 | + EE_Registry::instance()->SSN->set_session_data( |
|
| 450 | + array('nsmf_new_states' => $new_states) |
|
| 451 | + ); |
|
| 452 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 453 | + echo wp_json_encode(array( |
|
| 454 | + 'success' => true, |
|
| 455 | + 'id' => $new_state->ID(), |
|
| 456 | + 'name' => $new_state->name(), |
|
| 457 | + 'abbrev' => $new_state->abbrev(), |
|
| 458 | + 'country_iso' => $new_state->country_iso(), |
|
| 459 | + 'country_name' => $new_state->country()->name(), |
|
| 460 | + )); |
|
| 461 | + exit(); |
|
| 462 | + } |
|
| 463 | + return $new_state->ID(); |
|
| 464 | + } |
|
| 465 | + } else { |
|
| 466 | + $error = esc_html__( |
|
| 467 | + 'A new State/Province could not be added because invalid or missing data was received.', |
|
| 468 | + 'event_espresso' |
|
| 469 | + ); |
|
| 470 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 471 | + echo wp_json_encode(array('error' => $error)); |
|
| 472 | + exit(); |
|
| 473 | + } |
|
| 474 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + return false; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * recursively drills down through request params to remove any that were added by this module |
|
| 484 | + * |
|
| 485 | + * @param array $request_params |
|
| 486 | + * @return array |
|
| 487 | + */ |
|
| 488 | + public static function filter_checkout_request_params($request_params) |
|
| 489 | + { |
|
| 490 | + foreach ($request_params as $form_section) { |
|
| 491 | + if (is_array($form_section)) { |
|
| 492 | + EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 493 | + EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + return $request_params; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * @param array $request_params |
|
| 503 | + * @return array |
|
| 504 | + */ |
|
| 505 | + public static function unset_new_state_request_params($request_params) |
|
| 506 | + { |
|
| 507 | + unset( |
|
| 508 | + $request_params['new_state_micro_form'], |
|
| 509 | + $request_params['new_state_micro_add_new_state'], |
|
| 510 | + $request_params['new_state_micro_new_state_country'], |
|
| 511 | + $request_params['new_state_micro_new_state_name'], |
|
| 512 | + $request_params['new_state_micro_new_state_abbrv'] |
|
| 513 | + ); |
|
| 514 | + return $request_params; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + |
|
| 518 | + |
|
| 519 | + /** |
|
| 520 | + * @param array $props_n_values |
|
| 521 | + * @return bool |
|
| 522 | + * @throws EE_Error |
|
| 523 | + * @throws InvalidArgumentException |
|
| 524 | + * @throws InvalidDataTypeException |
|
| 525 | + * @throws InvalidInterfaceException |
|
| 526 | + */ |
|
| 527 | + public static function save_new_state_to_db($props_n_values = array()) |
|
| 528 | + { |
|
| 529 | + $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
| 530 | + if (! empty($existing_state)) { |
|
| 531 | + return array_pop($existing_state); |
|
| 532 | + } |
|
| 533 | + $new_state = EE_State::new_instance($props_n_values); |
|
| 534 | + if ($new_state instanceof EE_State) { |
|
| 535 | + $country_settings_url = add_query_arg( |
|
| 536 | + array( |
|
| 537 | + 'page' => 'espresso_general_settings', |
|
| 538 | + 'action' => 'country_settings', |
|
| 539 | + 'country' => $new_state->country_iso(), |
|
| 540 | + ), |
|
| 541 | + admin_url('admin.php') |
|
| 542 | + ); |
|
| 543 | + // if not non-ajax admin |
|
| 544 | + new PersistentAdminNotice( |
|
| 545 | + 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
| 546 | + sprintf( |
|
| 547 | + esc_html__( |
|
| 548 | + '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.', |
|
| 549 | + 'event_espresso' |
|
| 550 | + ), |
|
| 551 | + '<b>' . $new_state->name() . '</b>', |
|
| 552 | + '<b>' . $new_state->abbrev() . '</b>', |
|
| 553 | + '<b>' . $new_state->country()->name() . '</b>', |
|
| 554 | + '<a href="' |
|
| 555 | + . $country_settings_url |
|
| 556 | + . '">' |
|
| 557 | + . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
| 558 | + 'event_espresso') |
|
| 559 | + . '</a>', |
|
| 560 | + '<br />' |
|
| 561 | + ) |
|
| 562 | + ); |
|
| 563 | + $new_state->save(); |
|
| 564 | + EEM_State::instance()->reset_cached_states(); |
|
| 565 | + return $new_state; |
|
| 566 | + } |
|
| 567 | + return false; |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * @param string $CNT_ISO |
|
| 574 | + * @param string $STA_ID |
|
| 575 | + * @param array $cols_n_values |
|
| 576 | + * @return void |
|
| 577 | + * @throws DomainException |
|
| 578 | + * @throws EE_Error |
|
| 579 | + * @throws InvalidArgumentException |
|
| 580 | + * @throws InvalidDataTypeException |
|
| 581 | + * @throws InvalidInterfaceException |
|
| 582 | + */ |
|
| 583 | + public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
| 584 | + { |
|
| 585 | + if (! $CNT_ISO) { |
|
| 586 | + EE_Error::add_error( |
|
| 587 | + esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
| 588 | + __FILE__, |
|
| 589 | + __FUNCTION__, |
|
| 590 | + __LINE__ |
|
| 591 | + ); |
|
| 592 | + } |
|
| 593 | + $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 594 | + : false; |
|
| 595 | + if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 596 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 597 | + if ($state instanceof EE_State) { |
|
| 598 | + $STA_abbrev = $state->abbrev(); |
|
| 599 | + } |
|
| 600 | + } |
|
| 601 | + if (! $STA_abbrev) { |
|
| 602 | + EE_Error::add_error( |
|
| 603 | + esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 604 | + __FILE__, |
|
| 605 | + __FUNCTION__, |
|
| 606 | + __LINE__ |
|
| 607 | + ); |
|
| 608 | + } |
|
| 609 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 610 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 611 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 612 | + ); |
|
| 613 | + $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * @param EE_State[] $state_options |
|
| 620 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 621 | + * @param EE_Registration $registration |
|
| 622 | + * @param EE_Question $question |
|
| 623 | + * @param $answer |
|
| 624 | + * @return array |
|
| 625 | + * @throws EE_Error |
|
| 626 | + * @throws InvalidArgumentException |
|
| 627 | + * @throws InvalidDataTypeException |
|
| 628 | + * @throws InvalidInterfaceException |
|
| 629 | + */ |
|
| 630 | + public static function inject_new_reg_state_into_options( |
|
| 631 | + $state_options = array(), |
|
| 632 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 633 | + EE_Registration $registration, |
|
| 634 | + EE_Question $question, |
|
| 635 | + $answer |
|
| 636 | + ) { |
|
| 637 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 638 | + && $question->type() === EEM_Question::QST_type_state |
|
| 639 | + ) { |
|
| 640 | + $STA_ID = $answer->value(); |
|
| 641 | + if (! empty($STA_ID)) { |
|
| 642 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 643 | + if ($state instanceof EE_State) { |
|
| 644 | + $country = $state->country(); |
|
| 645 | + if ($country instanceof EE_Country) { |
|
| 646 | + if (! isset($state_options[$country->name()])) { |
|
| 647 | + $state_options[$country->name()] = array(); |
|
| 648 | + } |
|
| 649 | + if (! isset($state_options[$country->name()][$STA_ID])) { |
|
| 650 | + $state_options[$country->name()][$STA_ID] = $state->name(); |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + } |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + return $state_options; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * @param EE_Country[] $country_options |
|
| 663 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 664 | + * @param EE_Registration $registration |
|
| 665 | + * @param EE_Question $question |
|
| 666 | + * @param $answer |
|
| 667 | + * @return array |
|
| 668 | + * @throws EE_Error |
|
| 669 | + * @throws InvalidArgumentException |
|
| 670 | + * @throws InvalidDataTypeException |
|
| 671 | + * @throws InvalidInterfaceException |
|
| 672 | + */ |
|
| 673 | + public static function inject_new_reg_country_into_options( |
|
| 674 | + $country_options = array(), |
|
| 675 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 676 | + EE_Registration $registration, |
|
| 677 | + EE_Question $question, |
|
| 678 | + $answer |
|
| 679 | + ) { |
|
| 680 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 681 | + && $question->type() |
|
| 682 | + === EEM_Question::QST_type_country |
|
| 683 | + ) { |
|
| 684 | + $CNT_ISO = $answer->value(); |
|
| 685 | + if (! empty($CNT_ISO)) { |
|
| 686 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 687 | + if ($country instanceof EE_Country) { |
|
| 688 | + if (! isset($country_options[$CNT_ISO])) { |
|
| 689 | + $country_options[$CNT_ISO] = $country->name(); |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | + return $country_options; |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * @param EE_State[] $state_options |
|
| 701 | + * @return array |
|
| 702 | + * @throws EE_Error |
|
| 703 | + * @throws InvalidArgumentException |
|
| 704 | + * @throws InvalidDataTypeException |
|
| 705 | + * @throws InvalidInterfaceException |
|
| 706 | + */ |
|
| 707 | + public static function state_options($state_options = array()) |
|
| 708 | + { |
|
| 709 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 710 | + foreach ($new_states as $new_state) { |
|
| 711 | + if ( |
|
| 712 | + $new_state instanceof EE_State |
|
| 713 | + && $new_state->country() instanceof EE_Country |
|
| 714 | + ) { |
|
| 715 | + $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
| 716 | + } |
|
| 717 | + } |
|
| 718 | + return $state_options; |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + |
|
| 722 | + |
|
| 723 | + /** |
|
| 724 | + * @return array |
|
| 725 | + * @throws InvalidArgumentException |
|
| 726 | + * @throws InvalidDataTypeException |
|
| 727 | + * @throws InvalidInterfaceException |
|
| 728 | + */ |
|
| 729 | + protected static function _get_new_states() |
|
| 730 | + { |
|
| 731 | + $new_states = array(); |
|
| 732 | + if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 733 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 734 | + 'nsmf_new_states' |
|
| 735 | + ); |
|
| 736 | + } |
|
| 737 | + return is_array($new_states) ? $new_states : array(); |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + |
|
| 741 | + |
|
| 742 | + /** |
|
| 743 | + * @param EE_Country[] $country_options |
|
| 744 | + * @return array |
|
| 745 | + * @throws EE_Error |
|
| 746 | + * @throws InvalidArgumentException |
|
| 747 | + * @throws InvalidDataTypeException |
|
| 748 | + * @throws InvalidInterfaceException |
|
| 749 | + */ |
|
| 750 | + public static function country_options($country_options = array()) |
|
| 751 | + { |
|
| 752 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 753 | + foreach ($new_states as $new_state) { |
|
| 754 | + if ( |
|
| 755 | + $new_state instanceof EE_State |
|
| 756 | + && $new_state->country() instanceof EE_Country |
|
| 757 | + ) { |
|
| 758 | + $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
| 759 | + } |
|
| 760 | + } |
|
| 761 | + return $country_options; |
|
| 762 | + } |
|
| 763 | 763 | |
| 764 | 764 | |
| 765 | 765 | |
@@ -27,746 +27,746 @@ |
||
| 27 | 27 | class EE_Attendee extends EE_CPT_Base implements EEI_Contact, EEI_Address, EEI_Admin_Links, EEI_Attendee |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Sets some dynamic defaults |
|
| 32 | - * |
|
| 33 | - * @param array $fieldValues |
|
| 34 | - * @param bool $bydb |
|
| 35 | - * @param string $timezone |
|
| 36 | - * @param array $date_formats |
|
| 37 | - * @throws EE_Error |
|
| 38 | - */ |
|
| 39 | - protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
| 40 | - { |
|
| 41 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
| 42 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 43 | - $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
| 44 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 45 | - } |
|
| 46 | - if (! isset($fieldValues['ATT_slug'])) { |
|
| 47 | - // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
| 48 | - $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
| 49 | - } |
|
| 50 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 51 | - $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
| 52 | - } |
|
| 53 | - parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param array $props_n_values incoming values |
|
| 59 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 60 | - * used.) |
|
| 61 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 62 | - * date_format and the second value is the time format |
|
| 63 | - * @return EE_Attendee |
|
| 64 | - * @throws EE_Error |
|
| 65 | - */ |
|
| 66 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 67 | - { |
|
| 68 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 69 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param array $props_n_values incoming values from the database |
|
| 75 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 76 | - * the website will be used. |
|
| 77 | - * @return EE_Attendee |
|
| 78 | - */ |
|
| 79 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 80 | - { |
|
| 81 | - return new self($props_n_values, true, $timezone); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Set Attendee First Name |
|
| 87 | - * |
|
| 88 | - * @access public |
|
| 89 | - * @param string $fname |
|
| 90 | - * @throws EE_Error |
|
| 91 | - */ |
|
| 92 | - public function set_fname($fname = '') |
|
| 93 | - { |
|
| 94 | - $this->set('ATT_fname', $fname); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Set Attendee Last Name |
|
| 100 | - * |
|
| 101 | - * @access public |
|
| 102 | - * @param string $lname |
|
| 103 | - * @throws EE_Error |
|
| 104 | - */ |
|
| 105 | - public function set_lname($lname = '') |
|
| 106 | - { |
|
| 107 | - $this->set('ATT_lname', $lname); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Set Attendee Address |
|
| 113 | - * |
|
| 114 | - * @access public |
|
| 115 | - * @param string $address |
|
| 116 | - * @throws EE_Error |
|
| 117 | - */ |
|
| 118 | - public function set_address($address = '') |
|
| 119 | - { |
|
| 120 | - $this->set('ATT_address', $address); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Set Attendee Address2 |
|
| 126 | - * |
|
| 127 | - * @access public |
|
| 128 | - * @param string $address2 |
|
| 129 | - * @throws EE_Error |
|
| 130 | - */ |
|
| 131 | - public function set_address2($address2 = '') |
|
| 132 | - { |
|
| 133 | - $this->set('ATT_address2', $address2); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Set Attendee City |
|
| 139 | - * |
|
| 140 | - * @access public |
|
| 141 | - * @param string $city |
|
| 142 | - * @throws EE_Error |
|
| 143 | - */ |
|
| 144 | - public function set_city($city = '') |
|
| 145 | - { |
|
| 146 | - $this->set('ATT_city', $city); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Set Attendee State ID |
|
| 152 | - * |
|
| 153 | - * @access public |
|
| 154 | - * @param int $STA_ID |
|
| 155 | - * @throws EE_Error |
|
| 156 | - */ |
|
| 157 | - public function set_state($STA_ID = 0) |
|
| 158 | - { |
|
| 159 | - $this->set('STA_ID', $STA_ID); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Set Attendee Country ISO Code |
|
| 165 | - * |
|
| 166 | - * @access public |
|
| 167 | - * @param string $CNT_ISO |
|
| 168 | - * @throws EE_Error |
|
| 169 | - */ |
|
| 170 | - public function set_country($CNT_ISO = '') |
|
| 171 | - { |
|
| 172 | - $this->set('CNT_ISO', $CNT_ISO); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Set Attendee Zip/Postal Code |
|
| 178 | - * |
|
| 179 | - * @access public |
|
| 180 | - * @param string $zip |
|
| 181 | - * @throws EE_Error |
|
| 182 | - */ |
|
| 183 | - public function set_zip($zip = '') |
|
| 184 | - { |
|
| 185 | - $this->set('ATT_zip', $zip); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Set Attendee Email Address |
|
| 191 | - * |
|
| 192 | - * @access public |
|
| 193 | - * @param string $email |
|
| 194 | - * @throws EE_Error |
|
| 195 | - */ |
|
| 196 | - public function set_email($email = '') |
|
| 197 | - { |
|
| 198 | - $this->set('ATT_email', $email); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Set Attendee Phone |
|
| 204 | - * |
|
| 205 | - * @access public |
|
| 206 | - * @param string $phone |
|
| 207 | - * @throws EE_Error |
|
| 208 | - */ |
|
| 209 | - public function set_phone($phone = '') |
|
| 210 | - { |
|
| 211 | - $this->set('ATT_phone', $phone); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * set deleted |
|
| 217 | - * |
|
| 218 | - * @access public |
|
| 219 | - * @param bool $ATT_deleted |
|
| 220 | - * @throws EE_Error |
|
| 221 | - */ |
|
| 222 | - public function set_deleted($ATT_deleted = false) |
|
| 223 | - { |
|
| 224 | - $this->set('ATT_deleted', $ATT_deleted); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Returns the value for the post_author id saved with the cpt |
|
| 230 | - * |
|
| 231 | - * @since 4.5.0 |
|
| 232 | - * @return int |
|
| 233 | - * @throws EE_Error |
|
| 234 | - */ |
|
| 235 | - public function wp_user() |
|
| 236 | - { |
|
| 237 | - return $this->get('ATT_author'); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * get Attendee First Name |
|
| 243 | - * |
|
| 244 | - * @access public |
|
| 245 | - * @return string |
|
| 246 | - * @throws EE_Error |
|
| 247 | - */ |
|
| 248 | - public function fname() |
|
| 249 | - { |
|
| 250 | - return $this->get('ATT_fname'); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * echoes out the attendee's first name |
|
| 256 | - * |
|
| 257 | - * @return void |
|
| 258 | - * @throws EE_Error |
|
| 259 | - */ |
|
| 260 | - public function e_full_name() |
|
| 261 | - { |
|
| 262 | - echo $this->full_name(); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Returns the first and last name concatenated together with a space. |
|
| 268 | - * |
|
| 269 | - * @param bool $apply_html_entities |
|
| 270 | - * @return string |
|
| 271 | - * @throws EE_Error |
|
| 272 | - */ |
|
| 273 | - public function full_name($apply_html_entities = false) |
|
| 274 | - { |
|
| 275 | - $full_name = array( |
|
| 276 | - $this->fname(), |
|
| 277 | - $this->lname(), |
|
| 278 | - ); |
|
| 279 | - $full_name = array_filter($full_name); |
|
| 280 | - $full_name = implode(' ', $full_name); |
|
| 281 | - return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
| 287 | - * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
| 288 | - * attendee. |
|
| 289 | - * |
|
| 290 | - * @param bool $apply_html_entities |
|
| 291 | - * @return string |
|
| 292 | - * @throws EE_Error |
|
| 293 | - */ |
|
| 294 | - public function ATT_full_name($apply_html_entities = false) |
|
| 295 | - { |
|
| 296 | - return $apply_html_entities |
|
| 297 | - ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
| 298 | - : $this->get('ATT_full_name'); |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * get Attendee Last Name |
|
| 304 | - * |
|
| 305 | - * @access public |
|
| 306 | - * @return string |
|
| 307 | - * @throws EE_Error |
|
| 308 | - */ |
|
| 309 | - public function lname() |
|
| 310 | - { |
|
| 311 | - return $this->get('ATT_lname'); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
| 317 | - * |
|
| 318 | - * @return array numerically indexed, with each part of the address that is known. |
|
| 319 | - * Eg, if the user only responded to state and country, |
|
| 320 | - * it would be array(0=>'Alabama',1=>'USA') |
|
| 321 | - * @return array |
|
| 322 | - * @throws EE_Error |
|
| 323 | - */ |
|
| 324 | - public function full_address_as_array() |
|
| 325 | - { |
|
| 326 | - $full_address_array = array(); |
|
| 327 | - $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
| 328 | - foreach ($initial_address_fields as $address_field_name) { |
|
| 329 | - $address_fields_value = $this->get($address_field_name); |
|
| 330 | - if (! empty($address_fields_value)) { |
|
| 331 | - $full_address_array[] = $address_fields_value; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - //now handle state and country |
|
| 335 | - $state_obj = $this->state_obj(); |
|
| 336 | - if ($state_obj instanceof EE_State) { |
|
| 337 | - $full_address_array[] = $state_obj->name(); |
|
| 338 | - } |
|
| 339 | - $country_obj = $this->country_obj(); |
|
| 340 | - if ($country_obj instanceof EE_Country) { |
|
| 341 | - $full_address_array[] = $country_obj->name(); |
|
| 342 | - } |
|
| 343 | - //lastly get the xip |
|
| 344 | - $zip_value = $this->zip(); |
|
| 345 | - if (! empty($zip_value)) { |
|
| 346 | - $full_address_array[] = $zip_value; |
|
| 347 | - } |
|
| 348 | - return $full_address_array; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * get Attendee Address |
|
| 354 | - * |
|
| 355 | - * @return string |
|
| 356 | - * @throws EE_Error |
|
| 357 | - */ |
|
| 358 | - public function address() |
|
| 359 | - { |
|
| 360 | - return $this->get('ATT_address'); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * get Attendee Address2 |
|
| 366 | - * |
|
| 367 | - * @return string |
|
| 368 | - * @throws EE_Error |
|
| 369 | - */ |
|
| 370 | - public function address2() |
|
| 371 | - { |
|
| 372 | - return $this->get('ATT_address2'); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * get Attendee City |
|
| 378 | - * |
|
| 379 | - * @return string |
|
| 380 | - * @throws EE_Error |
|
| 381 | - */ |
|
| 382 | - public function city() |
|
| 383 | - { |
|
| 384 | - return $this->get('ATT_city'); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * get Attendee State ID |
|
| 390 | - * |
|
| 391 | - * @return string |
|
| 392 | - * @throws EE_Error |
|
| 393 | - */ |
|
| 394 | - public function state_ID() |
|
| 395 | - { |
|
| 396 | - return $this->get('STA_ID'); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * @return string |
|
| 402 | - * @throws EE_Error |
|
| 403 | - */ |
|
| 404 | - public function state_abbrev() |
|
| 405 | - { |
|
| 406 | - return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Gets the state set to this attendee |
|
| 412 | - * |
|
| 413 | - * @return EE_State |
|
| 414 | - * @throws EE_Error |
|
| 415 | - */ |
|
| 416 | - public function state_obj() |
|
| 417 | - { |
|
| 418 | - return $this->get_first_related('State'); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Returns the state's name, otherwise 'Unknown' |
|
| 424 | - * |
|
| 425 | - * @return string |
|
| 426 | - * @throws EE_Error |
|
| 427 | - */ |
|
| 428 | - public function state_name() |
|
| 429 | - { |
|
| 430 | - if ($this->state_obj()) { |
|
| 431 | - return $this->state_obj()->name(); |
|
| 432 | - } else { |
|
| 433 | - return ''; |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * either displays the state abbreviation or the state name, as determined |
|
| 440 | - * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
| 441 | - * defaults to abbreviation |
|
| 442 | - * |
|
| 443 | - * @return string |
|
| 444 | - * @throws EE_Error |
|
| 445 | - */ |
|
| 446 | - public function state() |
|
| 447 | - { |
|
| 448 | - if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
| 449 | - return $this->state_abbrev(); |
|
| 450 | - } |
|
| 451 | - return $this->state_name(); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * get Attendee Country ISO Code |
|
| 457 | - * |
|
| 458 | - * @return string |
|
| 459 | - * @throws EE_Error |
|
| 460 | - */ |
|
| 461 | - public function country_ID() |
|
| 462 | - { |
|
| 463 | - return $this->get('CNT_ISO'); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Gets country set for this attendee |
|
| 469 | - * |
|
| 470 | - * @return EE_Country |
|
| 471 | - * @throws EE_Error |
|
| 472 | - */ |
|
| 473 | - public function country_obj() |
|
| 474 | - { |
|
| 475 | - return $this->get_first_related('Country'); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * Returns the country's name if known, otherwise 'Unknown' |
|
| 481 | - * |
|
| 482 | - * @return string |
|
| 483 | - * @throws EE_Error |
|
| 484 | - */ |
|
| 485 | - public function country_name() |
|
| 486 | - { |
|
| 487 | - if ($this->country_obj()) { |
|
| 488 | - return $this->country_obj()->name(); |
|
| 489 | - } |
|
| 490 | - return ''; |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * either displays the country ISO2 code or the country name, as determined |
|
| 496 | - * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
| 497 | - * defaults to abbreviation |
|
| 498 | - * |
|
| 499 | - * @return string |
|
| 500 | - * @throws EE_Error |
|
| 501 | - */ |
|
| 502 | - public function country() |
|
| 503 | - { |
|
| 504 | - if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
| 505 | - return $this->country_ID(); |
|
| 506 | - } |
|
| 507 | - return $this->country_name(); |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * get Attendee Zip/Postal Code |
|
| 513 | - * |
|
| 514 | - * @return string |
|
| 515 | - * @throws EE_Error |
|
| 516 | - */ |
|
| 517 | - public function zip() |
|
| 518 | - { |
|
| 519 | - return $this->get('ATT_zip'); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * get Attendee Email Address |
|
| 525 | - * |
|
| 526 | - * @return string |
|
| 527 | - * @throws EE_Error |
|
| 528 | - */ |
|
| 529 | - public function email() |
|
| 530 | - { |
|
| 531 | - return $this->get('ATT_email'); |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * get Attendee Phone # |
|
| 537 | - * |
|
| 538 | - * @return string |
|
| 539 | - * @throws EE_Error |
|
| 540 | - */ |
|
| 541 | - public function phone() |
|
| 542 | - { |
|
| 543 | - return $this->get('ATT_phone'); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * get deleted |
|
| 549 | - * |
|
| 550 | - * @return bool |
|
| 551 | - * @throws EE_Error |
|
| 552 | - */ |
|
| 553 | - public function deleted() |
|
| 554 | - { |
|
| 555 | - return $this->get('ATT_deleted'); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * Gets registrations of this attendee |
|
| 561 | - * |
|
| 562 | - * @param array $query_params |
|
| 563 | - * @return EE_Registration[] |
|
| 564 | - * @throws EE_Error |
|
| 565 | - */ |
|
| 566 | - public function get_registrations($query_params = array()) |
|
| 567 | - { |
|
| 568 | - return $this->get_many_related('Registration', $query_params); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * Gets the most recent registration of this attendee |
|
| 574 | - * |
|
| 575 | - * @return EE_Registration |
|
| 576 | - * @throws EE_Error |
|
| 577 | - */ |
|
| 578 | - public function get_most_recent_registration() |
|
| 579 | - { |
|
| 580 | - return $this->get_first_related( |
|
| 581 | - 'Registration', |
|
| 582 | - array('order_by' => array('REG_date' => 'DESC')) |
|
| 583 | - ); //null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Gets the most recent registration for this attend at this event |
|
| 589 | - * |
|
| 590 | - * @param int $event_id |
|
| 591 | - * @return EE_Registration |
|
| 592 | - * @throws EE_Error |
|
| 593 | - */ |
|
| 594 | - public function get_most_recent_registration_for_event($event_id) |
|
| 595 | - { |
|
| 596 | - return $this->get_first_related( |
|
| 597 | - 'Registration', |
|
| 598 | - array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')) |
|
| 599 | - ); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * returns any events attached to this attendee ($_Event property); |
|
| 605 | - * |
|
| 606 | - * @return array |
|
| 607 | - * @throws EE_Error |
|
| 608 | - */ |
|
| 609 | - public function events() |
|
| 610 | - { |
|
| 611 | - return $this->get_many_related('Event'); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
| 617 | - * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
| 618 | - * used to save the billing info |
|
| 619 | - * |
|
| 620 | - * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
| 621 | - * @return EE_Form_Section_Proper|null |
|
| 622 | - * @throws EE_Error |
|
| 623 | - */ |
|
| 624 | - public function billing_info_for_payment_method($payment_method) |
|
| 625 | - { |
|
| 626 | - $pm_type = $payment_method->type_obj(); |
|
| 627 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
| 628 | - return null; |
|
| 629 | - } |
|
| 630 | - $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
| 631 | - if (! $billing_info) { |
|
| 632 | - return null; |
|
| 633 | - } |
|
| 634 | - $billing_form = $pm_type->billing_form(); |
|
| 635 | - //double-check the form isn't totally hidden, in which case pretend there is no form |
|
| 636 | - $form_totally_hidden = true; |
|
| 637 | - foreach($billing_form->inputs_in_subsections() as $input){ |
|
| 638 | - if(! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 639 | - $form_totally_hidden = false; |
|
| 640 | - break; |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - if($form_totally_hidden) { |
|
| 644 | - return null; |
|
| 645 | - } |
|
| 646 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 647 | - $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - return $billing_form; |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * Gets the postmeta key that holds this attendee's billing info for the |
|
| 656 | - * specified payment method |
|
| 657 | - * |
|
| 658 | - * @param EE_Payment_Method $payment_method |
|
| 659 | - * @return string |
|
| 660 | - * @throws EE_Error |
|
| 661 | - */ |
|
| 662 | - public function get_billing_info_postmeta_name($payment_method) |
|
| 663 | - { |
|
| 664 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 665 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 666 | - } |
|
| 667 | - return null; |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
| 673 | - * retrieve it |
|
| 674 | - * |
|
| 675 | - * @param EE_Billing_Attendee_Info_Form $billing_form |
|
| 676 | - * @param EE_Payment_Method $payment_method |
|
| 677 | - * @return boolean |
|
| 678 | - * @throws EE_Error |
|
| 679 | - */ |
|
| 680 | - public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
| 681 | - { |
|
| 682 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 683 | - EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
|
| 684 | - return false; |
|
| 685 | - } |
|
| 686 | - $billing_form->clean_sensitive_data(); |
|
| 687 | - return update_post_meta( |
|
| 688 | - $this->ID(), |
|
| 689 | - $this->get_billing_info_postmeta_name($payment_method), |
|
| 690 | - $billing_form->input_values(true) |
|
| 691 | - ); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * Return the link to the admin details for the object. |
|
| 697 | - * |
|
| 698 | - * @return string |
|
| 699 | - * @throws EE_Error |
|
| 700 | - * @throws InvalidArgumentException |
|
| 701 | - * @throws InvalidDataTypeException |
|
| 702 | - * @throws InvalidInterfaceException |
|
| 703 | - * @throws ReflectionException |
|
| 704 | - */ |
|
| 705 | - public function get_admin_details_link() |
|
| 706 | - { |
|
| 707 | - return $this->get_admin_edit_link(); |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 713 | - * |
|
| 714 | - * @return string |
|
| 715 | - * @throws EE_Error |
|
| 716 | - * @throws InvalidArgumentException |
|
| 717 | - * @throws ReflectionException |
|
| 718 | - * @throws InvalidDataTypeException |
|
| 719 | - * @throws InvalidInterfaceException |
|
| 720 | - */ |
|
| 721 | - public function get_admin_edit_link() |
|
| 722 | - { |
|
| 723 | - EE_Registry::instance()->load_helper('URL'); |
|
| 724 | - return EEH_URL::add_query_args_and_nonce( |
|
| 725 | - array( |
|
| 726 | - 'page' => 'espresso_registrations', |
|
| 727 | - 'action' => 'edit_attendee', |
|
| 728 | - 'post' => $this->ID(), |
|
| 729 | - ), |
|
| 730 | - admin_url('admin.php') |
|
| 731 | - ); |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * Returns the link to a settings page for the object. |
|
| 737 | - * |
|
| 738 | - * @return string |
|
| 739 | - * @throws EE_Error |
|
| 740 | - * @throws InvalidArgumentException |
|
| 741 | - * @throws InvalidDataTypeException |
|
| 742 | - * @throws InvalidInterfaceException |
|
| 743 | - * @throws ReflectionException |
|
| 744 | - */ |
|
| 745 | - public function get_admin_settings_link() |
|
| 746 | - { |
|
| 747 | - return $this->get_admin_edit_link(); |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - |
|
| 751 | - /** |
|
| 752 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 753 | - * |
|
| 754 | - * @return string |
|
| 755 | - * @throws EE_Error |
|
| 756 | - * @throws InvalidArgumentException |
|
| 757 | - * @throws ReflectionException |
|
| 758 | - * @throws InvalidDataTypeException |
|
| 759 | - * @throws InvalidInterfaceException |
|
| 760 | - */ |
|
| 761 | - public function get_admin_overview_link() |
|
| 762 | - { |
|
| 763 | - EE_Registry::instance()->load_helper('URL'); |
|
| 764 | - return EEH_URL::add_query_args_and_nonce( |
|
| 765 | - array( |
|
| 766 | - 'page' => 'espresso_registrations', |
|
| 767 | - 'action' => 'contact_list', |
|
| 768 | - ), |
|
| 769 | - admin_url('admin.php') |
|
| 770 | - ); |
|
| 771 | - } |
|
| 30 | + /** |
|
| 31 | + * Sets some dynamic defaults |
|
| 32 | + * |
|
| 33 | + * @param array $fieldValues |
|
| 34 | + * @param bool $bydb |
|
| 35 | + * @param string $timezone |
|
| 36 | + * @param array $date_formats |
|
| 37 | + * @throws EE_Error |
|
| 38 | + */ |
|
| 39 | + protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
| 40 | + { |
|
| 41 | + if (! isset($fieldValues['ATT_full_name'])) { |
|
| 42 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 43 | + $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
| 44 | + $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 45 | + } |
|
| 46 | + if (! isset($fieldValues['ATT_slug'])) { |
|
| 47 | + // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
| 48 | + $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
| 49 | + } |
|
| 50 | + if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 51 | + $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
| 52 | + } |
|
| 53 | + parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param array $props_n_values incoming values |
|
| 59 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 60 | + * used.) |
|
| 61 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 62 | + * date_format and the second value is the time format |
|
| 63 | + * @return EE_Attendee |
|
| 64 | + * @throws EE_Error |
|
| 65 | + */ |
|
| 66 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 67 | + { |
|
| 68 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 69 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param array $props_n_values incoming values from the database |
|
| 75 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 76 | + * the website will be used. |
|
| 77 | + * @return EE_Attendee |
|
| 78 | + */ |
|
| 79 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 80 | + { |
|
| 81 | + return new self($props_n_values, true, $timezone); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Set Attendee First Name |
|
| 87 | + * |
|
| 88 | + * @access public |
|
| 89 | + * @param string $fname |
|
| 90 | + * @throws EE_Error |
|
| 91 | + */ |
|
| 92 | + public function set_fname($fname = '') |
|
| 93 | + { |
|
| 94 | + $this->set('ATT_fname', $fname); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Set Attendee Last Name |
|
| 100 | + * |
|
| 101 | + * @access public |
|
| 102 | + * @param string $lname |
|
| 103 | + * @throws EE_Error |
|
| 104 | + */ |
|
| 105 | + public function set_lname($lname = '') |
|
| 106 | + { |
|
| 107 | + $this->set('ATT_lname', $lname); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Set Attendee Address |
|
| 113 | + * |
|
| 114 | + * @access public |
|
| 115 | + * @param string $address |
|
| 116 | + * @throws EE_Error |
|
| 117 | + */ |
|
| 118 | + public function set_address($address = '') |
|
| 119 | + { |
|
| 120 | + $this->set('ATT_address', $address); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Set Attendee Address2 |
|
| 126 | + * |
|
| 127 | + * @access public |
|
| 128 | + * @param string $address2 |
|
| 129 | + * @throws EE_Error |
|
| 130 | + */ |
|
| 131 | + public function set_address2($address2 = '') |
|
| 132 | + { |
|
| 133 | + $this->set('ATT_address2', $address2); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Set Attendee City |
|
| 139 | + * |
|
| 140 | + * @access public |
|
| 141 | + * @param string $city |
|
| 142 | + * @throws EE_Error |
|
| 143 | + */ |
|
| 144 | + public function set_city($city = '') |
|
| 145 | + { |
|
| 146 | + $this->set('ATT_city', $city); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Set Attendee State ID |
|
| 152 | + * |
|
| 153 | + * @access public |
|
| 154 | + * @param int $STA_ID |
|
| 155 | + * @throws EE_Error |
|
| 156 | + */ |
|
| 157 | + public function set_state($STA_ID = 0) |
|
| 158 | + { |
|
| 159 | + $this->set('STA_ID', $STA_ID); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Set Attendee Country ISO Code |
|
| 165 | + * |
|
| 166 | + * @access public |
|
| 167 | + * @param string $CNT_ISO |
|
| 168 | + * @throws EE_Error |
|
| 169 | + */ |
|
| 170 | + public function set_country($CNT_ISO = '') |
|
| 171 | + { |
|
| 172 | + $this->set('CNT_ISO', $CNT_ISO); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Set Attendee Zip/Postal Code |
|
| 178 | + * |
|
| 179 | + * @access public |
|
| 180 | + * @param string $zip |
|
| 181 | + * @throws EE_Error |
|
| 182 | + */ |
|
| 183 | + public function set_zip($zip = '') |
|
| 184 | + { |
|
| 185 | + $this->set('ATT_zip', $zip); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Set Attendee Email Address |
|
| 191 | + * |
|
| 192 | + * @access public |
|
| 193 | + * @param string $email |
|
| 194 | + * @throws EE_Error |
|
| 195 | + */ |
|
| 196 | + public function set_email($email = '') |
|
| 197 | + { |
|
| 198 | + $this->set('ATT_email', $email); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Set Attendee Phone |
|
| 204 | + * |
|
| 205 | + * @access public |
|
| 206 | + * @param string $phone |
|
| 207 | + * @throws EE_Error |
|
| 208 | + */ |
|
| 209 | + public function set_phone($phone = '') |
|
| 210 | + { |
|
| 211 | + $this->set('ATT_phone', $phone); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * set deleted |
|
| 217 | + * |
|
| 218 | + * @access public |
|
| 219 | + * @param bool $ATT_deleted |
|
| 220 | + * @throws EE_Error |
|
| 221 | + */ |
|
| 222 | + public function set_deleted($ATT_deleted = false) |
|
| 223 | + { |
|
| 224 | + $this->set('ATT_deleted', $ATT_deleted); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Returns the value for the post_author id saved with the cpt |
|
| 230 | + * |
|
| 231 | + * @since 4.5.0 |
|
| 232 | + * @return int |
|
| 233 | + * @throws EE_Error |
|
| 234 | + */ |
|
| 235 | + public function wp_user() |
|
| 236 | + { |
|
| 237 | + return $this->get('ATT_author'); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * get Attendee First Name |
|
| 243 | + * |
|
| 244 | + * @access public |
|
| 245 | + * @return string |
|
| 246 | + * @throws EE_Error |
|
| 247 | + */ |
|
| 248 | + public function fname() |
|
| 249 | + { |
|
| 250 | + return $this->get('ATT_fname'); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * echoes out the attendee's first name |
|
| 256 | + * |
|
| 257 | + * @return void |
|
| 258 | + * @throws EE_Error |
|
| 259 | + */ |
|
| 260 | + public function e_full_name() |
|
| 261 | + { |
|
| 262 | + echo $this->full_name(); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Returns the first and last name concatenated together with a space. |
|
| 268 | + * |
|
| 269 | + * @param bool $apply_html_entities |
|
| 270 | + * @return string |
|
| 271 | + * @throws EE_Error |
|
| 272 | + */ |
|
| 273 | + public function full_name($apply_html_entities = false) |
|
| 274 | + { |
|
| 275 | + $full_name = array( |
|
| 276 | + $this->fname(), |
|
| 277 | + $this->lname(), |
|
| 278 | + ); |
|
| 279 | + $full_name = array_filter($full_name); |
|
| 280 | + $full_name = implode(' ', $full_name); |
|
| 281 | + return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
| 287 | + * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
| 288 | + * attendee. |
|
| 289 | + * |
|
| 290 | + * @param bool $apply_html_entities |
|
| 291 | + * @return string |
|
| 292 | + * @throws EE_Error |
|
| 293 | + */ |
|
| 294 | + public function ATT_full_name($apply_html_entities = false) |
|
| 295 | + { |
|
| 296 | + return $apply_html_entities |
|
| 297 | + ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
| 298 | + : $this->get('ATT_full_name'); |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * get Attendee Last Name |
|
| 304 | + * |
|
| 305 | + * @access public |
|
| 306 | + * @return string |
|
| 307 | + * @throws EE_Error |
|
| 308 | + */ |
|
| 309 | + public function lname() |
|
| 310 | + { |
|
| 311 | + return $this->get('ATT_lname'); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
| 317 | + * |
|
| 318 | + * @return array numerically indexed, with each part of the address that is known. |
|
| 319 | + * Eg, if the user only responded to state and country, |
|
| 320 | + * it would be array(0=>'Alabama',1=>'USA') |
|
| 321 | + * @return array |
|
| 322 | + * @throws EE_Error |
|
| 323 | + */ |
|
| 324 | + public function full_address_as_array() |
|
| 325 | + { |
|
| 326 | + $full_address_array = array(); |
|
| 327 | + $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
| 328 | + foreach ($initial_address_fields as $address_field_name) { |
|
| 329 | + $address_fields_value = $this->get($address_field_name); |
|
| 330 | + if (! empty($address_fields_value)) { |
|
| 331 | + $full_address_array[] = $address_fields_value; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + //now handle state and country |
|
| 335 | + $state_obj = $this->state_obj(); |
|
| 336 | + if ($state_obj instanceof EE_State) { |
|
| 337 | + $full_address_array[] = $state_obj->name(); |
|
| 338 | + } |
|
| 339 | + $country_obj = $this->country_obj(); |
|
| 340 | + if ($country_obj instanceof EE_Country) { |
|
| 341 | + $full_address_array[] = $country_obj->name(); |
|
| 342 | + } |
|
| 343 | + //lastly get the xip |
|
| 344 | + $zip_value = $this->zip(); |
|
| 345 | + if (! empty($zip_value)) { |
|
| 346 | + $full_address_array[] = $zip_value; |
|
| 347 | + } |
|
| 348 | + return $full_address_array; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * get Attendee Address |
|
| 354 | + * |
|
| 355 | + * @return string |
|
| 356 | + * @throws EE_Error |
|
| 357 | + */ |
|
| 358 | + public function address() |
|
| 359 | + { |
|
| 360 | + return $this->get('ATT_address'); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * get Attendee Address2 |
|
| 366 | + * |
|
| 367 | + * @return string |
|
| 368 | + * @throws EE_Error |
|
| 369 | + */ |
|
| 370 | + public function address2() |
|
| 371 | + { |
|
| 372 | + return $this->get('ATT_address2'); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * get Attendee City |
|
| 378 | + * |
|
| 379 | + * @return string |
|
| 380 | + * @throws EE_Error |
|
| 381 | + */ |
|
| 382 | + public function city() |
|
| 383 | + { |
|
| 384 | + return $this->get('ATT_city'); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * get Attendee State ID |
|
| 390 | + * |
|
| 391 | + * @return string |
|
| 392 | + * @throws EE_Error |
|
| 393 | + */ |
|
| 394 | + public function state_ID() |
|
| 395 | + { |
|
| 396 | + return $this->get('STA_ID'); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * @return string |
|
| 402 | + * @throws EE_Error |
|
| 403 | + */ |
|
| 404 | + public function state_abbrev() |
|
| 405 | + { |
|
| 406 | + return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Gets the state set to this attendee |
|
| 412 | + * |
|
| 413 | + * @return EE_State |
|
| 414 | + * @throws EE_Error |
|
| 415 | + */ |
|
| 416 | + public function state_obj() |
|
| 417 | + { |
|
| 418 | + return $this->get_first_related('State'); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Returns the state's name, otherwise 'Unknown' |
|
| 424 | + * |
|
| 425 | + * @return string |
|
| 426 | + * @throws EE_Error |
|
| 427 | + */ |
|
| 428 | + public function state_name() |
|
| 429 | + { |
|
| 430 | + if ($this->state_obj()) { |
|
| 431 | + return $this->state_obj()->name(); |
|
| 432 | + } else { |
|
| 433 | + return ''; |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * either displays the state abbreviation or the state name, as determined |
|
| 440 | + * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
| 441 | + * defaults to abbreviation |
|
| 442 | + * |
|
| 443 | + * @return string |
|
| 444 | + * @throws EE_Error |
|
| 445 | + */ |
|
| 446 | + public function state() |
|
| 447 | + { |
|
| 448 | + if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
| 449 | + return $this->state_abbrev(); |
|
| 450 | + } |
|
| 451 | + return $this->state_name(); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * get Attendee Country ISO Code |
|
| 457 | + * |
|
| 458 | + * @return string |
|
| 459 | + * @throws EE_Error |
|
| 460 | + */ |
|
| 461 | + public function country_ID() |
|
| 462 | + { |
|
| 463 | + return $this->get('CNT_ISO'); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Gets country set for this attendee |
|
| 469 | + * |
|
| 470 | + * @return EE_Country |
|
| 471 | + * @throws EE_Error |
|
| 472 | + */ |
|
| 473 | + public function country_obj() |
|
| 474 | + { |
|
| 475 | + return $this->get_first_related('Country'); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * Returns the country's name if known, otherwise 'Unknown' |
|
| 481 | + * |
|
| 482 | + * @return string |
|
| 483 | + * @throws EE_Error |
|
| 484 | + */ |
|
| 485 | + public function country_name() |
|
| 486 | + { |
|
| 487 | + if ($this->country_obj()) { |
|
| 488 | + return $this->country_obj()->name(); |
|
| 489 | + } |
|
| 490 | + return ''; |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * either displays the country ISO2 code or the country name, as determined |
|
| 496 | + * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
| 497 | + * defaults to abbreviation |
|
| 498 | + * |
|
| 499 | + * @return string |
|
| 500 | + * @throws EE_Error |
|
| 501 | + */ |
|
| 502 | + public function country() |
|
| 503 | + { |
|
| 504 | + if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
| 505 | + return $this->country_ID(); |
|
| 506 | + } |
|
| 507 | + return $this->country_name(); |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * get Attendee Zip/Postal Code |
|
| 513 | + * |
|
| 514 | + * @return string |
|
| 515 | + * @throws EE_Error |
|
| 516 | + */ |
|
| 517 | + public function zip() |
|
| 518 | + { |
|
| 519 | + return $this->get('ATT_zip'); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * get Attendee Email Address |
|
| 525 | + * |
|
| 526 | + * @return string |
|
| 527 | + * @throws EE_Error |
|
| 528 | + */ |
|
| 529 | + public function email() |
|
| 530 | + { |
|
| 531 | + return $this->get('ATT_email'); |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * get Attendee Phone # |
|
| 537 | + * |
|
| 538 | + * @return string |
|
| 539 | + * @throws EE_Error |
|
| 540 | + */ |
|
| 541 | + public function phone() |
|
| 542 | + { |
|
| 543 | + return $this->get('ATT_phone'); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * get deleted |
|
| 549 | + * |
|
| 550 | + * @return bool |
|
| 551 | + * @throws EE_Error |
|
| 552 | + */ |
|
| 553 | + public function deleted() |
|
| 554 | + { |
|
| 555 | + return $this->get('ATT_deleted'); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * Gets registrations of this attendee |
|
| 561 | + * |
|
| 562 | + * @param array $query_params |
|
| 563 | + * @return EE_Registration[] |
|
| 564 | + * @throws EE_Error |
|
| 565 | + */ |
|
| 566 | + public function get_registrations($query_params = array()) |
|
| 567 | + { |
|
| 568 | + return $this->get_many_related('Registration', $query_params); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * Gets the most recent registration of this attendee |
|
| 574 | + * |
|
| 575 | + * @return EE_Registration |
|
| 576 | + * @throws EE_Error |
|
| 577 | + */ |
|
| 578 | + public function get_most_recent_registration() |
|
| 579 | + { |
|
| 580 | + return $this->get_first_related( |
|
| 581 | + 'Registration', |
|
| 582 | + array('order_by' => array('REG_date' => 'DESC')) |
|
| 583 | + ); //null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * Gets the most recent registration for this attend at this event |
|
| 589 | + * |
|
| 590 | + * @param int $event_id |
|
| 591 | + * @return EE_Registration |
|
| 592 | + * @throws EE_Error |
|
| 593 | + */ |
|
| 594 | + public function get_most_recent_registration_for_event($event_id) |
|
| 595 | + { |
|
| 596 | + return $this->get_first_related( |
|
| 597 | + 'Registration', |
|
| 598 | + array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')) |
|
| 599 | + ); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * returns any events attached to this attendee ($_Event property); |
|
| 605 | + * |
|
| 606 | + * @return array |
|
| 607 | + * @throws EE_Error |
|
| 608 | + */ |
|
| 609 | + public function events() |
|
| 610 | + { |
|
| 611 | + return $this->get_many_related('Event'); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
| 617 | + * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
| 618 | + * used to save the billing info |
|
| 619 | + * |
|
| 620 | + * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
| 621 | + * @return EE_Form_Section_Proper|null |
|
| 622 | + * @throws EE_Error |
|
| 623 | + */ |
|
| 624 | + public function billing_info_for_payment_method($payment_method) |
|
| 625 | + { |
|
| 626 | + $pm_type = $payment_method->type_obj(); |
|
| 627 | + if (! $pm_type instanceof EE_PMT_Base) { |
|
| 628 | + return null; |
|
| 629 | + } |
|
| 630 | + $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
| 631 | + if (! $billing_info) { |
|
| 632 | + return null; |
|
| 633 | + } |
|
| 634 | + $billing_form = $pm_type->billing_form(); |
|
| 635 | + //double-check the form isn't totally hidden, in which case pretend there is no form |
|
| 636 | + $form_totally_hidden = true; |
|
| 637 | + foreach($billing_form->inputs_in_subsections() as $input){ |
|
| 638 | + if(! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 639 | + $form_totally_hidden = false; |
|
| 640 | + break; |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + if($form_totally_hidden) { |
|
| 644 | + return null; |
|
| 645 | + } |
|
| 646 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 647 | + $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + return $billing_form; |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * Gets the postmeta key that holds this attendee's billing info for the |
|
| 656 | + * specified payment method |
|
| 657 | + * |
|
| 658 | + * @param EE_Payment_Method $payment_method |
|
| 659 | + * @return string |
|
| 660 | + * @throws EE_Error |
|
| 661 | + */ |
|
| 662 | + public function get_billing_info_postmeta_name($payment_method) |
|
| 663 | + { |
|
| 664 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 665 | + return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 666 | + } |
|
| 667 | + return null; |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
| 673 | + * retrieve it |
|
| 674 | + * |
|
| 675 | + * @param EE_Billing_Attendee_Info_Form $billing_form |
|
| 676 | + * @param EE_Payment_Method $payment_method |
|
| 677 | + * @return boolean |
|
| 678 | + * @throws EE_Error |
|
| 679 | + */ |
|
| 680 | + public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
| 681 | + { |
|
| 682 | + if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 683 | + EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
|
| 684 | + return false; |
|
| 685 | + } |
|
| 686 | + $billing_form->clean_sensitive_data(); |
|
| 687 | + return update_post_meta( |
|
| 688 | + $this->ID(), |
|
| 689 | + $this->get_billing_info_postmeta_name($payment_method), |
|
| 690 | + $billing_form->input_values(true) |
|
| 691 | + ); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * Return the link to the admin details for the object. |
|
| 697 | + * |
|
| 698 | + * @return string |
|
| 699 | + * @throws EE_Error |
|
| 700 | + * @throws InvalidArgumentException |
|
| 701 | + * @throws InvalidDataTypeException |
|
| 702 | + * @throws InvalidInterfaceException |
|
| 703 | + * @throws ReflectionException |
|
| 704 | + */ |
|
| 705 | + public function get_admin_details_link() |
|
| 706 | + { |
|
| 707 | + return $this->get_admin_edit_link(); |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 713 | + * |
|
| 714 | + * @return string |
|
| 715 | + * @throws EE_Error |
|
| 716 | + * @throws InvalidArgumentException |
|
| 717 | + * @throws ReflectionException |
|
| 718 | + * @throws InvalidDataTypeException |
|
| 719 | + * @throws InvalidInterfaceException |
|
| 720 | + */ |
|
| 721 | + public function get_admin_edit_link() |
|
| 722 | + { |
|
| 723 | + EE_Registry::instance()->load_helper('URL'); |
|
| 724 | + return EEH_URL::add_query_args_and_nonce( |
|
| 725 | + array( |
|
| 726 | + 'page' => 'espresso_registrations', |
|
| 727 | + 'action' => 'edit_attendee', |
|
| 728 | + 'post' => $this->ID(), |
|
| 729 | + ), |
|
| 730 | + admin_url('admin.php') |
|
| 731 | + ); |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * Returns the link to a settings page for the object. |
|
| 737 | + * |
|
| 738 | + * @return string |
|
| 739 | + * @throws EE_Error |
|
| 740 | + * @throws InvalidArgumentException |
|
| 741 | + * @throws InvalidDataTypeException |
|
| 742 | + * @throws InvalidInterfaceException |
|
| 743 | + * @throws ReflectionException |
|
| 744 | + */ |
|
| 745 | + public function get_admin_settings_link() |
|
| 746 | + { |
|
| 747 | + return $this->get_admin_edit_link(); |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + |
|
| 751 | + /** |
|
| 752 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 753 | + * |
|
| 754 | + * @return string |
|
| 755 | + * @throws EE_Error |
|
| 756 | + * @throws InvalidArgumentException |
|
| 757 | + * @throws ReflectionException |
|
| 758 | + * @throws InvalidDataTypeException |
|
| 759 | + * @throws InvalidInterfaceException |
|
| 760 | + */ |
|
| 761 | + public function get_admin_overview_link() |
|
| 762 | + { |
|
| 763 | + EE_Registry::instance()->load_helper('URL'); |
|
| 764 | + return EEH_URL::add_query_args_and_nonce( |
|
| 765 | + array( |
|
| 766 | + 'page' => 'espresso_registrations', |
|
| 767 | + 'action' => 'contact_list', |
|
| 768 | + ), |
|
| 769 | + admin_url('admin.php') |
|
| 770 | + ); |
|
| 771 | + } |
|
| 772 | 772 | } |
@@ -38,16 +38,16 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
| 40 | 40 | { |
| 41 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
| 42 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 41 | + if ( ! isset($fieldValues['ATT_full_name'])) { |
|
| 42 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'].' ' : ''; |
|
| 43 | 43 | $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
| 44 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 44 | + $fieldValues['ATT_full_name'] = $fname.$lname; |
|
| 45 | 45 | } |
| 46 | - if (! isset($fieldValues['ATT_slug'])) { |
|
| 46 | + if ( ! isset($fieldValues['ATT_slug'])) { |
|
| 47 | 47 | // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
| 48 | 48 | $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
| 49 | 49 | } |
| 50 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 50 | + if ( ! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 51 | 51 | $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
| 52 | 52 | } |
| 53 | 53 | parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
| 328 | 328 | foreach ($initial_address_fields as $address_field_name) { |
| 329 | 329 | $address_fields_value = $this->get($address_field_name); |
| 330 | - if (! empty($address_fields_value)) { |
|
| 330 | + if ( ! empty($address_fields_value)) { |
|
| 331 | 331 | $full_address_array[] = $address_fields_value; |
| 332 | 332 | } |
| 333 | 333 | } |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | } |
| 343 | 343 | //lastly get the xip |
| 344 | 344 | $zip_value = $this->zip(); |
| 345 | - if (! empty($zip_value)) { |
|
| 345 | + if ( ! empty($zip_value)) { |
|
| 346 | 346 | $full_address_array[] = $zip_value; |
| 347 | 347 | } |
| 348 | 348 | return $full_address_array; |
@@ -624,23 +624,23 @@ discard block |
||
| 624 | 624 | public function billing_info_for_payment_method($payment_method) |
| 625 | 625 | { |
| 626 | 626 | $pm_type = $payment_method->type_obj(); |
| 627 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
| 627 | + if ( ! $pm_type instanceof EE_PMT_Base) { |
|
| 628 | 628 | return null; |
| 629 | 629 | } |
| 630 | 630 | $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
| 631 | - if (! $billing_info) { |
|
| 631 | + if ( ! $billing_info) { |
|
| 632 | 632 | return null; |
| 633 | 633 | } |
| 634 | 634 | $billing_form = $pm_type->billing_form(); |
| 635 | 635 | //double-check the form isn't totally hidden, in which case pretend there is no form |
| 636 | 636 | $form_totally_hidden = true; |
| 637 | - foreach($billing_form->inputs_in_subsections() as $input){ |
|
| 638 | - if(! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 637 | + foreach ($billing_form->inputs_in_subsections() as $input) { |
|
| 638 | + if ( ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 639 | 639 | $form_totally_hidden = false; |
| 640 | 640 | break; |
| 641 | 641 | } |
| 642 | 642 | } |
| 643 | - if($form_totally_hidden) { |
|
| 643 | + if ($form_totally_hidden) { |
|
| 644 | 644 | return null; |
| 645 | 645 | } |
| 646 | 646 | if ($billing_form instanceof EE_Form_Section_Proper) { |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | public function get_billing_info_postmeta_name($payment_method) |
| 663 | 663 | { |
| 664 | 664 | if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
| 665 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 665 | + return 'billing_info_'.$payment_method->type_obj()->system_name(); |
|
| 666 | 666 | } |
| 667 | 667 | return null; |
| 668 | 668 | } |
@@ -679,7 +679,7 @@ discard block |
||
| 679 | 679 | */ |
| 680 | 680 | public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
| 681 | 681 | { |
| 682 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 682 | + if ( ! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 683 | 683 | EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
| 684 | 684 | return false; |
| 685 | 685 | } |
@@ -15,288 +15,288 @@ |
||
| 15 | 15 | abstract class EE_Form_Section_Layout_Base |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Form form section to lay out |
|
| 20 | - * |
|
| 21 | - * @var EE_Form_Section_Proper |
|
| 22 | - */ |
|
| 23 | - protected $_form_section; |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * __construct |
|
| 29 | - */ |
|
| 30 | - public function __construct() |
|
| 31 | - { |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * The form section on which this strategy is to perform |
|
| 38 | - * |
|
| 39 | - * @param EE_Form_Section_Proper $form |
|
| 40 | - */ |
|
| 41 | - public function _construct_finalize(EE_Form_Section_Proper $form) |
|
| 42 | - { |
|
| 43 | - $this->_form_section = $form; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @return EE_Form_Section_Proper |
|
| 50 | - */ |
|
| 51 | - public function form_section() |
|
| 52 | - { |
|
| 53 | - return $this->_form_section; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Also has teh side effect of enqueuing any needed JS and CSS for |
|
| 60 | - * this form. |
|
| 61 | - * Creates all the HTML necessary for displaying this form, its inputs, and |
|
| 62 | - * proper subsections. |
|
| 63 | - * Returns the HTML |
|
| 64 | - * |
|
| 65 | - * @return string HTML for displaying |
|
| 66 | - * @throws EE_Error |
|
| 67 | - */ |
|
| 68 | - public function layout_form() |
|
| 69 | - { |
|
| 70 | - $html = ''; |
|
| 71 | - // layout_form_begin |
|
| 72 | - $html .= apply_filters( |
|
| 73 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
| 74 | - $this->layout_form_begin(), |
|
| 75 | - $this->_form_section |
|
| 76 | - ); |
|
| 77 | - // layout_form_loop |
|
| 78 | - $html .= apply_filters( |
|
| 79 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
| 80 | - $this->layout_form_loop(), |
|
| 81 | - $this->_form_section |
|
| 82 | - ); |
|
| 83 | - // layout_form_end |
|
| 84 | - $html .= apply_filters( |
|
| 85 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
| 86 | - $this->layout_form_end(), |
|
| 87 | - $this->_form_section |
|
| 88 | - ); |
|
| 89 | - $html = $this->add_form_section_hooks_and_filters($html); |
|
| 90 | - return $html; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @return string |
|
| 97 | - * @throws EE_Error |
|
| 98 | - */ |
|
| 99 | - public function layout_form_loop() |
|
| 100 | - { |
|
| 101 | - $html = ''; |
|
| 102 | - foreach ($this->_form_section->subsections() as $name => $subsection) { |
|
| 103 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 104 | - $html .= apply_filters( |
|
| 105 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
|
| 106 | - . $name . '__in_' . $this->_form_section->name(), |
|
| 107 | - $this->layout_input($subsection), |
|
| 108 | - $this->_form_section, |
|
| 109 | - $subsection |
|
| 110 | - ); |
|
| 111 | - } elseif ($subsection instanceof EE_Form_Section_Base) { |
|
| 112 | - $html .= apply_filters( |
|
| 113 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
|
| 114 | - . $name . '__in_' . $this->_form_section->name(), |
|
| 115 | - $this->layout_subsection($subsection), |
|
| 116 | - $this->_form_section, |
|
| 117 | - $subsection |
|
| 118 | - ); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - return $html; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
| 128 | - * |
|
| 129 | - * @return string |
|
| 130 | - */ |
|
| 131 | - abstract public function layout_form_begin(); |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Should be used to end the form section (eg a /table tag, or a /div tag, etc) |
|
| 137 | - * |
|
| 138 | - * @return string |
|
| 139 | - */ |
|
| 140 | - abstract public function layout_form_end(); |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Should be used internally by layout_form() to layout each input (eg, if this layout |
|
| 146 | - * is putting each input in a row of its own, this should probably be called by a |
|
| 147 | - * foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop. |
|
| 148 | - * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely |
|
| 149 | - * customize the form's layout, but would like to make use of it for laying out |
|
| 150 | - * 'easy-to-layout' inputs |
|
| 151 | - * |
|
| 152 | - * @param EE_Form_Input_Base $input |
|
| 153 | - * @return string html |
|
| 154 | - */ |
|
| 155 | - abstract public function layout_input($input); |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Similar to layout_input(), should be used internally by layout_form() within a |
|
| 161 | - * loop to layout each proper subsection. Unlike layout_input(), however, it is assumed |
|
| 162 | - * that the proper subsection will layout its container, label, etc on its own. |
|
| 163 | - * |
|
| 164 | - * @param EE_Form_Section_Base $subsection |
|
| 165 | - * @return string html |
|
| 166 | - */ |
|
| 167 | - abstract public function layout_subsection($subsection); |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Gets the HTML for the label tag and its contents for the input |
|
| 173 | - * |
|
| 174 | - * @param EE_Form_Input_Base $input |
|
| 175 | - * @return string |
|
| 176 | - */ |
|
| 177 | - public function display_label($input) |
|
| 178 | - { |
|
| 179 | - if($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy){ |
|
| 180 | - return ''; |
|
| 181 | - } |
|
| 182 | - $class = $input->required() |
|
| 183 | - ? 'ee-required-label ' . $input->html_label_class() |
|
| 184 | - : $input->html_label_class(); |
|
| 185 | - $label_text = $input->required() |
|
| 186 | - ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
| 187 | - : $input->html_label_text(); |
|
| 188 | - return '<label id="' |
|
| 189 | - . $input->html_label_id() |
|
| 190 | - . '" class="' |
|
| 191 | - . $class |
|
| 192 | - . '" style="' |
|
| 193 | - . $input->html_label_style() |
|
| 194 | - . '" for="' . $input->html_name() |
|
| 195 | - . '">' |
|
| 196 | - . $label_text |
|
| 197 | - . '</label>'; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Gets the HTML for all the form's form-wide errors (ie, errors which |
|
| 204 | - * are not for specific inputs. E.g., if two inputs somehow disagree, |
|
| 205 | - * those errors would probably be on the form section, not one of its inputs) |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - public function display_form_wide_errors() |
|
| 209 | - { |
|
| 210 | - $html = ''; |
|
| 211 | - if ($this->_form_section->get_validation_errors()) { |
|
| 212 | - $html .= "<div class='ee-form-wide-errors'>"; |
|
| 213 | - //get all the errors on THIS form section (errors which aren't |
|
| 214 | - //for specific inputs, but instead for the entire form section) |
|
| 215 | - foreach ($this->_form_section->get_validation_errors() as $error) { |
|
| 216 | - $html .= $error->getMessage() . '<br>'; |
|
| 217 | - } |
|
| 218 | - $html .= '</div>'; |
|
| 219 | - } |
|
| 220 | - return apply_filters( |
|
| 221 | - 'FHEE__EE_Form_Section_Layout_Base__display_form_wide_errors', |
|
| 222 | - $html, |
|
| 223 | - $this |
|
| 224 | - ); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * returns the HTML for the server-side validation errors for the specified input |
|
| 231 | - * Note that if JS is enabled, it should remove these and instead |
|
| 232 | - * populate the form's errors in the jquery validate fashion |
|
| 233 | - * using the localized data provided to the JS |
|
| 234 | - * |
|
| 235 | - * @param EE_Form_Input_Base $input |
|
| 236 | - * @return string |
|
| 237 | - */ |
|
| 238 | - public function display_errors($input) |
|
| 239 | - { |
|
| 240 | - if ($input->get_validation_errors()) { |
|
| 241 | - return "<label id='" |
|
| 242 | - . $input->html_id() |
|
| 243 | - . "-error' class='error' for='{$input->html_name()}'>" |
|
| 244 | - . $input->get_validation_error_string() |
|
| 245 | - . '</label>'; |
|
| 246 | - } |
|
| 247 | - return ''; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Displays the help span for the specified input |
|
| 254 | - * |
|
| 255 | - * @param EE_Form_Input_Base $input |
|
| 256 | - * @return string |
|
| 257 | - */ |
|
| 258 | - public function display_help_text($input) |
|
| 259 | - { |
|
| 260 | - $help_text = $input->html_help_text(); |
|
| 261 | - if ($help_text !== '' && $help_text !== null) { |
|
| 262 | - $tag = is_admin() ? 'p' : 'span'; |
|
| 263 | - return '<' |
|
| 264 | - . $tag |
|
| 265 | - . ' id="' |
|
| 266 | - . $input->html_id() |
|
| 267 | - . '-help" class="' |
|
| 268 | - . $input->html_help_class() |
|
| 269 | - . '" style="' |
|
| 270 | - . $input->html_help_style() |
|
| 271 | - . '">' |
|
| 272 | - . $help_text |
|
| 273 | - . '</' |
|
| 274 | - . $tag |
|
| 275 | - . '>'; |
|
| 276 | - } |
|
| 277 | - return ''; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * Does an action and hook onto the end of teh form |
|
| 284 | - * |
|
| 285 | - * @param string $html |
|
| 286 | - * @return string |
|
| 287 | - */ |
|
| 288 | - public function add_form_section_hooks_and_filters($html) |
|
| 289 | - { |
|
| 290 | - // replace dashes and spaces with underscores |
|
| 291 | - $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
|
| 292 | - do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
| 293 | - $html = (string) apply_filters( |
|
| 294 | - 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
| 295 | - $html, |
|
| 296 | - $this->_form_section |
|
| 297 | - ); |
|
| 298 | - $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
| 299 | - $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
| 300 | - return $html; |
|
| 301 | - } |
|
| 18 | + /** |
|
| 19 | + * Form form section to lay out |
|
| 20 | + * |
|
| 21 | + * @var EE_Form_Section_Proper |
|
| 22 | + */ |
|
| 23 | + protected $_form_section; |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * __construct |
|
| 29 | + */ |
|
| 30 | + public function __construct() |
|
| 31 | + { |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * The form section on which this strategy is to perform |
|
| 38 | + * |
|
| 39 | + * @param EE_Form_Section_Proper $form |
|
| 40 | + */ |
|
| 41 | + public function _construct_finalize(EE_Form_Section_Proper $form) |
|
| 42 | + { |
|
| 43 | + $this->_form_section = $form; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @return EE_Form_Section_Proper |
|
| 50 | + */ |
|
| 51 | + public function form_section() |
|
| 52 | + { |
|
| 53 | + return $this->_form_section; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Also has teh side effect of enqueuing any needed JS and CSS for |
|
| 60 | + * this form. |
|
| 61 | + * Creates all the HTML necessary for displaying this form, its inputs, and |
|
| 62 | + * proper subsections. |
|
| 63 | + * Returns the HTML |
|
| 64 | + * |
|
| 65 | + * @return string HTML for displaying |
|
| 66 | + * @throws EE_Error |
|
| 67 | + */ |
|
| 68 | + public function layout_form() |
|
| 69 | + { |
|
| 70 | + $html = ''; |
|
| 71 | + // layout_form_begin |
|
| 72 | + $html .= apply_filters( |
|
| 73 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
| 74 | + $this->layout_form_begin(), |
|
| 75 | + $this->_form_section |
|
| 76 | + ); |
|
| 77 | + // layout_form_loop |
|
| 78 | + $html .= apply_filters( |
|
| 79 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
| 80 | + $this->layout_form_loop(), |
|
| 81 | + $this->_form_section |
|
| 82 | + ); |
|
| 83 | + // layout_form_end |
|
| 84 | + $html .= apply_filters( |
|
| 85 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
| 86 | + $this->layout_form_end(), |
|
| 87 | + $this->_form_section |
|
| 88 | + ); |
|
| 89 | + $html = $this->add_form_section_hooks_and_filters($html); |
|
| 90 | + return $html; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @return string |
|
| 97 | + * @throws EE_Error |
|
| 98 | + */ |
|
| 99 | + public function layout_form_loop() |
|
| 100 | + { |
|
| 101 | + $html = ''; |
|
| 102 | + foreach ($this->_form_section->subsections() as $name => $subsection) { |
|
| 103 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 104 | + $html .= apply_filters( |
|
| 105 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
|
| 106 | + . $name . '__in_' . $this->_form_section->name(), |
|
| 107 | + $this->layout_input($subsection), |
|
| 108 | + $this->_form_section, |
|
| 109 | + $subsection |
|
| 110 | + ); |
|
| 111 | + } elseif ($subsection instanceof EE_Form_Section_Base) { |
|
| 112 | + $html .= apply_filters( |
|
| 113 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
|
| 114 | + . $name . '__in_' . $this->_form_section->name(), |
|
| 115 | + $this->layout_subsection($subsection), |
|
| 116 | + $this->_form_section, |
|
| 117 | + $subsection |
|
| 118 | + ); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + return $html; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
| 128 | + * |
|
| 129 | + * @return string |
|
| 130 | + */ |
|
| 131 | + abstract public function layout_form_begin(); |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Should be used to end the form section (eg a /table tag, or a /div tag, etc) |
|
| 137 | + * |
|
| 138 | + * @return string |
|
| 139 | + */ |
|
| 140 | + abstract public function layout_form_end(); |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Should be used internally by layout_form() to layout each input (eg, if this layout |
|
| 146 | + * is putting each input in a row of its own, this should probably be called by a |
|
| 147 | + * foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop. |
|
| 148 | + * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely |
|
| 149 | + * customize the form's layout, but would like to make use of it for laying out |
|
| 150 | + * 'easy-to-layout' inputs |
|
| 151 | + * |
|
| 152 | + * @param EE_Form_Input_Base $input |
|
| 153 | + * @return string html |
|
| 154 | + */ |
|
| 155 | + abstract public function layout_input($input); |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Similar to layout_input(), should be used internally by layout_form() within a |
|
| 161 | + * loop to layout each proper subsection. Unlike layout_input(), however, it is assumed |
|
| 162 | + * that the proper subsection will layout its container, label, etc on its own. |
|
| 163 | + * |
|
| 164 | + * @param EE_Form_Section_Base $subsection |
|
| 165 | + * @return string html |
|
| 166 | + */ |
|
| 167 | + abstract public function layout_subsection($subsection); |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Gets the HTML for the label tag and its contents for the input |
|
| 173 | + * |
|
| 174 | + * @param EE_Form_Input_Base $input |
|
| 175 | + * @return string |
|
| 176 | + */ |
|
| 177 | + public function display_label($input) |
|
| 178 | + { |
|
| 179 | + if($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy){ |
|
| 180 | + return ''; |
|
| 181 | + } |
|
| 182 | + $class = $input->required() |
|
| 183 | + ? 'ee-required-label ' . $input->html_label_class() |
|
| 184 | + : $input->html_label_class(); |
|
| 185 | + $label_text = $input->required() |
|
| 186 | + ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
| 187 | + : $input->html_label_text(); |
|
| 188 | + return '<label id="' |
|
| 189 | + . $input->html_label_id() |
|
| 190 | + . '" class="' |
|
| 191 | + . $class |
|
| 192 | + . '" style="' |
|
| 193 | + . $input->html_label_style() |
|
| 194 | + . '" for="' . $input->html_name() |
|
| 195 | + . '">' |
|
| 196 | + . $label_text |
|
| 197 | + . '</label>'; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Gets the HTML for all the form's form-wide errors (ie, errors which |
|
| 204 | + * are not for specific inputs. E.g., if two inputs somehow disagree, |
|
| 205 | + * those errors would probably be on the form section, not one of its inputs) |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + public function display_form_wide_errors() |
|
| 209 | + { |
|
| 210 | + $html = ''; |
|
| 211 | + if ($this->_form_section->get_validation_errors()) { |
|
| 212 | + $html .= "<div class='ee-form-wide-errors'>"; |
|
| 213 | + //get all the errors on THIS form section (errors which aren't |
|
| 214 | + //for specific inputs, but instead for the entire form section) |
|
| 215 | + foreach ($this->_form_section->get_validation_errors() as $error) { |
|
| 216 | + $html .= $error->getMessage() . '<br>'; |
|
| 217 | + } |
|
| 218 | + $html .= '</div>'; |
|
| 219 | + } |
|
| 220 | + return apply_filters( |
|
| 221 | + 'FHEE__EE_Form_Section_Layout_Base__display_form_wide_errors', |
|
| 222 | + $html, |
|
| 223 | + $this |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * returns the HTML for the server-side validation errors for the specified input |
|
| 231 | + * Note that if JS is enabled, it should remove these and instead |
|
| 232 | + * populate the form's errors in the jquery validate fashion |
|
| 233 | + * using the localized data provided to the JS |
|
| 234 | + * |
|
| 235 | + * @param EE_Form_Input_Base $input |
|
| 236 | + * @return string |
|
| 237 | + */ |
|
| 238 | + public function display_errors($input) |
|
| 239 | + { |
|
| 240 | + if ($input->get_validation_errors()) { |
|
| 241 | + return "<label id='" |
|
| 242 | + . $input->html_id() |
|
| 243 | + . "-error' class='error' for='{$input->html_name()}'>" |
|
| 244 | + . $input->get_validation_error_string() |
|
| 245 | + . '</label>'; |
|
| 246 | + } |
|
| 247 | + return ''; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Displays the help span for the specified input |
|
| 254 | + * |
|
| 255 | + * @param EE_Form_Input_Base $input |
|
| 256 | + * @return string |
|
| 257 | + */ |
|
| 258 | + public function display_help_text($input) |
|
| 259 | + { |
|
| 260 | + $help_text = $input->html_help_text(); |
|
| 261 | + if ($help_text !== '' && $help_text !== null) { |
|
| 262 | + $tag = is_admin() ? 'p' : 'span'; |
|
| 263 | + return '<' |
|
| 264 | + . $tag |
|
| 265 | + . ' id="' |
|
| 266 | + . $input->html_id() |
|
| 267 | + . '-help" class="' |
|
| 268 | + . $input->html_help_class() |
|
| 269 | + . '" style="' |
|
| 270 | + . $input->html_help_style() |
|
| 271 | + . '">' |
|
| 272 | + . $help_text |
|
| 273 | + . '</' |
|
| 274 | + . $tag |
|
| 275 | + . '>'; |
|
| 276 | + } |
|
| 277 | + return ''; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * Does an action and hook onto the end of teh form |
|
| 284 | + * |
|
| 285 | + * @param string $html |
|
| 286 | + * @return string |
|
| 287 | + */ |
|
| 288 | + public function add_form_section_hooks_and_filters($html) |
|
| 289 | + { |
|
| 290 | + // replace dashes and spaces with underscores |
|
| 291 | + $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
|
| 292 | + do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
| 293 | + $html = (string) apply_filters( |
|
| 294 | + 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
| 295 | + $html, |
|
| 296 | + $this->_form_section |
|
| 297 | + ); |
|
| 298 | + $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
| 299 | + $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
| 300 | + return $html; |
|
| 301 | + } |
|
| 302 | 302 | } |
@@ -70,19 +70,19 @@ discard block |
||
| 70 | 70 | $html = ''; |
| 71 | 71 | // layout_form_begin |
| 72 | 72 | $html .= apply_filters( |
| 73 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
| 73 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_'.$this->_form_section->name(), |
|
| 74 | 74 | $this->layout_form_begin(), |
| 75 | 75 | $this->_form_section |
| 76 | 76 | ); |
| 77 | 77 | // layout_form_loop |
| 78 | 78 | $html .= apply_filters( |
| 79 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
| 79 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_'.$this->_form_section->name(), |
|
| 80 | 80 | $this->layout_form_loop(), |
| 81 | 81 | $this->_form_section |
| 82 | 82 | ); |
| 83 | 83 | // layout_form_end |
| 84 | 84 | $html .= apply_filters( |
| 85 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
| 85 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_'.$this->_form_section->name(), |
|
| 86 | 86 | $this->layout_form_end(), |
| 87 | 87 | $this->_form_section |
| 88 | 88 | ); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | if ($subsection instanceof EE_Form_Input_Base) { |
| 104 | 104 | $html .= apply_filters( |
| 105 | 105 | 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
| 106 | - . $name . '__in_' . $this->_form_section->name(), |
|
| 106 | + . $name.'__in_'.$this->_form_section->name(), |
|
| 107 | 107 | $this->layout_input($subsection), |
| 108 | 108 | $this->_form_section, |
| 109 | 109 | $subsection |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | } elseif ($subsection instanceof EE_Form_Section_Base) { |
| 112 | 112 | $html .= apply_filters( |
| 113 | 113 | 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
| 114 | - . $name . '__in_' . $this->_form_section->name(), |
|
| 114 | + . $name.'__in_'.$this->_form_section->name(), |
|
| 115 | 115 | $this->layout_subsection($subsection), |
| 116 | 116 | $this->_form_section, |
| 117 | 117 | $subsection |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | public function display_label($input) |
| 178 | 178 | { |
| 179 | - if($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy){ |
|
| 179 | + if ($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 180 | 180 | return ''; |
| 181 | 181 | } |
| 182 | 182 | $class = $input->required() |
| 183 | - ? 'ee-required-label ' . $input->html_label_class() |
|
| 183 | + ? 'ee-required-label '.$input->html_label_class() |
|
| 184 | 184 | : $input->html_label_class(); |
| 185 | 185 | $label_text = $input->required() |
| 186 | - ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
| 186 | + ? $input->html_label_text().'<span class="ee-asterisk">*</span>' |
|
| 187 | 187 | : $input->html_label_text(); |
| 188 | 188 | return '<label id="' |
| 189 | 189 | . $input->html_label_id() |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | . $class |
| 192 | 192 | . '" style="' |
| 193 | 193 | . $input->html_label_style() |
| 194 | - . '" for="' . $input->html_name() |
|
| 194 | + . '" for="'.$input->html_name() |
|
| 195 | 195 | . '">' |
| 196 | 196 | . $label_text |
| 197 | 197 | . '</label>'; |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | //get all the errors on THIS form section (errors which aren't |
| 214 | 214 | //for specific inputs, but instead for the entire form section) |
| 215 | 215 | foreach ($this->_form_section->get_validation_errors() as $error) { |
| 216 | - $html .= $error->getMessage() . '<br>'; |
|
| 216 | + $html .= $error->getMessage().'<br>'; |
|
| 217 | 217 | } |
| 218 | 218 | $html .= '</div>'; |
| 219 | 219 | } |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | public function display_help_text($input) |
| 259 | 259 | { |
| 260 | - $help_text = $input->html_help_text(); |
|
| 260 | + $help_text = $input->html_help_text(); |
|
| 261 | 261 | if ($help_text !== '' && $help_text !== null) { |
| 262 | 262 | $tag = is_admin() ? 'p' : 'span'; |
| 263 | 263 | return '<' |
@@ -289,14 +289,14 @@ discard block |
||
| 289 | 289 | { |
| 290 | 290 | // replace dashes and spaces with underscores |
| 291 | 291 | $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
| 292 | - do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
| 292 | + do_action('AHEE__Form_Section_Layout__'.$hook_name, $this->_form_section); |
|
| 293 | 293 | $html = (string) apply_filters( |
| 294 | - 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
| 294 | + 'AFEE__Form_Section_Layout__'.$hook_name.'__html', |
|
| 295 | 295 | $html, |
| 296 | 296 | $this->_form_section |
| 297 | 297 | ); |
| 298 | - $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
| 299 | - $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
| 298 | + $html .= EEH_HTML::nl().'<!-- AHEE__Form_Section_Layout__'.$hook_name.'__html -->'; |
|
| 299 | + $html .= EEH_HTML::nl().'<!-- AFEE__Form_Section_Layout__'.$hook_name.' -->'; |
|
| 300 | 300 | return $html; |
| 301 | 301 | } |
| 302 | 302 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public static function instance() { |
| 34 | 34 | // check if class object is instantiated |
| 35 | - if ( self::$_instance === NULL or ! is_object( self::$_instance ) or ! ( self::$_instance instanceof EEH_Qtip_Loader )) { |
|
| 35 | + if (self::$_instance === NULL or ! is_object(self::$_instance) or ! (self::$_instance instanceof EEH_Qtip_Loader)) { |
|
| 36 | 36 | self::$_instance = new self(); |
| 37 | 37 | } |
| 38 | 38 | return self::$_instance; |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | private function __construct() { |
| 50 | 50 | //let's just make sure this is instantiated in the right place. |
| 51 | - if ( did_action( 'wp_print_styles' ) || did_action( 'admin_head' )) { |
|
| 52 | - EE_Error::doing_it_wrong( 'EEH_Qtip_Loader', __('This helper must be instantiated before or within a callback for the WordPress wp_enqueue_scripts hook action hook.', 'event_espresso' ), '4.1' ); |
|
| 51 | + if (did_action('wp_print_styles') || did_action('admin_head')) { |
|
| 52 | + EE_Error::doing_it_wrong('EEH_Qtip_Loader', __('This helper must be instantiated before or within a callback for the WordPress wp_enqueue_scripts hook action hook.', 'event_espresso'), '4.1'); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
@@ -61,25 +61,25 @@ discard block |
||
| 61 | 61 | * @return void |
| 62 | 62 | */ |
| 63 | 63 | public function register_and_enqueue() { |
| 64 | - $qtips_js = !defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.js' : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.js'; |
|
| 65 | - $qtip_map = EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.map'; |
|
| 66 | - $qtipcss = !defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.css' : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.css'; |
|
| 64 | + $qtips_js = ! defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.js' : EE_THIRD_PARTY_URL.'qtip/jquery.qtip.js'; |
|
| 65 | + $qtip_map = EE_THIRD_PARTY_URL.'qtip/jquery.qtip.min.map'; |
|
| 66 | + $qtipcss = ! defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.css' : EE_THIRD_PARTY_URL.'qtip/jquery.qtip.css'; |
|
| 67 | 67 | |
| 68 | - wp_register_script('qtip-map', $qtip_map, array(), '3', TRUE ); |
|
| 69 | - wp_register_script('qtip', $qtips_js, array('jquery'), '3.0.3', TRUE ); |
|
| 70 | - wp_register_script('ee-qtip-helper', EE_HELPERS_ASSETS . 'ee-qtip-helper.js', array('qtip', 'jquery-cookie'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
| 68 | + wp_register_script('qtip-map', $qtip_map, array(), '3', TRUE); |
|
| 69 | + wp_register_script('qtip', $qtips_js, array('jquery'), '3.0.3', TRUE); |
|
| 70 | + wp_register_script('ee-qtip-helper', EE_HELPERS_ASSETS.'ee-qtip-helper.js', array('qtip', 'jquery-cookie'), EVENT_ESPRESSO_VERSION, TRUE); |
|
| 71 | 71 | |
| 72 | - wp_register_style('qtip-css', $qtipcss, array(), '2.2' ); |
|
| 72 | + wp_register_style('qtip-css', $qtipcss, array(), '2.2'); |
|
| 73 | 73 | |
| 74 | 74 | //k now let's see if there are any registered qtips. If there are, then we need to setup the localized script for ee-qtip-helper.js (and enqueue ee-qtip-helper.js of course!) |
| 75 | - if ( !empty( $this->_qtips ) ) { |
|
| 75 | + if ( ! empty($this->_qtips)) { |
|
| 76 | 76 | wp_enqueue_script('ee-qtip-helper'); |
| 77 | 77 | wp_enqueue_style('qtip-css'); |
| 78 | 78 | $qtips = array(); |
| 79 | - foreach ( $this->_qtips as $qtip ) { |
|
| 79 | + foreach ($this->_qtips as $qtip) { |
|
| 80 | 80 | $qts = $qtip->get_tips(); |
| 81 | - foreach ( $qts as $qt ) { |
|
| 82 | - if ( ! $qt instanceof EE_Qtip ) |
|
| 81 | + foreach ($qts as $qt) { |
|
| 82 | + if ( ! $qt instanceof EE_Qtip) |
|
| 83 | 83 | continue; |
| 84 | 84 | $qtips[] = array( |
| 85 | 85 | 'content_id' => $qt->content_id, |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | ); |
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | - if ( !empty($qtips) ) |
|
| 92 | - wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array( 'qtips' => $qtips ) ); |
|
| 91 | + if ( ! empty($qtips)) |
|
| 92 | + wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array('qtips' => $qtips)); |
|
| 93 | 93 | |
| 94 | 94 | } else { |
| 95 | 95 | //qtips has been requested without any registration (so assuming its just directly used in the admin). |
@@ -111,24 +111,24 @@ discard block |
||
| 111 | 111 | * @param string|array $configname name of the Qtip class (full class name is expected and will be used for looking for file, Qtip config classes must extend EE_Qtip_Config) [if this is an array, then we loop through the array to instantiate and setup the qtips] |
| 112 | 112 | * @return void |
| 113 | 113 | */ |
| 114 | - public function register( $configname, $paths = array() ) { |
|
| 114 | + public function register($configname, $paths = array()) { |
|
| 115 | 115 | |
| 116 | 116 | //let's just make sure this is instantiated in the right place. |
| 117 | - if ( did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts') ) { |
|
| 118 | - EE_Error::doing_it_wrong( 'EEH_Qtip_Loader->register()', __('EE_Qtip_Config objects must be registered before wp_enqueue_scripts is called.', 'event_espresso' ), '4.1' ); |
|
| 117 | + if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
| 118 | + EE_Error::doing_it_wrong('EEH_Qtip_Loader->register()', __('EE_Qtip_Config objects must be registered before wp_enqueue_scripts is called.', 'event_espresso'), '4.1'); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | $configname = (array) $configname; //typecast to array |
| 122 | - foreach ( $configname as $config ) { |
|
| 123 | - $this->_register( $config, $paths ); |
|
| 122 | + foreach ($configname as $config) { |
|
| 123 | + $this->_register($config, $paths); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | //hook into appropriate footer |
| 127 | 127 | $footer_action = is_admin() ? 'admin_footer' : 'wp_footer'; |
| 128 | - add_action($footer_action, array($this, 'setup_qtip'), 10 ); |
|
| 128 | + add_action($footer_action, array($this, 'setup_qtip'), 10); |
|
| 129 | 129 | |
| 130 | 130 | //make sure we "turn on" qtip js. |
| 131 | - add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 131 | + add_filter('FHEE_load_qtip', '__return_true'); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | |
@@ -142,15 +142,15 @@ discard block |
||
| 142 | 142 | * @throws EE_Error |
| 143 | 143 | * @return void |
| 144 | 144 | */ |
| 145 | - private function _register( $config, $paths ) { |
|
| 145 | + private function _register($config, $paths) { |
|
| 146 | 146 | //before doing anything we have to make sure that EE_Qtip_Config parent is required. |
| 147 | - EE_Registry::instance()->load_lib( 'Qtip_Config', array(), TRUE ); |
|
| 147 | + EE_Registry::instance()->load_lib('Qtip_Config', array(), TRUE); |
|
| 148 | 148 | |
| 149 | - if ( !empty( $paths ) ) { |
|
| 149 | + if ( ! empty($paths)) { |
|
| 150 | 150 | $paths = (array) $paths; |
| 151 | - foreach ( $paths as $path ) { |
|
| 152 | - $path = $path . $config . '.lib.php'; |
|
| 153 | - if ( !is_readable($path ) ) { |
|
| 151 | + foreach ($paths as $path) { |
|
| 152 | + $path = $path.$config.'.lib.php'; |
|
| 153 | + if ( ! is_readable($path)) { |
|
| 154 | 154 | continue; |
| 155 | 155 | } else { |
| 156 | 156 | require_once $path; |
@@ -159,26 +159,26 @@ discard block |
||
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | //does class exist at this point? If it does then let's instantiate. If it doesn't then let's continue with other paths. |
| 162 | - if ( !class_exists($config) ) { |
|
| 163 | - $path = EE_LIBRARIES . 'qtips/' . $config . '.lib.php'; |
|
| 164 | - if ( !is_readable($path ) ) { |
|
| 165 | - throw new EE_Error( sprintf( __('Unable to load the Qtip Config registered for this page (%s) because none of the file paths attempted are readable. Please check the spelling of the paths you\'ve used in the registration', 'event_espresso'), $config ) ); |
|
| 162 | + if ( ! class_exists($config)) { |
|
| 163 | + $path = EE_LIBRARIES.'qtips/'.$config.'.lib.php'; |
|
| 164 | + if ( ! is_readable($path)) { |
|
| 165 | + throw new EE_Error(sprintf(__('Unable to load the Qtip Config registered for this page (%s) because none of the file paths attempted are readable. Please check the spelling of the paths you\'ve used in the registration', 'event_espresso'), $config)); |
|
| 166 | 166 | } else { |
| 167 | 167 | require_once $path; |
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | //now we attempt a class_exists one more time. |
| 172 | - if ( !class_exists( $config ) ) |
|
| 173 | - throw new EE_Error( sprintf( __('The Qtip_Config class being registered (%s) does not exist, please check the spelling.', 'event_espresso'), $config ) ); |
|
| 172 | + if ( ! class_exists($config)) |
|
| 173 | + throw new EE_Error(sprintf(__('The Qtip_Config class being registered (%s) does not exist, please check the spelling.', 'event_espresso'), $config)); |
|
| 174 | 174 | |
| 175 | 175 | //made it HERE? FINALLY, let's get things setup. |
| 176 | 176 | $a = new ReflectionClass($config); |
| 177 | 177 | $qtip = $a->newInstance(); |
| 178 | 178 | |
| 179 | 179 | //verify that $qtip is a valid object |
| 180 | - if ( ! $qtip instanceof EE_Qtip_Config ) |
|
| 181 | - throw new EE_Error( sprintf( esc_html__( 'The class given for the Qtip loader (%1$s) is not a child of the %2$sEE_Qtip_Config%3$s class. Please make sure you are extending EE_Qtip_Config.', 'event_espresso'), $config, '<strong>', '</strong>' ) ); |
|
| 180 | + if ( ! $qtip instanceof EE_Qtip_Config) |
|
| 181 | + throw new EE_Error(sprintf(esc_html__('The class given for the Qtip loader (%1$s) is not a child of the %2$sEE_Qtip_Config%3$s class. Please make sure you are extending EE_Qtip_Config.', 'event_espresso'), $config, '<strong>', '</strong>')); |
|
| 182 | 182 | |
| 183 | 183 | $this->_qtips[] = $a->newInstance(); |
| 184 | 184 | |
@@ -194,12 +194,12 @@ discard block |
||
| 194 | 194 | * @return void |
| 195 | 195 | */ |
| 196 | 196 | public function setup_qtip() { |
| 197 | - if ( empty( $this->_qtips ) ) |
|
| 197 | + if (empty($this->_qtips)) |
|
| 198 | 198 | return; //no qtips! |
| 199 | 199 | |
| 200 | 200 | $content = array(); |
| 201 | 201 | |
| 202 | - foreach ( $this->_qtips as $qtip ) { |
|
| 202 | + foreach ($this->_qtips as $qtip) { |
|
| 203 | 203 | $content[] = $this->_generate_content_container($qtip); |
| 204 | 204 | } |
| 205 | 205 | |
@@ -216,10 +216,10 @@ discard block |
||
| 216 | 216 | private function _generate_content_container($qtip) { |
| 217 | 217 | $qts = $qtip->get_tips(); |
| 218 | 218 | $content = array(); |
| 219 | - foreach ( $qts as $qt ) { |
|
| 220 | - if ( ! $qt instanceof EE_Qtip ) |
|
| 219 | + foreach ($qts as $qt) { |
|
| 220 | + if ( ! $qt instanceof EE_Qtip) |
|
| 221 | 221 | continue; |
| 222 | - $content[] = '<div class="ee-qtip-helper-content hidden" id="' . $qt->content_id . '">' . $qt->content . '</div>'; |
|
| 222 | + $content[] = '<div class="ee-qtip-helper-content hidden" id="'.$qt->content_id.'">'.$qt->content.'</div>'; |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | return implode('<br />', $content); |
@@ -19,126 +19,126 @@ |
||
| 19 | 19 | abstract class DomainBase implements DomainInterface |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Equivalent to `__FILE__` for main plugin file. |
|
| 24 | - * |
|
| 25 | - * @var FilePath |
|
| 26 | - */ |
|
| 27 | - private $plugin_file; |
|
| 22 | + /** |
|
| 23 | + * Equivalent to `__FILE__` for main plugin file. |
|
| 24 | + * |
|
| 25 | + * @var FilePath |
|
| 26 | + */ |
|
| 27 | + private $plugin_file; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * String indicating version for plugin |
|
| 31 | - * |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - private $version; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var string $plugin_basename |
|
| 38 | - */ |
|
| 39 | - private $plugin_basename; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var string $plugin_path |
|
| 43 | - */ |
|
| 44 | - private $plugin_path; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var string $plugin_url |
|
| 48 | - */ |
|
| 49 | - private $plugin_url; |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Initializes internal properties. |
|
| 55 | - * |
|
| 56 | - * @param FilePath $plugin_file |
|
| 57 | - * @param Version $version |
|
| 58 | - */ |
|
| 59 | - public function __construct(FilePath $plugin_file, Version $version) |
|
| 60 | - { |
|
| 61 | - $this->plugin_file = $plugin_file; |
|
| 62 | - $this->version = $version; |
|
| 63 | - $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
| 64 | - $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
| 65 | - $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @return string |
|
| 71 | - */ |
|
| 72 | - public function pluginFile() |
|
| 73 | - { |
|
| 74 | - return (string) $this->plugin_file; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function pluginBasename() |
|
| 83 | - { |
|
| 84 | - return $this->plugin_basename; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - public function pluginPath() |
|
| 93 | - { |
|
| 94 | - return $this->plugin_path; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - public function pluginUrl() |
|
| 103 | - { |
|
| 104 | - return $this->plugin_url; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public function version() |
|
| 113 | - { |
|
| 114 | - return (string) $this->version; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @return Version |
|
| 121 | - */ |
|
| 122 | - public function versionValueObject() |
|
| 123 | - { |
|
| 124 | - return $this->version; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @return string |
|
| 130 | - */ |
|
| 131 | - public function distributionAssetsPath() |
|
| 132 | - { |
|
| 133 | - return $this->pluginPath() . 'assets/dist/'; |
|
| 134 | - } |
|
| 29 | + /** |
|
| 30 | + * String indicating version for plugin |
|
| 31 | + * |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + private $version; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var string $plugin_basename |
|
| 38 | + */ |
|
| 39 | + private $plugin_basename; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var string $plugin_path |
|
| 43 | + */ |
|
| 44 | + private $plugin_path; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var string $plugin_url |
|
| 48 | + */ |
|
| 49 | + private $plugin_url; |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Initializes internal properties. |
|
| 55 | + * |
|
| 56 | + * @param FilePath $plugin_file |
|
| 57 | + * @param Version $version |
|
| 58 | + */ |
|
| 59 | + public function __construct(FilePath $plugin_file, Version $version) |
|
| 60 | + { |
|
| 61 | + $this->plugin_file = $plugin_file; |
|
| 62 | + $this->version = $version; |
|
| 63 | + $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
| 64 | + $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
| 65 | + $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @return string |
|
| 71 | + */ |
|
| 72 | + public function pluginFile() |
|
| 73 | + { |
|
| 74 | + return (string) $this->plugin_file; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function pluginBasename() |
|
| 83 | + { |
|
| 84 | + return $this->plugin_basename; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + public function pluginPath() |
|
| 93 | + { |
|
| 94 | + return $this->plugin_path; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + public function pluginUrl() |
|
| 103 | + { |
|
| 104 | + return $this->plugin_url; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public function version() |
|
| 113 | + { |
|
| 114 | + return (string) $this->version; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @return Version |
|
| 121 | + */ |
|
| 122 | + public function versionValueObject() |
|
| 123 | + { |
|
| 124 | + return $this->version; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @return string |
|
| 130 | + */ |
|
| 131 | + public function distributionAssetsPath() |
|
| 132 | + { |
|
| 133 | + return $this->pluginPath() . 'assets/dist/'; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @return string |
|
| 139 | - */ |
|
| 140 | - public function distributionAssetsUrl() |
|
| 141 | - { |
|
| 142 | - return $this->pluginUrl() . 'assets/dist/'; |
|
| 143 | - } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @return string |
|
| 139 | + */ |
|
| 140 | + public function distributionAssetsUrl() |
|
| 141 | + { |
|
| 142 | + return $this->pluginUrl() . 'assets/dist/'; |
|
| 143 | + } |
|
| 144 | 144 | } |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | public function distributionAssetsPath() |
| 132 | 132 | { |
| 133 | - return $this->pluginPath() . 'assets/dist/'; |
|
| 133 | + return $this->pluginPath().'assets/dist/'; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | |
@@ -139,6 +139,6 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | public function distributionAssetsUrl() |
| 141 | 141 | { |
| 142 | - return $this->pluginUrl() . 'assets/dist/'; |
|
| 142 | + return $this->pluginUrl().'assets/dist/'; |
|
| 143 | 143 | } |
| 144 | 144 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | use EventEspresso\core\services\request\RequestInterface; |
| 8 | 8 | use EventEspresso\core\services\request\ResponseInterface; |
| 9 | 9 | |
| 10 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 10 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 11 | 11 | exit('No direct script access allowed'); |
| 12 | 12 | } |
| 13 | 13 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | public static function instance() { |
| 131 | 131 | // check if class object is instantiated, and instantiated properly |
| 132 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 132 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
| 133 | 133 | self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/); |
| 134 | 134 | } |
| 135 | 135 | return self::$_instance; |
@@ -211,8 +211,8 @@ discard block |
||
| 211 | 211 | ) { |
| 212 | 212 | $class = trim($class, '\\'); |
| 213 | 213 | $registered = false; |
| 214 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 215 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
| 214 | + if (empty(self::$_instance->_dependency_map[$class])) { |
|
| 215 | + self::$_instance->_dependency_map[$class] = array(); |
|
| 216 | 216 | } |
| 217 | 217 | // we need to make sure that any aliases used when registering a dependency |
| 218 | 218 | // get resolved to the correct class name |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | $alias = self::$_instance->get_alias($dependency); |
| 221 | 221 | if ( |
| 222 | 222 | $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
| 223 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 223 | + || ! isset(self::$_instance->_dependency_map[$class][$alias]) |
|
| 224 | 224 | ) { |
| 225 | 225 | unset($dependencies[$dependency]); |
| 226 | 226 | $dependencies[$alias] = $load_source; |
@@ -233,13 +233,13 @@ discard block |
||
| 233 | 233 | // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
| 234 | 234 | // Union is way faster than array_merge() but should be used with caution... |
| 235 | 235 | // especially with numerically indexed arrays |
| 236 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 236 | + $dependencies += self::$_instance->_dependency_map[$class]; |
|
| 237 | 237 | // now we need to ensure that the resulting dependencies |
| 238 | 238 | // array only has the entries that are required for the class |
| 239 | 239 | // so first count how many dependencies were originally registered for the class |
| 240 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 240 | + $dependency_count = count(self::$_instance->_dependency_map[$class]); |
|
| 241 | 241 | // if that count is non-zero (meaning dependencies were already registered) |
| 242 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 242 | + self::$_instance->_dependency_map[$class] = $dependency_count |
|
| 243 | 243 | // then truncate the final array to match that count |
| 244 | 244 | ? array_slice($dependencies, 0, $dependency_count) |
| 245 | 245 | // otherwise just take the incoming array because nothing previously existed |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | public static function register_class_loader($class_name, $loader = 'load_core') |
| 259 | 259 | { |
| 260 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 260 | + if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 261 | 261 | throw new DomainException( |
| 262 | 262 | esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
| 263 | 263 | ); |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | ); |
| 282 | 282 | } |
| 283 | 283 | $class_name = self::$_instance->get_alias($class_name); |
| 284 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 284 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 285 | 285 | self::$_instance->_class_loaders[$class_name] = $loader; |
| 286 | 286 | return true; |
| 287 | 287 | } |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | public function class_loader($class_name) |
| 367 | 367 | { |
| 368 | 368 | // all legacy models use load_model() |
| 369 | - if(strpos($class_name, 'EEM_') === 0){ |
|
| 369 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 370 | 370 | return 'load_model'; |
| 371 | 371 | } |
| 372 | 372 | $class_name = $this->get_alias($class_name); |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | public function add_alias($class_name, $alias, $for_class = '') |
| 396 | 396 | { |
| 397 | 397 | if ($for_class !== '') { |
| 398 | - if (! isset($this->_aliases[$for_class])) { |
|
| 398 | + if ( ! isset($this->_aliases[$for_class])) { |
|
| 399 | 399 | $this->_aliases[$for_class] = array(); |
| 400 | 400 | } |
| 401 | 401 | $this->_aliases[$for_class][$class_name] = $alias; |
@@ -441,10 +441,10 @@ discard block |
||
| 441 | 441 | */ |
| 442 | 442 | public function get_alias($class_name = '', $for_class = '') |
| 443 | 443 | { |
| 444 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 444 | + if ( ! $this->has_alias($class_name, $for_class)) { |
|
| 445 | 445 | return $class_name; |
| 446 | 446 | } |
| 447 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 447 | + if ($for_class !== '' && isset($this->_aliases[$for_class][$class_name])) { |
|
| 448 | 448 | return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
| 449 | 449 | } |
| 450 | 450 | return $this->get_alias($this->_aliases[$class_name]); |
@@ -714,13 +714,13 @@ discard block |
||
| 714 | 714 | 'EE_Front_Controller' => 'load_core', |
| 715 | 715 | 'EE_Module_Request_Router' => 'load_core', |
| 716 | 716 | 'EE_Registry' => 'load_core', |
| 717 | - 'EE_Request' => function () use (&$legacy_request) { |
|
| 717 | + 'EE_Request' => function() use (&$legacy_request) { |
|
| 718 | 718 | return $legacy_request; |
| 719 | 719 | }, |
| 720 | - 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
| 720 | + 'EventEspresso\core\services\request\Request' => function() use (&$request) { |
|
| 721 | 721 | return $request; |
| 722 | 722 | }, |
| 723 | - 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
| 723 | + 'EventEspresso\core\services\request\Response' => function() use (&$response) { |
|
| 724 | 724 | return $response; |
| 725 | 725 | }, |
| 726 | 726 | 'EE_Request_Handler' => 'load_core', |
@@ -742,7 +742,7 @@ discard block |
||
| 742 | 742 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
| 743 | 743 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
| 744 | 744 | 'EE_Payment_Method_Manager' => 'load_lib', |
| 745 | - 'EE_Messages_Generator' => function () { |
|
| 745 | + 'EE_Messages_Generator' => function() { |
|
| 746 | 746 | return EE_Registry::instance()->load_lib( |
| 747 | 747 | 'Messages_Generator', |
| 748 | 748 | array(), |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | false |
| 751 | 751 | ); |
| 752 | 752 | }, |
| 753 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 753 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
| 754 | 754 | return EE_Registry::instance()->load_lib( |
| 755 | 755 | 'Messages_Template_Defaults', |
| 756 | 756 | $arguments, |
@@ -763,22 +763,22 @@ discard block |
||
| 763 | 763 | // 'EEM_Message_Template_Group' => 'load_model', |
| 764 | 764 | // 'EEM_Message_Template' => 'load_model', |
| 765 | 765 | //load_helper |
| 766 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 766 | + 'EEH_Parse_Shortcodes' => function() { |
|
| 767 | 767 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
| 768 | 768 | return new EEH_Parse_Shortcodes(); |
| 769 | 769 | } |
| 770 | 770 | return null; |
| 771 | 771 | }, |
| 772 | - 'EE_Template_Config' => function () { |
|
| 772 | + 'EE_Template_Config' => function() { |
|
| 773 | 773 | return EE_Config::instance()->template_settings; |
| 774 | 774 | }, |
| 775 | - 'EE_Currency_Config' => function () { |
|
| 775 | + 'EE_Currency_Config' => function() { |
|
| 776 | 776 | return EE_Config::instance()->currency; |
| 777 | 777 | }, |
| 778 | - 'EE_Registration_Config' => function () { |
|
| 778 | + 'EE_Registration_Config' => function() { |
|
| 779 | 779 | return EE_Config::instance()->registration; |
| 780 | 780 | }, |
| 781 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 781 | + 'EventEspresso\core\services\loaders\Loader' => function() { |
|
| 782 | 782 | return LoaderFactory::getLoader(); |
| 783 | 783 | }, |
| 784 | 784 | ); |
@@ -834,7 +834,7 @@ discard block |
||
| 834 | 834 | 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
| 835 | 835 | 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
| 836 | 836 | ); |
| 837 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 837 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 838 | 838 | $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
| 839 | 839 | } |
| 840 | 840 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | use EventEspresso\core\services\request\ResponseInterface; |
| 9 | 9 | |
| 10 | 10 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 11 | - exit('No direct script access allowed'); |
|
| 11 | + exit('No direct script access allowed'); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | |
@@ -25,841 +25,841 @@ discard block |
||
| 25 | 25 | class EE_Dependency_Map |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * This means that the requested class dependency is not present in the dependency map |
|
| 30 | - */ |
|
| 31 | - const not_registered = 0; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 35 | - */ |
|
| 36 | - const load_new_object = 1; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 40 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 41 | - */ |
|
| 42 | - const load_from_cache = 2; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * When registering a dependency, |
|
| 46 | - * this indicates to keep any existing dependencies that already exist, |
|
| 47 | - * and simply discard any new dependencies declared in the incoming data |
|
| 48 | - */ |
|
| 49 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * When registering a dependency, |
|
| 53 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 54 | - */ |
|
| 55 | - const OVERWRITE_DEPENDENCIES = 1; |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @type EE_Dependency_Map $_instance |
|
| 61 | - */ |
|
| 62 | - protected static $_instance; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @type RequestInterface $request |
|
| 66 | - */ |
|
| 67 | - protected $request; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @type LegacyRequestInterface $legacy_request |
|
| 71 | - */ |
|
| 72 | - protected $legacy_request; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @type ResponseInterface $response |
|
| 76 | - */ |
|
| 77 | - protected $response; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @type LoaderInterface $loader |
|
| 81 | - */ |
|
| 82 | - protected $loader; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @type array $_dependency_map |
|
| 86 | - */ |
|
| 87 | - protected $_dependency_map = array(); |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @type array $_class_loaders |
|
| 91 | - */ |
|
| 92 | - protected $_class_loaders = array(); |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @type array $_aliases |
|
| 96 | - */ |
|
| 97 | - protected $_aliases = array(); |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * EE_Dependency_Map constructor. |
|
| 103 | - */ |
|
| 104 | - protected function __construct() |
|
| 105 | - { |
|
| 106 | - // add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 107 | - do_action('EE_Dependency_Map____construct'); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @throws InvalidDataTypeException |
|
| 114 | - * @throws InvalidInterfaceException |
|
| 115 | - * @throws InvalidArgumentException |
|
| 116 | - */ |
|
| 117 | - public function initialize() |
|
| 118 | - { |
|
| 119 | - $this->_register_core_dependencies(); |
|
| 120 | - $this->_register_core_class_loaders(); |
|
| 121 | - $this->_register_core_aliases(); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @singleton method used to instantiate class object |
|
| 128 | - * @return EE_Dependency_Map |
|
| 129 | - */ |
|
| 130 | - public static function instance() { |
|
| 131 | - // check if class object is instantiated, and instantiated properly |
|
| 132 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 133 | - self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/); |
|
| 134 | - } |
|
| 135 | - return self::$_instance; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param RequestInterface $request |
|
| 141 | - */ |
|
| 142 | - public function setRequest(RequestInterface $request) |
|
| 143 | - { |
|
| 144 | - $this->request = $request; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @param LegacyRequestInterface $legacy_request |
|
| 150 | - */ |
|
| 151 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
| 152 | - { |
|
| 153 | - $this->legacy_request = $legacy_request; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @param ResponseInterface $response |
|
| 159 | - */ |
|
| 160 | - public function setResponse(ResponseInterface $response) |
|
| 161 | - { |
|
| 162 | - $this->response = $response; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @param LoaderInterface $loader |
|
| 169 | - */ |
|
| 170 | - public function setLoader(LoaderInterface $loader) |
|
| 171 | - { |
|
| 172 | - $this->loader = $loader; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @param string $class |
|
| 179 | - * @param array $dependencies |
|
| 180 | - * @param int $overwrite |
|
| 181 | - * @return bool |
|
| 182 | - */ |
|
| 183 | - public static function register_dependencies( |
|
| 184 | - $class, |
|
| 185 | - array $dependencies, |
|
| 186 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 187 | - ) { |
|
| 188 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 195 | - * to the class specified by the first parameter. |
|
| 196 | - * IMPORTANT !!! |
|
| 197 | - * The order of elements in the incoming $dependencies array MUST match |
|
| 198 | - * the order of the constructor parameters for the class in question. |
|
| 199 | - * This is especially important when overriding any existing dependencies that are registered. |
|
| 200 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 201 | - * |
|
| 202 | - * @param string $class |
|
| 203 | - * @param array $dependencies |
|
| 204 | - * @param int $overwrite |
|
| 205 | - * @return bool |
|
| 206 | - */ |
|
| 207 | - public function registerDependencies( |
|
| 208 | - $class, |
|
| 209 | - array $dependencies, |
|
| 210 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 211 | - ) { |
|
| 212 | - $class = trim($class, '\\'); |
|
| 213 | - $registered = false; |
|
| 214 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 215 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
| 216 | - } |
|
| 217 | - // we need to make sure that any aliases used when registering a dependency |
|
| 218 | - // get resolved to the correct class name |
|
| 219 | - foreach ($dependencies as $dependency => $load_source) { |
|
| 220 | - $alias = self::$_instance->get_alias($dependency); |
|
| 221 | - if ( |
|
| 222 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 223 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 224 | - ) { |
|
| 225 | - unset($dependencies[$dependency]); |
|
| 226 | - $dependencies[$alias] = $load_source; |
|
| 227 | - $registered = true; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - // now add our two lists of dependencies together. |
|
| 231 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
| 232 | - // so $dependencies is NOT overwritten because it is listed first |
|
| 233 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 234 | - // Union is way faster than array_merge() but should be used with caution... |
|
| 235 | - // especially with numerically indexed arrays |
|
| 236 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 237 | - // now we need to ensure that the resulting dependencies |
|
| 238 | - // array only has the entries that are required for the class |
|
| 239 | - // so first count how many dependencies were originally registered for the class |
|
| 240 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 241 | - // if that count is non-zero (meaning dependencies were already registered) |
|
| 242 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 243 | - // then truncate the final array to match that count |
|
| 244 | - ? array_slice($dependencies, 0, $dependency_count) |
|
| 245 | - // otherwise just take the incoming array because nothing previously existed |
|
| 246 | - : $dependencies; |
|
| 247 | - return $registered; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * @param string $class_name |
|
| 254 | - * @param string $loader |
|
| 255 | - * @return bool |
|
| 256 | - * @throws DomainException |
|
| 257 | - */ |
|
| 258 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 259 | - { |
|
| 260 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 261 | - throw new DomainException( |
|
| 262 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 263 | - ); |
|
| 264 | - } |
|
| 265 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 266 | - if ( |
|
| 267 | - ! is_callable($loader) |
|
| 268 | - && ( |
|
| 269 | - strpos($loader, 'load_') !== 0 |
|
| 270 | - || ! method_exists('EE_Registry', $loader) |
|
| 271 | - ) |
|
| 272 | - ) { |
|
| 273 | - throw new DomainException( |
|
| 274 | - sprintf( |
|
| 275 | - esc_html__( |
|
| 276 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 277 | - 'event_espresso' |
|
| 278 | - ), |
|
| 279 | - $loader |
|
| 280 | - ) |
|
| 281 | - ); |
|
| 282 | - } |
|
| 283 | - $class_name = self::$_instance->get_alias($class_name); |
|
| 284 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 285 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 286 | - return true; |
|
| 287 | - } |
|
| 288 | - return false; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * @return array |
|
| 295 | - */ |
|
| 296 | - public function dependency_map() |
|
| 297 | - { |
|
| 298 | - return $this->_dependency_map; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
| 305 | - * |
|
| 306 | - * @param string $class_name |
|
| 307 | - * @return boolean |
|
| 308 | - */ |
|
| 309 | - public function has($class_name = '') |
|
| 310 | - { |
|
| 311 | - // all legacy models have the same dependencies |
|
| 312 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 313 | - $class_name = 'LEGACY_MODELS'; |
|
| 314 | - } |
|
| 315 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 322 | - * |
|
| 323 | - * @param string $class_name |
|
| 324 | - * @param string $dependency |
|
| 325 | - * @return bool |
|
| 326 | - */ |
|
| 327 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 328 | - { |
|
| 329 | - // all legacy models have the same dependencies |
|
| 330 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 331 | - $class_name = 'LEGACY_MODELS'; |
|
| 332 | - } |
|
| 333 | - $dependency = $this->get_alias($dependency); |
|
| 334 | - return isset($this->_dependency_map[$class_name][$dependency]) |
|
| 335 | - ? true |
|
| 336 | - : false; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 343 | - * |
|
| 344 | - * @param string $class_name |
|
| 345 | - * @param string $dependency |
|
| 346 | - * @return int |
|
| 347 | - */ |
|
| 348 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 349 | - { |
|
| 350 | - // all legacy models have the same dependencies |
|
| 351 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 352 | - $class_name = 'LEGACY_MODELS'; |
|
| 353 | - } |
|
| 354 | - $dependency = $this->get_alias($dependency); |
|
| 355 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
| 356 | - ? $this->_dependency_map[$class_name][$dependency] |
|
| 357 | - : EE_Dependency_Map::not_registered; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * @param string $class_name |
|
| 364 | - * @return string | Closure |
|
| 365 | - */ |
|
| 366 | - public function class_loader($class_name) |
|
| 367 | - { |
|
| 368 | - // all legacy models use load_model() |
|
| 369 | - if(strpos($class_name, 'EEM_') === 0){ |
|
| 370 | - return 'load_model'; |
|
| 371 | - } |
|
| 372 | - $class_name = $this->get_alias($class_name); |
|
| 373 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * @return array |
|
| 380 | - */ |
|
| 381 | - public function class_loaders() |
|
| 382 | - { |
|
| 383 | - return $this->_class_loaders; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * adds an alias for a classname |
|
| 390 | - * |
|
| 391 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 392 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 393 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 394 | - */ |
|
| 395 | - public function add_alias($class_name, $alias, $for_class = '') |
|
| 396 | - { |
|
| 397 | - if ($for_class !== '') { |
|
| 398 | - if (! isset($this->_aliases[$for_class])) { |
|
| 399 | - $this->_aliases[$for_class] = array(); |
|
| 400 | - } |
|
| 401 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
| 402 | - } |
|
| 403 | - $this->_aliases[$class_name] = $alias; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * returns TRUE if the provided class name has an alias |
|
| 410 | - * |
|
| 411 | - * @param string $class_name |
|
| 412 | - * @param string $for_class |
|
| 413 | - * @return bool |
|
| 414 | - */ |
|
| 415 | - public function has_alias($class_name = '', $for_class = '') |
|
| 416 | - { |
|
| 417 | - return isset($this->_aliases[$for_class][$class_name]) |
|
| 418 | - || ( |
|
| 419 | - isset($this->_aliases[$class_name]) |
|
| 420 | - && ! is_array($this->_aliases[$class_name]) |
|
| 421 | - ); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
| 428 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 429 | - * for example: |
|
| 430 | - * if the following two entries were added to the _aliases array: |
|
| 431 | - * array( |
|
| 432 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 433 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 434 | - * ) |
|
| 435 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 436 | - * to load an instance of 'some\namespace\classname' |
|
| 437 | - * |
|
| 438 | - * @param string $class_name |
|
| 439 | - * @param string $for_class |
|
| 440 | - * @return string |
|
| 441 | - */ |
|
| 442 | - public function get_alias($class_name = '', $for_class = '') |
|
| 443 | - { |
|
| 444 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 445 | - return $class_name; |
|
| 446 | - } |
|
| 447 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 448 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 449 | - } |
|
| 450 | - return $this->get_alias($this->_aliases[$class_name]); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 457 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 458 | - * This is done by using the following class constants: |
|
| 459 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 460 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 461 | - */ |
|
| 462 | - protected function _register_core_dependencies() |
|
| 463 | - { |
|
| 464 | - $this->_dependency_map = array( |
|
| 465 | - 'EE_Request_Handler' => array( |
|
| 466 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 467 | - ), |
|
| 468 | - 'EE_System' => array( |
|
| 469 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 470 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 471 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 472 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 473 | - ), |
|
| 474 | - 'EE_Session' => array( |
|
| 475 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 476 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
| 477 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 478 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 479 | - ), |
|
| 480 | - 'EE_Cart' => array( |
|
| 481 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 482 | - ), |
|
| 483 | - 'EE_Front_Controller' => array( |
|
| 484 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 485 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 486 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 487 | - ), |
|
| 488 | - 'EE_Messenger_Collection_Loader' => array( |
|
| 489 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 490 | - ), |
|
| 491 | - 'EE_Message_Type_Collection_Loader' => array( |
|
| 492 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 493 | - ), |
|
| 494 | - 'EE_Message_Resource_Manager' => array( |
|
| 495 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 496 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 497 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 498 | - ), |
|
| 499 | - 'EE_Message_Factory' => array( |
|
| 500 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 501 | - ), |
|
| 502 | - 'EE_messages' => array( |
|
| 503 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 504 | - ), |
|
| 505 | - 'EE_Messages_Generator' => array( |
|
| 506 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 507 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 508 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 509 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 510 | - ), |
|
| 511 | - 'EE_Messages_Processor' => array( |
|
| 512 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 513 | - ), |
|
| 514 | - 'EE_Messages_Queue' => array( |
|
| 515 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 516 | - ), |
|
| 517 | - 'EE_Messages_Template_Defaults' => array( |
|
| 518 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 519 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 520 | - ), |
|
| 521 | - 'EE_Message_To_Generate_From_Request' => array( |
|
| 522 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 523 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 524 | - ), |
|
| 525 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 526 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 527 | - ), |
|
| 528 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 529 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 530 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 531 | - ), |
|
| 532 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 533 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 534 | - ), |
|
| 535 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 536 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 537 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 538 | - ), |
|
| 539 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 540 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 541 | - ), |
|
| 542 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 543 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 544 | - ), |
|
| 545 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 546 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 547 | - ), |
|
| 548 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 549 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 550 | - ), |
|
| 551 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 552 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 553 | - ), |
|
| 554 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 555 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 556 | - ), |
|
| 557 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 558 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 559 | - ), |
|
| 560 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 561 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 562 | - ), |
|
| 563 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 564 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 565 | - ), |
|
| 566 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 567 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 568 | - ), |
|
| 569 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 570 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 571 | - ), |
|
| 572 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 573 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 574 | - ), |
|
| 575 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
| 576 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 577 | - ), |
|
| 578 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
| 579 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 580 | - ), |
|
| 581 | - 'EE_Data_Migration_Class_Base' => array( |
|
| 582 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 583 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 584 | - ), |
|
| 585 | - 'EE_DMS_Core_4_1_0' => array( |
|
| 586 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 587 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 588 | - ), |
|
| 589 | - 'EE_DMS_Core_4_2_0' => array( |
|
| 590 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 591 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 592 | - ), |
|
| 593 | - 'EE_DMS_Core_4_3_0' => array( |
|
| 594 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 595 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 596 | - ), |
|
| 597 | - 'EE_DMS_Core_4_4_0' => array( |
|
| 598 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 599 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 600 | - ), |
|
| 601 | - 'EE_DMS_Core_4_5_0' => array( |
|
| 602 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 603 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 604 | - ), |
|
| 605 | - 'EE_DMS_Core_4_6_0' => array( |
|
| 606 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 607 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 608 | - ), |
|
| 609 | - 'EE_DMS_Core_4_7_0' => array( |
|
| 610 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 611 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 612 | - ), |
|
| 613 | - 'EE_DMS_Core_4_8_0' => array( |
|
| 614 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 615 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 616 | - ), |
|
| 617 | - 'EE_DMS_Core_4_9_0' => array( |
|
| 618 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 619 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 620 | - ), |
|
| 621 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
| 622 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 623 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 624 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
| 625 | - ), |
|
| 626 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 627 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 628 | - ), |
|
| 629 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 630 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 631 | - ), |
|
| 632 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 633 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 634 | - ), |
|
| 635 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 636 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 637 | - ), |
|
| 638 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 639 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 640 | - ), |
|
| 641 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 642 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 643 | - ), |
|
| 644 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 645 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 646 | - ), |
|
| 647 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 648 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 649 | - ), |
|
| 650 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 651 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 652 | - ), |
|
| 653 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
| 654 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 655 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 656 | - ), |
|
| 657 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
| 658 | - null, |
|
| 659 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 660 | - ), |
|
| 661 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
| 662 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 663 | - ), |
|
| 664 | - 'LEGACY_MODELS' => array( |
|
| 665 | - null, |
|
| 666 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 667 | - ), |
|
| 668 | - 'EE_Module_Request_Router' => array( |
|
| 669 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 670 | - ), |
|
| 671 | - 'EE_Registration_Processor' => array( |
|
| 672 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 673 | - ), |
|
| 674 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
| 675 | - null, |
|
| 676 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 677 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 678 | - ), |
|
| 679 | - 'EE_Admin_Transactions_List_Table' => array( |
|
| 680 | - null, |
|
| 681 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
| 682 | - ), |
|
| 683 | - ); |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * Registers how core classes are loaded. |
|
| 690 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 691 | - * 'EE_Request_Handler' => 'load_core' |
|
| 692 | - * 'EE_Messages_Queue' => 'load_lib' |
|
| 693 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
| 694 | - * or, if greater control is required, by providing a custom closure. For example: |
|
| 695 | - * 'Some_Class' => function () { |
|
| 696 | - * return new Some_Class(); |
|
| 697 | - * }, |
|
| 698 | - * This is required for instantiating dependencies |
|
| 699 | - * where an interface has been type hinted in a class constructor. For example: |
|
| 700 | - * 'Required_Interface' => function () { |
|
| 701 | - * return new A_Class_That_Implements_Required_Interface(); |
|
| 702 | - * }, |
|
| 703 | - * |
|
| 704 | - * @throws InvalidInterfaceException |
|
| 705 | - * @throws InvalidDataTypeException |
|
| 706 | - * @throws InvalidArgumentException |
|
| 707 | - */ |
|
| 708 | - protected function _register_core_class_loaders() |
|
| 709 | - { |
|
| 710 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 711 | - //be used in a closure. |
|
| 712 | - $request = &$this->request; |
|
| 713 | - $response = &$this->response; |
|
| 714 | - $legacy_request = &$this->legacy_request; |
|
| 715 | - // $loader = &$this->loader; |
|
| 716 | - $this->_class_loaders = array( |
|
| 717 | - //load_core |
|
| 718 | - 'EE_Capabilities' => 'load_core', |
|
| 719 | - 'EE_Encryption' => 'load_core', |
|
| 720 | - 'EE_Front_Controller' => 'load_core', |
|
| 721 | - 'EE_Module_Request_Router' => 'load_core', |
|
| 722 | - 'EE_Registry' => 'load_core', |
|
| 723 | - 'EE_Request' => function () use (&$legacy_request) { |
|
| 724 | - return $legacy_request; |
|
| 725 | - }, |
|
| 726 | - 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
| 727 | - return $request; |
|
| 728 | - }, |
|
| 729 | - 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
| 730 | - return $response; |
|
| 731 | - }, |
|
| 732 | - 'EE_Request_Handler' => 'load_core', |
|
| 733 | - 'EE_Session' => 'load_core', |
|
| 734 | - 'EE_Cron_Tasks' => 'load_core', |
|
| 735 | - 'EE_System' => 'load_core', |
|
| 736 | - 'EE_Maintenance_Mode' => 'load_core', |
|
| 737 | - 'EE_Register_CPTs' => 'load_core', |
|
| 738 | - 'EE_Admin' => 'load_core', |
|
| 739 | - //load_lib |
|
| 740 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 741 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
| 742 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 743 | - 'EE_Messenger_Collection' => 'load_lib', |
|
| 744 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 745 | - 'EE_Messages_Processor' => 'load_lib', |
|
| 746 | - 'EE_Message_Repository' => 'load_lib', |
|
| 747 | - 'EE_Messages_Queue' => 'load_lib', |
|
| 748 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 749 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 750 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 751 | - 'EE_Messages_Generator' => function () { |
|
| 752 | - return EE_Registry::instance()->load_lib( |
|
| 753 | - 'Messages_Generator', |
|
| 754 | - array(), |
|
| 755 | - false, |
|
| 756 | - false |
|
| 757 | - ); |
|
| 758 | - }, |
|
| 759 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 760 | - return EE_Registry::instance()->load_lib( |
|
| 761 | - 'Messages_Template_Defaults', |
|
| 762 | - $arguments, |
|
| 763 | - false, |
|
| 764 | - false |
|
| 765 | - ); |
|
| 766 | - }, |
|
| 767 | - //load_model |
|
| 768 | - // 'EEM_Attendee' => 'load_model', |
|
| 769 | - // 'EEM_Message_Template_Group' => 'load_model', |
|
| 770 | - // 'EEM_Message_Template' => 'load_model', |
|
| 771 | - //load_helper |
|
| 772 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 773 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 774 | - return new EEH_Parse_Shortcodes(); |
|
| 775 | - } |
|
| 776 | - return null; |
|
| 777 | - }, |
|
| 778 | - 'EE_Template_Config' => function () { |
|
| 779 | - return EE_Config::instance()->template_settings; |
|
| 780 | - }, |
|
| 781 | - 'EE_Currency_Config' => function () { |
|
| 782 | - return EE_Config::instance()->currency; |
|
| 783 | - }, |
|
| 784 | - 'EE_Registration_Config' => function () { |
|
| 785 | - return EE_Config::instance()->registration; |
|
| 786 | - }, |
|
| 787 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 788 | - return LoaderFactory::getLoader(); |
|
| 789 | - }, |
|
| 790 | - ); |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - |
|
| 794 | - |
|
| 795 | - /** |
|
| 796 | - * can be used for supplying alternate names for classes, |
|
| 797 | - * or for connecting interface names to instantiable classes |
|
| 798 | - */ |
|
| 799 | - protected function _register_core_aliases() |
|
| 800 | - { |
|
| 801 | - $this->_aliases = array( |
|
| 802 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 803 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 804 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 805 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 806 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 807 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 808 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 809 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 810 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 811 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 812 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 813 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 814 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 815 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 816 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 817 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 818 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 819 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 820 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 821 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 822 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 823 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 824 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 825 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 826 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 827 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 828 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 829 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 830 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 831 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 832 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
| 833 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 834 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 835 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 836 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 837 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 838 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 839 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
| 840 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
| 841 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
| 842 | - ); |
|
| 843 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 844 | - $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
|
| 845 | - } |
|
| 846 | - } |
|
| 847 | - |
|
| 848 | - |
|
| 849 | - |
|
| 850 | - /** |
|
| 851 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 852 | - * request Primarily used by unit tests. |
|
| 853 | - * |
|
| 854 | - * @throws InvalidDataTypeException |
|
| 855 | - * @throws InvalidInterfaceException |
|
| 856 | - * @throws InvalidArgumentException |
|
| 857 | - */ |
|
| 858 | - public function reset() |
|
| 859 | - { |
|
| 860 | - $this->_register_core_class_loaders(); |
|
| 861 | - $this->_register_core_dependencies(); |
|
| 862 | - } |
|
| 28 | + /** |
|
| 29 | + * This means that the requested class dependency is not present in the dependency map |
|
| 30 | + */ |
|
| 31 | + const not_registered = 0; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 35 | + */ |
|
| 36 | + const load_new_object = 1; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 40 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 41 | + */ |
|
| 42 | + const load_from_cache = 2; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * When registering a dependency, |
|
| 46 | + * this indicates to keep any existing dependencies that already exist, |
|
| 47 | + * and simply discard any new dependencies declared in the incoming data |
|
| 48 | + */ |
|
| 49 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * When registering a dependency, |
|
| 53 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 54 | + */ |
|
| 55 | + const OVERWRITE_DEPENDENCIES = 1; |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @type EE_Dependency_Map $_instance |
|
| 61 | + */ |
|
| 62 | + protected static $_instance; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @type RequestInterface $request |
|
| 66 | + */ |
|
| 67 | + protected $request; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @type LegacyRequestInterface $legacy_request |
|
| 71 | + */ |
|
| 72 | + protected $legacy_request; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @type ResponseInterface $response |
|
| 76 | + */ |
|
| 77 | + protected $response; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @type LoaderInterface $loader |
|
| 81 | + */ |
|
| 82 | + protected $loader; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @type array $_dependency_map |
|
| 86 | + */ |
|
| 87 | + protected $_dependency_map = array(); |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @type array $_class_loaders |
|
| 91 | + */ |
|
| 92 | + protected $_class_loaders = array(); |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @type array $_aliases |
|
| 96 | + */ |
|
| 97 | + protected $_aliases = array(); |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * EE_Dependency_Map constructor. |
|
| 103 | + */ |
|
| 104 | + protected function __construct() |
|
| 105 | + { |
|
| 106 | + // add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 107 | + do_action('EE_Dependency_Map____construct'); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @throws InvalidDataTypeException |
|
| 114 | + * @throws InvalidInterfaceException |
|
| 115 | + * @throws InvalidArgumentException |
|
| 116 | + */ |
|
| 117 | + public function initialize() |
|
| 118 | + { |
|
| 119 | + $this->_register_core_dependencies(); |
|
| 120 | + $this->_register_core_class_loaders(); |
|
| 121 | + $this->_register_core_aliases(); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @singleton method used to instantiate class object |
|
| 128 | + * @return EE_Dependency_Map |
|
| 129 | + */ |
|
| 130 | + public static function instance() { |
|
| 131 | + // check if class object is instantiated, and instantiated properly |
|
| 132 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 133 | + self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/); |
|
| 134 | + } |
|
| 135 | + return self::$_instance; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param RequestInterface $request |
|
| 141 | + */ |
|
| 142 | + public function setRequest(RequestInterface $request) |
|
| 143 | + { |
|
| 144 | + $this->request = $request; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @param LegacyRequestInterface $legacy_request |
|
| 150 | + */ |
|
| 151 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
| 152 | + { |
|
| 153 | + $this->legacy_request = $legacy_request; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @param ResponseInterface $response |
|
| 159 | + */ |
|
| 160 | + public function setResponse(ResponseInterface $response) |
|
| 161 | + { |
|
| 162 | + $this->response = $response; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @param LoaderInterface $loader |
|
| 169 | + */ |
|
| 170 | + public function setLoader(LoaderInterface $loader) |
|
| 171 | + { |
|
| 172 | + $this->loader = $loader; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @param string $class |
|
| 179 | + * @param array $dependencies |
|
| 180 | + * @param int $overwrite |
|
| 181 | + * @return bool |
|
| 182 | + */ |
|
| 183 | + public static function register_dependencies( |
|
| 184 | + $class, |
|
| 185 | + array $dependencies, |
|
| 186 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 187 | + ) { |
|
| 188 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 195 | + * to the class specified by the first parameter. |
|
| 196 | + * IMPORTANT !!! |
|
| 197 | + * The order of elements in the incoming $dependencies array MUST match |
|
| 198 | + * the order of the constructor parameters for the class in question. |
|
| 199 | + * This is especially important when overriding any existing dependencies that are registered. |
|
| 200 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 201 | + * |
|
| 202 | + * @param string $class |
|
| 203 | + * @param array $dependencies |
|
| 204 | + * @param int $overwrite |
|
| 205 | + * @return bool |
|
| 206 | + */ |
|
| 207 | + public function registerDependencies( |
|
| 208 | + $class, |
|
| 209 | + array $dependencies, |
|
| 210 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 211 | + ) { |
|
| 212 | + $class = trim($class, '\\'); |
|
| 213 | + $registered = false; |
|
| 214 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 215 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
| 216 | + } |
|
| 217 | + // we need to make sure that any aliases used when registering a dependency |
|
| 218 | + // get resolved to the correct class name |
|
| 219 | + foreach ($dependencies as $dependency => $load_source) { |
|
| 220 | + $alias = self::$_instance->get_alias($dependency); |
|
| 221 | + if ( |
|
| 222 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 223 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 224 | + ) { |
|
| 225 | + unset($dependencies[$dependency]); |
|
| 226 | + $dependencies[$alias] = $load_source; |
|
| 227 | + $registered = true; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + // now add our two lists of dependencies together. |
|
| 231 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
| 232 | + // so $dependencies is NOT overwritten because it is listed first |
|
| 233 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 234 | + // Union is way faster than array_merge() but should be used with caution... |
|
| 235 | + // especially with numerically indexed arrays |
|
| 236 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 237 | + // now we need to ensure that the resulting dependencies |
|
| 238 | + // array only has the entries that are required for the class |
|
| 239 | + // so first count how many dependencies were originally registered for the class |
|
| 240 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 241 | + // if that count is non-zero (meaning dependencies were already registered) |
|
| 242 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 243 | + // then truncate the final array to match that count |
|
| 244 | + ? array_slice($dependencies, 0, $dependency_count) |
|
| 245 | + // otherwise just take the incoming array because nothing previously existed |
|
| 246 | + : $dependencies; |
|
| 247 | + return $registered; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * @param string $class_name |
|
| 254 | + * @param string $loader |
|
| 255 | + * @return bool |
|
| 256 | + * @throws DomainException |
|
| 257 | + */ |
|
| 258 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 259 | + { |
|
| 260 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 261 | + throw new DomainException( |
|
| 262 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 263 | + ); |
|
| 264 | + } |
|
| 265 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 266 | + if ( |
|
| 267 | + ! is_callable($loader) |
|
| 268 | + && ( |
|
| 269 | + strpos($loader, 'load_') !== 0 |
|
| 270 | + || ! method_exists('EE_Registry', $loader) |
|
| 271 | + ) |
|
| 272 | + ) { |
|
| 273 | + throw new DomainException( |
|
| 274 | + sprintf( |
|
| 275 | + esc_html__( |
|
| 276 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 277 | + 'event_espresso' |
|
| 278 | + ), |
|
| 279 | + $loader |
|
| 280 | + ) |
|
| 281 | + ); |
|
| 282 | + } |
|
| 283 | + $class_name = self::$_instance->get_alias($class_name); |
|
| 284 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 285 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 286 | + return true; |
|
| 287 | + } |
|
| 288 | + return false; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * @return array |
|
| 295 | + */ |
|
| 296 | + public function dependency_map() |
|
| 297 | + { |
|
| 298 | + return $this->_dependency_map; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
| 305 | + * |
|
| 306 | + * @param string $class_name |
|
| 307 | + * @return boolean |
|
| 308 | + */ |
|
| 309 | + public function has($class_name = '') |
|
| 310 | + { |
|
| 311 | + // all legacy models have the same dependencies |
|
| 312 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 313 | + $class_name = 'LEGACY_MODELS'; |
|
| 314 | + } |
|
| 315 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 322 | + * |
|
| 323 | + * @param string $class_name |
|
| 324 | + * @param string $dependency |
|
| 325 | + * @return bool |
|
| 326 | + */ |
|
| 327 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 328 | + { |
|
| 329 | + // all legacy models have the same dependencies |
|
| 330 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 331 | + $class_name = 'LEGACY_MODELS'; |
|
| 332 | + } |
|
| 333 | + $dependency = $this->get_alias($dependency); |
|
| 334 | + return isset($this->_dependency_map[$class_name][$dependency]) |
|
| 335 | + ? true |
|
| 336 | + : false; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 343 | + * |
|
| 344 | + * @param string $class_name |
|
| 345 | + * @param string $dependency |
|
| 346 | + * @return int |
|
| 347 | + */ |
|
| 348 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 349 | + { |
|
| 350 | + // all legacy models have the same dependencies |
|
| 351 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 352 | + $class_name = 'LEGACY_MODELS'; |
|
| 353 | + } |
|
| 354 | + $dependency = $this->get_alias($dependency); |
|
| 355 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
| 356 | + ? $this->_dependency_map[$class_name][$dependency] |
|
| 357 | + : EE_Dependency_Map::not_registered; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * @param string $class_name |
|
| 364 | + * @return string | Closure |
|
| 365 | + */ |
|
| 366 | + public function class_loader($class_name) |
|
| 367 | + { |
|
| 368 | + // all legacy models use load_model() |
|
| 369 | + if(strpos($class_name, 'EEM_') === 0){ |
|
| 370 | + return 'load_model'; |
|
| 371 | + } |
|
| 372 | + $class_name = $this->get_alias($class_name); |
|
| 373 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * @return array |
|
| 380 | + */ |
|
| 381 | + public function class_loaders() |
|
| 382 | + { |
|
| 383 | + return $this->_class_loaders; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * adds an alias for a classname |
|
| 390 | + * |
|
| 391 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 392 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 393 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 394 | + */ |
|
| 395 | + public function add_alias($class_name, $alias, $for_class = '') |
|
| 396 | + { |
|
| 397 | + if ($for_class !== '') { |
|
| 398 | + if (! isset($this->_aliases[$for_class])) { |
|
| 399 | + $this->_aliases[$for_class] = array(); |
|
| 400 | + } |
|
| 401 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
| 402 | + } |
|
| 403 | + $this->_aliases[$class_name] = $alias; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * returns TRUE if the provided class name has an alias |
|
| 410 | + * |
|
| 411 | + * @param string $class_name |
|
| 412 | + * @param string $for_class |
|
| 413 | + * @return bool |
|
| 414 | + */ |
|
| 415 | + public function has_alias($class_name = '', $for_class = '') |
|
| 416 | + { |
|
| 417 | + return isset($this->_aliases[$for_class][$class_name]) |
|
| 418 | + || ( |
|
| 419 | + isset($this->_aliases[$class_name]) |
|
| 420 | + && ! is_array($this->_aliases[$class_name]) |
|
| 421 | + ); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
| 428 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 429 | + * for example: |
|
| 430 | + * if the following two entries were added to the _aliases array: |
|
| 431 | + * array( |
|
| 432 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 433 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 434 | + * ) |
|
| 435 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 436 | + * to load an instance of 'some\namespace\classname' |
|
| 437 | + * |
|
| 438 | + * @param string $class_name |
|
| 439 | + * @param string $for_class |
|
| 440 | + * @return string |
|
| 441 | + */ |
|
| 442 | + public function get_alias($class_name = '', $for_class = '') |
|
| 443 | + { |
|
| 444 | + if (! $this->has_alias($class_name, $for_class)) { |
|
| 445 | + return $class_name; |
|
| 446 | + } |
|
| 447 | + if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 448 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 449 | + } |
|
| 450 | + return $this->get_alias($this->_aliases[$class_name]); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 457 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 458 | + * This is done by using the following class constants: |
|
| 459 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 460 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 461 | + */ |
|
| 462 | + protected function _register_core_dependencies() |
|
| 463 | + { |
|
| 464 | + $this->_dependency_map = array( |
|
| 465 | + 'EE_Request_Handler' => array( |
|
| 466 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 467 | + ), |
|
| 468 | + 'EE_System' => array( |
|
| 469 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 470 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 471 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 472 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 473 | + ), |
|
| 474 | + 'EE_Session' => array( |
|
| 475 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 476 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
| 477 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 478 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 479 | + ), |
|
| 480 | + 'EE_Cart' => array( |
|
| 481 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 482 | + ), |
|
| 483 | + 'EE_Front_Controller' => array( |
|
| 484 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 485 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 486 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 487 | + ), |
|
| 488 | + 'EE_Messenger_Collection_Loader' => array( |
|
| 489 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 490 | + ), |
|
| 491 | + 'EE_Message_Type_Collection_Loader' => array( |
|
| 492 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 493 | + ), |
|
| 494 | + 'EE_Message_Resource_Manager' => array( |
|
| 495 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 496 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 497 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 498 | + ), |
|
| 499 | + 'EE_Message_Factory' => array( |
|
| 500 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 501 | + ), |
|
| 502 | + 'EE_messages' => array( |
|
| 503 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 504 | + ), |
|
| 505 | + 'EE_Messages_Generator' => array( |
|
| 506 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 507 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 508 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 509 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 510 | + ), |
|
| 511 | + 'EE_Messages_Processor' => array( |
|
| 512 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 513 | + ), |
|
| 514 | + 'EE_Messages_Queue' => array( |
|
| 515 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 516 | + ), |
|
| 517 | + 'EE_Messages_Template_Defaults' => array( |
|
| 518 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 519 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 520 | + ), |
|
| 521 | + 'EE_Message_To_Generate_From_Request' => array( |
|
| 522 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 523 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 524 | + ), |
|
| 525 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 526 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 527 | + ), |
|
| 528 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 529 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 530 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 531 | + ), |
|
| 532 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 533 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 534 | + ), |
|
| 535 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 536 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 537 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 538 | + ), |
|
| 539 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 540 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 541 | + ), |
|
| 542 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 543 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 544 | + ), |
|
| 545 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 546 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 547 | + ), |
|
| 548 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 549 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 550 | + ), |
|
| 551 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 552 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 553 | + ), |
|
| 554 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 555 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 556 | + ), |
|
| 557 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 558 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 559 | + ), |
|
| 560 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 561 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 562 | + ), |
|
| 563 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 564 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 565 | + ), |
|
| 566 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 567 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 568 | + ), |
|
| 569 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 570 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 571 | + ), |
|
| 572 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 573 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 574 | + ), |
|
| 575 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
| 576 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 577 | + ), |
|
| 578 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
| 579 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 580 | + ), |
|
| 581 | + 'EE_Data_Migration_Class_Base' => array( |
|
| 582 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 583 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 584 | + ), |
|
| 585 | + 'EE_DMS_Core_4_1_0' => array( |
|
| 586 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 587 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 588 | + ), |
|
| 589 | + 'EE_DMS_Core_4_2_0' => array( |
|
| 590 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 591 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 592 | + ), |
|
| 593 | + 'EE_DMS_Core_4_3_0' => array( |
|
| 594 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 595 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 596 | + ), |
|
| 597 | + 'EE_DMS_Core_4_4_0' => array( |
|
| 598 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 599 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 600 | + ), |
|
| 601 | + 'EE_DMS_Core_4_5_0' => array( |
|
| 602 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 603 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 604 | + ), |
|
| 605 | + 'EE_DMS_Core_4_6_0' => array( |
|
| 606 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 607 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 608 | + ), |
|
| 609 | + 'EE_DMS_Core_4_7_0' => array( |
|
| 610 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 611 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 612 | + ), |
|
| 613 | + 'EE_DMS_Core_4_8_0' => array( |
|
| 614 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 615 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 616 | + ), |
|
| 617 | + 'EE_DMS_Core_4_9_0' => array( |
|
| 618 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 619 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 620 | + ), |
|
| 621 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
| 622 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 623 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 624 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
| 625 | + ), |
|
| 626 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 627 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 628 | + ), |
|
| 629 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 630 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 631 | + ), |
|
| 632 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 633 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 634 | + ), |
|
| 635 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 636 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 637 | + ), |
|
| 638 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 639 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 640 | + ), |
|
| 641 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 642 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 643 | + ), |
|
| 644 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 645 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 646 | + ), |
|
| 647 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 648 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 649 | + ), |
|
| 650 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 651 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 652 | + ), |
|
| 653 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
| 654 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 655 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 656 | + ), |
|
| 657 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
| 658 | + null, |
|
| 659 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 660 | + ), |
|
| 661 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
| 662 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 663 | + ), |
|
| 664 | + 'LEGACY_MODELS' => array( |
|
| 665 | + null, |
|
| 666 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 667 | + ), |
|
| 668 | + 'EE_Module_Request_Router' => array( |
|
| 669 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 670 | + ), |
|
| 671 | + 'EE_Registration_Processor' => array( |
|
| 672 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 673 | + ), |
|
| 674 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
| 675 | + null, |
|
| 676 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 677 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 678 | + ), |
|
| 679 | + 'EE_Admin_Transactions_List_Table' => array( |
|
| 680 | + null, |
|
| 681 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
| 682 | + ), |
|
| 683 | + ); |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * Registers how core classes are loaded. |
|
| 690 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 691 | + * 'EE_Request_Handler' => 'load_core' |
|
| 692 | + * 'EE_Messages_Queue' => 'load_lib' |
|
| 693 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
| 694 | + * or, if greater control is required, by providing a custom closure. For example: |
|
| 695 | + * 'Some_Class' => function () { |
|
| 696 | + * return new Some_Class(); |
|
| 697 | + * }, |
|
| 698 | + * This is required for instantiating dependencies |
|
| 699 | + * where an interface has been type hinted in a class constructor. For example: |
|
| 700 | + * 'Required_Interface' => function () { |
|
| 701 | + * return new A_Class_That_Implements_Required_Interface(); |
|
| 702 | + * }, |
|
| 703 | + * |
|
| 704 | + * @throws InvalidInterfaceException |
|
| 705 | + * @throws InvalidDataTypeException |
|
| 706 | + * @throws InvalidArgumentException |
|
| 707 | + */ |
|
| 708 | + protected function _register_core_class_loaders() |
|
| 709 | + { |
|
| 710 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 711 | + //be used in a closure. |
|
| 712 | + $request = &$this->request; |
|
| 713 | + $response = &$this->response; |
|
| 714 | + $legacy_request = &$this->legacy_request; |
|
| 715 | + // $loader = &$this->loader; |
|
| 716 | + $this->_class_loaders = array( |
|
| 717 | + //load_core |
|
| 718 | + 'EE_Capabilities' => 'load_core', |
|
| 719 | + 'EE_Encryption' => 'load_core', |
|
| 720 | + 'EE_Front_Controller' => 'load_core', |
|
| 721 | + 'EE_Module_Request_Router' => 'load_core', |
|
| 722 | + 'EE_Registry' => 'load_core', |
|
| 723 | + 'EE_Request' => function () use (&$legacy_request) { |
|
| 724 | + return $legacy_request; |
|
| 725 | + }, |
|
| 726 | + 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
| 727 | + return $request; |
|
| 728 | + }, |
|
| 729 | + 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
| 730 | + return $response; |
|
| 731 | + }, |
|
| 732 | + 'EE_Request_Handler' => 'load_core', |
|
| 733 | + 'EE_Session' => 'load_core', |
|
| 734 | + 'EE_Cron_Tasks' => 'load_core', |
|
| 735 | + 'EE_System' => 'load_core', |
|
| 736 | + 'EE_Maintenance_Mode' => 'load_core', |
|
| 737 | + 'EE_Register_CPTs' => 'load_core', |
|
| 738 | + 'EE_Admin' => 'load_core', |
|
| 739 | + //load_lib |
|
| 740 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 741 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
| 742 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 743 | + 'EE_Messenger_Collection' => 'load_lib', |
|
| 744 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 745 | + 'EE_Messages_Processor' => 'load_lib', |
|
| 746 | + 'EE_Message_Repository' => 'load_lib', |
|
| 747 | + 'EE_Messages_Queue' => 'load_lib', |
|
| 748 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 749 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 750 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 751 | + 'EE_Messages_Generator' => function () { |
|
| 752 | + return EE_Registry::instance()->load_lib( |
|
| 753 | + 'Messages_Generator', |
|
| 754 | + array(), |
|
| 755 | + false, |
|
| 756 | + false |
|
| 757 | + ); |
|
| 758 | + }, |
|
| 759 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 760 | + return EE_Registry::instance()->load_lib( |
|
| 761 | + 'Messages_Template_Defaults', |
|
| 762 | + $arguments, |
|
| 763 | + false, |
|
| 764 | + false |
|
| 765 | + ); |
|
| 766 | + }, |
|
| 767 | + //load_model |
|
| 768 | + // 'EEM_Attendee' => 'load_model', |
|
| 769 | + // 'EEM_Message_Template_Group' => 'load_model', |
|
| 770 | + // 'EEM_Message_Template' => 'load_model', |
|
| 771 | + //load_helper |
|
| 772 | + 'EEH_Parse_Shortcodes' => function () { |
|
| 773 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 774 | + return new EEH_Parse_Shortcodes(); |
|
| 775 | + } |
|
| 776 | + return null; |
|
| 777 | + }, |
|
| 778 | + 'EE_Template_Config' => function () { |
|
| 779 | + return EE_Config::instance()->template_settings; |
|
| 780 | + }, |
|
| 781 | + 'EE_Currency_Config' => function () { |
|
| 782 | + return EE_Config::instance()->currency; |
|
| 783 | + }, |
|
| 784 | + 'EE_Registration_Config' => function () { |
|
| 785 | + return EE_Config::instance()->registration; |
|
| 786 | + }, |
|
| 787 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 788 | + return LoaderFactory::getLoader(); |
|
| 789 | + }, |
|
| 790 | + ); |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + |
|
| 794 | + |
|
| 795 | + /** |
|
| 796 | + * can be used for supplying alternate names for classes, |
|
| 797 | + * or for connecting interface names to instantiable classes |
|
| 798 | + */ |
|
| 799 | + protected function _register_core_aliases() |
|
| 800 | + { |
|
| 801 | + $this->_aliases = array( |
|
| 802 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 803 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 804 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 805 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 806 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 807 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 808 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 809 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 810 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 811 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 812 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 813 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 814 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 815 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 816 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 817 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 818 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 819 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 820 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 821 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 822 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 823 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 824 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 825 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 826 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 827 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 828 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 829 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 830 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 831 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 832 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
| 833 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 834 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 835 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 836 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 837 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 838 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 839 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
| 840 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
| 841 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
| 842 | + ); |
|
| 843 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 844 | + $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
|
| 845 | + } |
|
| 846 | + } |
|
| 847 | + |
|
| 848 | + |
|
| 849 | + |
|
| 850 | + /** |
|
| 851 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 852 | + * request Primarily used by unit tests. |
|
| 853 | + * |
|
| 854 | + * @throws InvalidDataTypeException |
|
| 855 | + * @throws InvalidInterfaceException |
|
| 856 | + * @throws InvalidArgumentException |
|
| 857 | + */ |
|
| 858 | + public function reset() |
|
| 859 | + { |
|
| 860 | + $this->_register_core_class_loaders(); |
|
| 861 | + $this->_register_core_dependencies(); |
|
| 862 | + } |
|
| 863 | 863 | |
| 864 | 864 | |
| 865 | 865 | } |
@@ -19,33 +19,33 @@ |
||
| 19 | 19 | class InvalidRequestStackMiddlewareException extends InvalidDataTypeException |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @param mixed $middleware_app_class |
|
| 24 | - * @param string $message |
|
| 25 | - * @param int $code |
|
| 26 | - * @param Exception $previous |
|
| 27 | - */ |
|
| 28 | - public function __construct($middleware_app_class, $message = '', $code = 0, Exception $previous = null) |
|
| 29 | - { |
|
| 30 | - if(is_array($middleware_app_class)) { |
|
| 31 | - $middleware_app_class = reset($middleware_app_class); |
|
| 32 | - } |
|
| 33 | - if (empty($message)) { |
|
| 34 | - $message = sprintf( |
|
| 35 | - esc_html__( |
|
| 36 | - 'The supplied Request Stack Middleware class "%1$s" is invalid or could no be found.', |
|
| 37 | - 'event_espresso' |
|
| 38 | - ), |
|
| 39 | - $middleware_app_class |
|
| 40 | - ); |
|
| 41 | - } |
|
| 42 | - parent::__construct( |
|
| 43 | - '$middleware_app_class', |
|
| 44 | - $middleware_app_class, |
|
| 45 | - 'EventEspresso\core\services\request\middleware\Middleware', |
|
| 46 | - $message, |
|
| 47 | - $code, |
|
| 48 | - $previous |
|
| 49 | - ); |
|
| 50 | - } |
|
| 22 | + /** |
|
| 23 | + * @param mixed $middleware_app_class |
|
| 24 | + * @param string $message |
|
| 25 | + * @param int $code |
|
| 26 | + * @param Exception $previous |
|
| 27 | + */ |
|
| 28 | + public function __construct($middleware_app_class, $message = '', $code = 0, Exception $previous = null) |
|
| 29 | + { |
|
| 30 | + if(is_array($middleware_app_class)) { |
|
| 31 | + $middleware_app_class = reset($middleware_app_class); |
|
| 32 | + } |
|
| 33 | + if (empty($message)) { |
|
| 34 | + $message = sprintf( |
|
| 35 | + esc_html__( |
|
| 36 | + 'The supplied Request Stack Middleware class "%1$s" is invalid or could no be found.', |
|
| 37 | + 'event_espresso' |
|
| 38 | + ), |
|
| 39 | + $middleware_app_class |
|
| 40 | + ); |
|
| 41 | + } |
|
| 42 | + parent::__construct( |
|
| 43 | + '$middleware_app_class', |
|
| 44 | + $middleware_app_class, |
|
| 45 | + 'EventEspresso\core\services\request\middleware\Middleware', |
|
| 46 | + $message, |
|
| 47 | + $code, |
|
| 48 | + $previous |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | public function __construct($middleware_app_class, $message = '', $code = 0, Exception $previous = null) |
| 29 | 29 | { |
| 30 | - if(is_array($middleware_app_class)) { |
|
| 30 | + if (is_array($middleware_app_class)) { |
|
| 31 | 31 | $middleware_app_class = reset($middleware_app_class); |
| 32 | 32 | } |
| 33 | 33 | if (empty($message)) { |
@@ -24,97 +24,97 @@ |
||
| 24 | 24 | class RequestStackBuilder extends SplDoublyLinkedList |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @type LoaderInterface $loader |
|
| 29 | - */ |
|
| 30 | - private $loader; |
|
| 27 | + /** |
|
| 28 | + * @type LoaderInterface $loader |
|
| 29 | + */ |
|
| 30 | + private $loader; |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * RequestStackBuilder constructor. |
|
| 35 | - * |
|
| 36 | - * @param LoaderInterface $loader |
|
| 37 | - */ |
|
| 38 | - public function __construct(LoaderInterface $loader) |
|
| 39 | - { |
|
| 40 | - $this->loader = $loader; |
|
| 41 | - $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 42 | - } |
|
| 33 | + /** |
|
| 34 | + * RequestStackBuilder constructor. |
|
| 35 | + * |
|
| 36 | + * @param LoaderInterface $loader |
|
| 37 | + */ |
|
| 38 | + public function __construct(LoaderInterface $loader) |
|
| 39 | + { |
|
| 40 | + $this->loader = $loader; |
|
| 41 | + $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * builds decorated middleware stack |
|
| 47 | - * by continuously injecting previous middleware app into the next |
|
| 48 | - * |
|
| 49 | - * @param RequestStackCoreAppInterface $application |
|
| 50 | - * @return RequestStack |
|
| 51 | - * @throws Exception |
|
| 52 | - */ |
|
| 53 | - public function resolve(RequestStackCoreAppInterface $application) |
|
| 54 | - { |
|
| 55 | - $core_app = $application; |
|
| 56 | - // NOW... because the RequestStack is following the decorator pattern, |
|
| 57 | - // the first stack app we add will end up at the center of the stack, |
|
| 58 | - // and will end up being the last item to actually run, but we don't want that! |
|
| 59 | - // Basically we're dealing with TWO stacks, and transferring items from one to the other, |
|
| 60 | - // BUT... we want the final stack to be in the same order as the first. |
|
| 61 | - // So we need to reverse the iterator mode when transferring items, |
|
| 62 | - // because if we don't, the second stack will end up in the incorrect order. |
|
| 63 | - $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 64 | - for ($this->rewind(); $this->valid(); $this->next()) { |
|
| 65 | - try { |
|
| 66 | - $middleware_app = $this->validateMiddlewareAppDetails($this->current(), true); |
|
| 67 | - $middleware_app_class = array_shift($middleware_app); |
|
| 68 | - $middleware_app_args = is_array($middleware_app) ? $middleware_app : array(); |
|
| 69 | - $middleware_app_args = array($application, $this->loader) + $middleware_app_args; |
|
| 70 | - $application = $this->loader->getShared($middleware_app_class, $middleware_app_args); |
|
| 71 | - } catch (InvalidRequestStackMiddlewareException $exception) { |
|
| 72 | - if(WP_DEBUG) { |
|
| 73 | - new ExceptionStackTraceDisplay($exception); |
|
| 74 | - continue; |
|
| 75 | - } |
|
| 76 | - error_log($exception->getMessage()); |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - return new RequestStack($application, $core_app); |
|
| 80 | - } |
|
| 45 | + /** |
|
| 46 | + * builds decorated middleware stack |
|
| 47 | + * by continuously injecting previous middleware app into the next |
|
| 48 | + * |
|
| 49 | + * @param RequestStackCoreAppInterface $application |
|
| 50 | + * @return RequestStack |
|
| 51 | + * @throws Exception |
|
| 52 | + */ |
|
| 53 | + public function resolve(RequestStackCoreAppInterface $application) |
|
| 54 | + { |
|
| 55 | + $core_app = $application; |
|
| 56 | + // NOW... because the RequestStack is following the decorator pattern, |
|
| 57 | + // the first stack app we add will end up at the center of the stack, |
|
| 58 | + // and will end up being the last item to actually run, but we don't want that! |
|
| 59 | + // Basically we're dealing with TWO stacks, and transferring items from one to the other, |
|
| 60 | + // BUT... we want the final stack to be in the same order as the first. |
|
| 61 | + // So we need to reverse the iterator mode when transferring items, |
|
| 62 | + // because if we don't, the second stack will end up in the incorrect order. |
|
| 63 | + $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 64 | + for ($this->rewind(); $this->valid(); $this->next()) { |
|
| 65 | + try { |
|
| 66 | + $middleware_app = $this->validateMiddlewareAppDetails($this->current(), true); |
|
| 67 | + $middleware_app_class = array_shift($middleware_app); |
|
| 68 | + $middleware_app_args = is_array($middleware_app) ? $middleware_app : array(); |
|
| 69 | + $middleware_app_args = array($application, $this->loader) + $middleware_app_args; |
|
| 70 | + $application = $this->loader->getShared($middleware_app_class, $middleware_app_args); |
|
| 71 | + } catch (InvalidRequestStackMiddlewareException $exception) { |
|
| 72 | + if(WP_DEBUG) { |
|
| 73 | + new ExceptionStackTraceDisplay($exception); |
|
| 74 | + continue; |
|
| 75 | + } |
|
| 76 | + error_log($exception->getMessage()); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + return new RequestStack($application, $core_app); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Ensures that the app details that have been pushed onto RequestStackBuilder |
|
| 85 | - * are all ordered correctly so that the middleware can be properly constructed |
|
| 86 | - * |
|
| 87 | - * @param array $middleware_app |
|
| 88 | - * @param bool $recurse |
|
| 89 | - * @return array |
|
| 90 | - * @throws InvalidRequestStackMiddlewareException |
|
| 91 | - */ |
|
| 92 | - protected function validateMiddlewareAppDetails(array $middleware_app, $recurse = false) |
|
| 93 | - { |
|
| 94 | - $middleware_app_class = reset($middleware_app); |
|
| 95 | - // is array empty ? |
|
| 96 | - if($middleware_app_class === false) { |
|
| 97 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 98 | - } |
|
| 99 | - // are the class and arguments in the wrong order ? |
|
| 100 | - if(is_array($middleware_app_class)) { |
|
| 101 | - if ($recurse === true) { |
|
| 102 | - return $this->validateMiddlewareAppDetails(array_reverse($middleware_app)); |
|
| 103 | - } |
|
| 104 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 105 | - } |
|
| 106 | - // is filter callback working like legacy middleware and sending a numerically indexed array ? |
|
| 107 | - if(is_int($middleware_app_class)) { |
|
| 108 | - if ($recurse === true) { |
|
| 109 | - $middleware_app = array_reverse($middleware_app); |
|
| 110 | - return $this->validateMiddlewareAppDetails(array(reset($middleware_app), array())); |
|
| 111 | - } |
|
| 112 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 113 | - } |
|
| 114 | - // is $middleware_app_class a valid FQCN (or class is already loaded) ? |
|
| 115 | - if(! class_exists($middleware_app_class)) { |
|
| 116 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 117 | - } |
|
| 118 | - return $middleware_app; |
|
| 119 | - } |
|
| 83 | + /** |
|
| 84 | + * Ensures that the app details that have been pushed onto RequestStackBuilder |
|
| 85 | + * are all ordered correctly so that the middleware can be properly constructed |
|
| 86 | + * |
|
| 87 | + * @param array $middleware_app |
|
| 88 | + * @param bool $recurse |
|
| 89 | + * @return array |
|
| 90 | + * @throws InvalidRequestStackMiddlewareException |
|
| 91 | + */ |
|
| 92 | + protected function validateMiddlewareAppDetails(array $middleware_app, $recurse = false) |
|
| 93 | + { |
|
| 94 | + $middleware_app_class = reset($middleware_app); |
|
| 95 | + // is array empty ? |
|
| 96 | + if($middleware_app_class === false) { |
|
| 97 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 98 | + } |
|
| 99 | + // are the class and arguments in the wrong order ? |
|
| 100 | + if(is_array($middleware_app_class)) { |
|
| 101 | + if ($recurse === true) { |
|
| 102 | + return $this->validateMiddlewareAppDetails(array_reverse($middleware_app)); |
|
| 103 | + } |
|
| 104 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 105 | + } |
|
| 106 | + // is filter callback working like legacy middleware and sending a numerically indexed array ? |
|
| 107 | + if(is_int($middleware_app_class)) { |
|
| 108 | + if ($recurse === true) { |
|
| 109 | + $middleware_app = array_reverse($middleware_app); |
|
| 110 | + return $this->validateMiddlewareAppDetails(array(reset($middleware_app), array())); |
|
| 111 | + } |
|
| 112 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 113 | + } |
|
| 114 | + // is $middleware_app_class a valid FQCN (or class is already loaded) ? |
|
| 115 | + if(! class_exists($middleware_app_class)) { |
|
| 116 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 117 | + } |
|
| 118 | + return $middleware_app; |
|
| 119 | + } |
|
| 120 | 120 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | $middleware_app_args = array($application, $this->loader) + $middleware_app_args; |
| 70 | 70 | $application = $this->loader->getShared($middleware_app_class, $middleware_app_args); |
| 71 | 71 | } catch (InvalidRequestStackMiddlewareException $exception) { |
| 72 | - if(WP_DEBUG) { |
|
| 72 | + if (WP_DEBUG) { |
|
| 73 | 73 | new ExceptionStackTraceDisplay($exception); |
| 74 | 74 | continue; |
| 75 | 75 | } |
@@ -93,18 +93,18 @@ discard block |
||
| 93 | 93 | { |
| 94 | 94 | $middleware_app_class = reset($middleware_app); |
| 95 | 95 | // is array empty ? |
| 96 | - if($middleware_app_class === false) { |
|
| 96 | + if ($middleware_app_class === false) { |
|
| 97 | 97 | throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
| 98 | 98 | } |
| 99 | 99 | // are the class and arguments in the wrong order ? |
| 100 | - if(is_array($middleware_app_class)) { |
|
| 100 | + if (is_array($middleware_app_class)) { |
|
| 101 | 101 | if ($recurse === true) { |
| 102 | 102 | return $this->validateMiddlewareAppDetails(array_reverse($middleware_app)); |
| 103 | 103 | } |
| 104 | 104 | throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
| 105 | 105 | } |
| 106 | 106 | // is filter callback working like legacy middleware and sending a numerically indexed array ? |
| 107 | - if(is_int($middleware_app_class)) { |
|
| 107 | + if (is_int($middleware_app_class)) { |
|
| 108 | 108 | if ($recurse === true) { |
| 109 | 109 | $middleware_app = array_reverse($middleware_app); |
| 110 | 110 | return $this->validateMiddlewareAppDetails(array(reset($middleware_app), array())); |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
| 113 | 113 | } |
| 114 | 114 | // is $middleware_app_class a valid FQCN (or class is already loaded) ? |
| 115 | - if(! class_exists($middleware_app_class)) { |
|
| 115 | + if ( ! class_exists($middleware_app_class)) { |
|
| 116 | 116 | throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
| 117 | 117 | } |
| 118 | 118 | return $middleware_app; |
@@ -16,49 +16,49 @@ |
||
| 16 | 16 | interface DomainInterface extends InterminableInterface |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @return string |
|
| 21 | - * @throws DomainException |
|
| 22 | - */ |
|
| 23 | - public function pluginFile(); |
|
| 19 | + /** |
|
| 20 | + * @return string |
|
| 21 | + * @throws DomainException |
|
| 22 | + */ |
|
| 23 | + public function pluginFile(); |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @return string |
|
| 28 | - * @throws DomainException |
|
| 29 | - */ |
|
| 30 | - public function pluginBasename(); |
|
| 26 | + /** |
|
| 27 | + * @return string |
|
| 28 | + * @throws DomainException |
|
| 29 | + */ |
|
| 30 | + public function pluginBasename(); |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @return string |
|
| 35 | - */ |
|
| 36 | - public function pluginPath(); |
|
| 33 | + /** |
|
| 34 | + * @return string |
|
| 35 | + */ |
|
| 36 | + public function pluginPath(); |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @return string |
|
| 41 | - * @throws DomainException |
|
| 42 | - */ |
|
| 43 | - public function pluginUrl(); |
|
| 39 | + /** |
|
| 40 | + * @return string |
|
| 41 | + * @throws DomainException |
|
| 42 | + */ |
|
| 43 | + public function pluginUrl(); |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @return string |
|
| 48 | - * @throws DomainException |
|
| 49 | - */ |
|
| 50 | - public function version(); |
|
| 46 | + /** |
|
| 47 | + * @return string |
|
| 48 | + * @throws DomainException |
|
| 49 | + */ |
|
| 50 | + public function version(); |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return string |
|
| 55 | - */ |
|
| 56 | - public function distributionAssetsPath(); |
|
| 53 | + /** |
|
| 54 | + * @return string |
|
| 55 | + */ |
|
| 56 | + public function distributionAssetsPath(); |
|
| 57 | 57 | |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @return string |
|
| 61 | - */ |
|
| 62 | - public function distributionAssetsUrl(); |
|
| 59 | + /** |
|
| 60 | + * @return string |
|
| 61 | + */ |
|
| 62 | + public function distributionAssetsUrl(); |
|
| 63 | 63 | |
| 64 | 64 | } |