diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..24d4829 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,513 @@ +# +# Keep all settings active for when ESD moves back into its own project +# +root = true + +[.editorconfig] +ij_formatter_enabled = false + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +max_line_length = 120 +tab_width = 4 +trim_trailing_whitespace = true +# +# IntelliJ extended formatting +# +ij_continuation_indent_size = 4 +ij_formatter_off_tag = @formatter:off +ij_formatter_on_tag = @formatter:on +ij_formatter_tags_enabled = true +ij_smart_tabs = false +ij_visual_guides = 80,120 +ij_wrap_on_typing = true +ij_any_align_group_field_declarations = false +ij_any_align_multiline_array_initializer_expression = false +ij_any_align_multiline_binary_operation = false +ij_any_align_multiline_chained_methods = false +ij_any_align_multiline_extends_list = false +ij_any_align_multiline_for = true +ij_any_align_multiline_parameters = false +ij_any_align_multiline_parameters_in_calls = false +ij_any_align_multiline_ternary_operation = true +ij_any_array_initializer_new_line_after_left_brace = true +ij_any_array_initializer_right_brace_on_new_line = true +ij_any_array_initializer_wrap = on_every_item +ij_any_assignment_wrap = normal +ij_any_binary_operation_sign_on_next_line = true +ij_any_binary_operation_wrap = normal +ij_any_blank_lines_after_class_header = 0 +ij_any_blank_lines_after_imports = 1 +ij_any_blank_lines_after_package = 1 +ij_any_blank_lines_around_class = 1 +ij_any_blank_lines_around_field = 1 +ij_any_blank_lines_around_field_in_interface = 0 +ij_any_blank_lines_around_method = 1 +ij_any_blank_lines_around_method_in_interface = 0 +ij_any_blank_lines_before_class_end = 0 +ij_any_blank_lines_before_imports = 1 +ij_any_blank_lines_before_method_body = 0 +ij_any_blank_lines_before_package = 1 +ij_any_block_brace_style = end_of_line +ij_any_block_comment_add_space = true +ij_any_block_comment_at_first_column = false +ij_any_call_parameters_new_line_after_left_paren = true +ij_any_call_parameters_right_paren_on_new_line = true +ij_any_call_parameters_wrap = on_every_item +ij_any_catch_on_new_line = true +ij_any_class_brace_style = next_line +ij_any_do_while_brace_force = always +ij_any_else_on_new_line = true +ij_any_enum_constants_wrap = on_every_item +ij_any_extends_keyword_wrap = on_every_item +ij_any_extends_list_wrap = on_every_item +ij_any_finally_on_new_line = true +ij_any_for_brace_force = always +ij_any_for_statement_new_line_after_left_paren = false +ij_any_for_statement_right_paren_on_new_line = true +ij_any_for_statement_wrap = on_every_item +ij_any_if_brace_force = always +ij_any_indent_break_from_case = true +ij_any_indent_case_from_switch = true +ij_any_keep_blank_lines_before_right_brace = 0 +ij_any_keep_blank_lines_in_code = 1 +ij_any_keep_blank_lines_in_declarations = 0 +ij_any_keep_control_statement_in_one_line = false +ij_any_keep_first_column_comment = false +ij_any_keep_indents_on_empty_lines = false +ij_any_keep_line_breaks = true +ij_any_keep_simple_blocks_in_one_line = false +ij_any_keep_simple_classes_in_one_line = false +ij_any_keep_simple_methods_in_one_line = false +ij_any_lambda_brace_style = next_line_if_wrapped +ij_any_line_comment_add_space = true +ij_any_line_comment_at_first_column = false +ij_any_method_brace_style = next_line +ij_any_method_call_chain_wrap = on_every_item +ij_any_method_parameters_new_line_after_left_paren = true +ij_any_method_parameters_right_paren_on_new_line = true +ij_any_method_parameters_wrap = on_every_item +ij_any_modifier_list_wrap = false +ij_any_parentheses_expression_new_line_after_left_paren = false +ij_any_parentheses_expression_right_paren_on_new_line = false +ij_any_place_assignment_sign_on_next_line = false +ij_any_prefer_parameters_wrap = false +ij_any_space_after_colon = true +ij_any_space_after_comma = true +ij_any_space_after_for_semicolon = true +ij_any_space_after_quest = false +ij_any_space_after_type_cast = false +ij_any_space_before_array_initializer_left_brace = false +ij_any_space_before_catch_keyword = true +ij_any_space_before_catch_left_brace = true +ij_any_space_before_catch_parentheses = true +ij_any_space_before_class_left_brace = true +ij_any_space_before_colon = true +ij_any_space_before_comma = false +ij_any_space_before_do_left_brace = true +ij_any_space_before_else_keyword = true +ij_any_space_before_else_left_brace = true +ij_any_space_before_finally_keyword = true +ij_any_space_before_finally_left_brace = true +ij_any_space_before_for_left_brace = true +ij_any_space_before_for_parentheses = true +ij_any_space_before_for_semicolon = false +ij_any_space_before_if_left_brace = true +ij_any_space_before_if_parentheses = true +ij_any_space_before_method_call_parentheses = false +ij_any_space_before_method_left_brace = true +ij_any_space_before_method_parentheses = false +ij_any_space_before_quest = true +ij_any_space_before_switch_left_brace = true +ij_any_space_before_switch_parentheses = true +ij_any_space_before_try_left_brace = true +ij_any_space_before_while_keyword = true +ij_any_space_before_while_left_brace = true +ij_any_space_before_while_parentheses = true +ij_any_spaces_around_additive_operators = true +ij_any_spaces_around_assignment_operators = true +ij_any_spaces_around_bitwise_operators = true +ij_any_spaces_around_equality_operators = true +ij_any_spaces_around_logical_operators = true +ij_any_spaces_around_multiplicative_operators = true +ij_any_spaces_around_relational_operators = true +ij_any_spaces_around_shift_operators = true +ij_any_spaces_around_unary_operator = false +ij_any_spaces_within_array_initializer_braces = false +ij_any_spaces_within_braces = false +ij_any_spaces_within_brackets = false +ij_any_spaces_within_catch_parentheses = false +ij_any_spaces_within_for_parentheses = false +ij_any_spaces_within_if_parentheses = false +ij_any_spaces_within_method_call_parentheses = false +ij_any_spaces_within_method_parentheses = false +ij_any_spaces_within_parentheses = false +ij_any_spaces_within_switch_parentheses = false +ij_any_spaces_within_while_parentheses = false +ij_any_special_else_if_treatment = true +ij_any_ternary_operation_signs_on_next_line = true +ij_any_ternary_operation_wrap = on_every_item +ij_any_while_brace_force = always +ij_any_while_on_new_line = true +ij_any_wrap_comments = true +ij_any_wrap_long_lines = true +# +# Language specific settings applied to all files +# +ij_html_align_attributes = true +ij_html_attribute_wrap = on_every_item +ij_html_continuation_indent_size = 4 +ij_html_enforce_quotes = true +ij_html_indent_size = 4 +ij_html_keep_blank_lines = 1 +ij_html_keep_indents_on_empty_lines = false +ij_html_keep_line_breaks = true +ij_html_keep_line_breaks_in_text = true +ij_html_quote_style = double +ij_html_new_line_after_last_attribute = never +ij_html_new_line_before_first_attribute = never +ij_html_space_after_tag_name = false +ij_html_space_around_equality_in_attribute = false +ij_html_space_inside_empty_tag = true +ij_html_text_wrap = on_every_item + +ij_json_space_after_colon = true +ij_json_keep_trailing_comma = false +ij_json_space_after_comma = true +ij_json_space_before_colon = false +ij_json_space_before_comma = false + +ij_markdown_keep_line_breaks_inside_text_blocks = true + +ij_xml_keep_line_breaks_in_text = true + +[*.{php,phtml}] +# +# Tabs And Indents +# +ij_php_tab_width = 4 +ij_php_indent_size = 4 +ij_php_continuation_indent_size = 4 +ij_php_keep_indents_on_empty_lines = false +ij_php_indent_code_in_php_tags = false +# +# Spaces +# +# # Before parentheses +ij_php_space_before_method_parentheses = false +ij_php_space_before_method_call_parentheses = false +ij_php_space_before_closure_left_parenthesis = true +ij_php_space_before_if_parentheses = true +ij_php_space_before_for_parentheses = true +ij_php_space_before_while_parentheses = true +ij_php_space_before_switch_parentheses = true +ij_php_space_before_catch_parentheses = true +ij_php_space_before_array_initializer_left_brace = false +ij_php_space_before_short_closure_left_parenthesis = true +# # Around operators +ij_php_spaces_around_assignment_operators = true +ij_php_spaces_around_logical_operators = true +ij_php_spaces_around_equality_operators = true +ij_php_spaces_around_relational_operators = true +ij_php_spaces_around_bitwise_operators = true +ij_php_spaces_around_additive_operators = true +ij_php_spaces_around_multiplicative_operators = true +ij_php_spaces_around_shift_operators = true +ij_php_spaces_around_unary_operator = false +ij_php_concat_spaces = true +ij_php_spaces_around_arrow = false +ij_php_spaces_around_null_coalesce_operator = true +ij_php_spaces_around_assignment_in_declare = false +# # Before left brace +ij_php_space_before_class_left_brace = true +ij_php_space_before_method_left_brace = true +ij_php_space_before_if_left_brace = true +ij_php_space_before_else_left_brace = true +ij_php_space_before_for_left_brace = true +ij_php_space_before_while_left_brace = true +ij_php_space_before_do_left_brace = true +ij_php_space_before_switch_left_brace = true +ij_php_space_before_try_left_brace = true +ij_php_space_before_catch_left_brace = true +ij_php_space_before_finally_left_brace = true +# # Before keywords +ij_php_space_before_else_keyword = true +ij_php_space_before_while_keyword = true +ij_php_space_before_catch_keyword = true +ij_php_space_before_finally_keyword = true +# # Within +ij_php_spaces_within_brackets = false +ij_php_spaces_around_var_within_brackets = false +ij_php_spaces_within_array_initializer_braces = false +ij_php_spaces_within_parentheses = false +ij_php_spaces_within_method_parentheses = false +ij_php_spaces_within_method_call_parentheses = false +ij_php_spaces_within_if_parentheses = false +ij_php_spaces_within_for_parentheses = false +ij_php_spaces_within_while_parentheses = false +ij_php_spaces_within_switch_parentheses = false +ij_php_spaces_within_catch_parentheses = false +ij_php_spaces_within_short_echo_tags = true +# # In ternary operator (?:) +ij_php_space_before_quest = true +ij_php_space_after_quest = true +ij_php_space_before_colon = true +ij_php_space_after_colon = true +ij_php_space_between_ternary_quest_and_colon = false +# # Other +ij_php_space_before_comma = false +ij_php_space_after_comma = true +ij_php_space_before_for_semicolon = false +ij_php_space_after_for_semicolon = true +ij_php_space_after_type_cast = true +ij_php_space_before_colon_in_return_type = false +ij_php_space_after_colon_in_return_type = true +ij_php_spaces_around_pipe_in_union_type = false +ij_php_space_before_colon_in_named_argument = false +ij_php_space_after_colon_in_named_argument = true +ij_php_space_before_colon_in_enum_backed_type = false +ij_php_space_after_colon_in_enum_backed_type = true +ij_php_space_before_unary_not = false +ij_php_space_after_unary_not = false +# +# Wrapping and Braces +# +# # Keep when reformatting +ij_php_keep_line_breaks = true +ij_php_line_comment_at_first_column = false +ij_php_keep_control_statement_in_one_line = false +ij_php_keep_simple_classes_in_one_line = true +ij_php_keep_simple_methods_in_one_line = false +# # Braces placement +# ### 1: End of line / Not-1: Next line +ij_php_namespace_brace_style = 0 +ij_php_class_brace_style = next_line +ij_php_anonymous_brace_style = end_of_line +ij_php_method_brace_style = next_line +ij_php_force_empty_methods_in_one_line = true +ij_php_lambda_brace_style = next_line_if_wrapped +ij_php_block_brace_style = end_of_line +# # Extends / implements / permits +ij_php_extends_list_wrap = normal +ij_php_align_multiline_extends_list = true +ij_php_extends_keyword_wrap = normal +# # Function declaration parameters +ij_php_method_parameters_wrap = on_every_item +ij_php_align_multiline_parameters = false +ij_php_method_parameters_new_line_after_left_paren = true +ij_php_method_parameters_right_paren_on_new_line = true +ij_php_keep_rparen_and_lbrace_on_one_line = true +# # Function/constructor call arguments +ij_php_call_parameters_wrap = on_every_item +ij_php_align_multiline_parameters_in_calls = false +ij_php_call_parameters_new_line_after_left_paren = true +ij_php_call_parameters_right_paren_on_new_line = true +# ### 0: Don't change / 1: Always / unset: 2: Never +ij_php_place_parens_for_constructor = 1 +ij_php_align_named_arguments = true +ij_php_treat_multiline_arrays_and_lambdas_multiline = true +# # Chained method calls +ij_php_method_call_chain_wrap = on_every_item +ij_php_align_multiline_chained_methods = false +ij_php_multiline_chained_calls_semicolon_on_new_line = false +# # if() statement +ij_php_if_lparen_on_next_line = false +ij_php_if_rparen_on_next_line = true +ij_php_if_brace_force = always +ij_php_else_on_new_line = false +ij_php_special_else_if_treatment = true +# # for()/foreach() statements +ij_php_for_statement_wrap = on_every_item +ij_php_align_multiline_for = true +ij_php_for_statement_new_line_after_left_paren = false +ij_php_for_statement_right_paren_on_new_line = true +ij_php_for_brace_force = always +# # while() statement +ij_php_while_brace_force = always +# # do..while() statement +ij_php_do_while_brace_force = always +ij_php_while_on_new_line = false +# # switch() statement +ij_php_indent_case_from_switch = true +ij_php_indent_break_from_case = true +# # 'try' statement +ij_php_catch_on_new_line = false +ij_php_finally_on_new_line = false +# # Binary expressions +ij_php_align_multiline_binary_operation = true +ij_php_binary_operation_sign_on_next_line = true +ij_php_binary_operation_wrap = normal +ij_php_parentheses_expression_new_line_after_left_paren = false +ij_php_parentheses_expression_right_paren_on_new_line = false +# # Assignment statement +ij_php_assignment_wrap = on_every_item +ij_php_place_assignment_sign_on_next_line = false +ij_php_align_assignments = false +# # Class property/constate groups +ij_php_align_group_field_declarations = false +ij_php_align_class_constants = false +ij_php_align_enum_cases = false +# # Ternary operation +ij_php_ternary_operation_wrap = on_every_item +ij_php_align_multiline_ternary_operation = true +ij_php_ternary_operation_signs_on_next_line = true +# # Array initializer +ij_php_array_initializer_wrap = on_every_item +ij_php_align_multiline_array_initializer_expression = true +ij_php_align_key_value_pairs = false +ij_php_array_initializer_new_line_after_left_brace = true +ij_php_array_initializer_right_brace_on_new_line = true +# # Modifier list +ij_php_modifier_list_wrap = false +# # Function return type +ij_php_return_type_on_new_line = false +# # Comments +ij_php_align_inline_comments = false +# # PHP opening tag +ij_php_new_line_after_php_opening_tag = true +# # 'match' expression +ij_php_align_match_arm_bodies = false +# # Group 'use' +ij_php_group_use_wrap = on_every_item +# # Attributes +ij_php_attributes_wrap = on_every_item +# # Attributes for parameters +ij_php_parameters_attributes_wrap = on_every_item +# +# Blank Lines +# +# # Keep maximum blank lines +ij_php_keep_blank_lines_in_declarations = 1 +ij_php_keep_blank_lines_in_code = 1 +ij_php_keep_blank_lines_after_lbrace = 0 +ij_php_keep_blank_lines_before_right_brace = 0 +# # Minimum blank lines +ij_php_blank_lines_after_opening_tag = 1 +ij_php_blank_lines_before_namespace = 1 +ij_php_blank_lines_after_namespace = 1 +ij_php_blank_lines_before_imports = 1 +ij_php_blank_lines_between_imports = 0 +ij_php_blank_lines_after_imports = 1 +ij_php_blank_lines_around_class = 1 +ij_php_blank_lines_after_class_header = 0 +ij_php_blank_lines_before_class_end = 0 +ij_php_blank_lines_around_field = 0 +ij_php_blank_lines_around_method = 1 +ij_php_blank_lines_before_method_body = 0 +ij_php_blank_lines_before_return_statement = 1 +ij_php_blank_lines_around_constants = 0 +ij_php_blank_lines_around_enum_cases = 0 +ij_php_blank_lines_after_function = 1 +# PHPDoc +ij_php_phpdoc_keep_blank_lines = true +ij_php_phpdoc_blank_line_before_tags = true +ij_php_phpdoc_blank_lines_around_parameters = true +ij_php_phpdoc_wrap_long_lines = true +ij_php_align_phpdoc_param_names = true +ij_php_align_phpdoc_comments = false +# # PHPDoc @param spaces +ij_php_phpdoc_param_spaces_between_tag_and_type = 1 +ij_php_phpdoc_param_spaces_between_type_and_name = 1 +ij_php_phpdoc_param_spaces_between_name_and_description = 1 +# # Generated PHPDoc tags +ij_php_phpdoc_use_fqcn = true +ij_php_null_type_position = in_the_end +# # PHPDoc tags order +ij_php_sort_phpdoc_elements = true +ij_php_deprecated_weight = 1 +ij_php_todo_weight = 2 +ij_php_param_weight = 3 +ij_php_return_weight = 4 +ij_php_throws_weight = 5 +ij_php_example_weight = 6 +ij_php_property_weight = 7 +ij_php_property_read_weight = 8 +ij_php_property_write_weight = 9 +ij_php_method_weight = 10 +ij_php_see_weight = 11 +ij_php_link_weight = 12 +ij_php_api_weight = 13 +ij_php_internal_weight = 14 +ij_php_ignore_weight = 15 +ij_php_since_weight = 16 +# # @package +ij_php_blank_lines_before_package = 1 +ij_php_blank_lines_after_package = 1 +# +# Code Conversion +# +ij_php_lower_case_boolean_const = true +ij_php_lower_case_null_const = true +ij_php_lower_case_keywords = true +ij_php_else_if_style = combine +ij_php_import_sorting = alphabetic +ij_php_comma_after_last_parameter = false +ij_php_comma_after_last_closure_use_var = false +ij_php_comma_after_last_argument = true +ij_php_comma_after_last_match_arm = true +# # Array/List declaration style +ij_php_force_short_declaration_array_style = true +ij_php_comma_after_last_array_element = true +# +# Code Generation +# +ij_php_variable_naming_style = camel_case +ij_php_fields_default_visibility = private +ij_php_getters_setters_order_style = getters_first +ij_php_getters_setters_naming_style = camel_case +ij_php_keep_first_column_comment = false +ij_php_line_comment_add_space = true +# # # + +[*.{json,htm,html,js,md,php,phtml}] +ij_json_array_wrapping = split_into_lines +ij_json_indent_size = 4 +ij_json_keep_line_breaks = false +ij_json_object_wrapping = split_into_lines +ij_json_property_alignment = do_not_align +ij_json_spaces_within_braces = true +ij_json_spaces_within_brackets = true +ij_json_wrap_long_lines = false +ij_json_continuation_indent_size = 4 +ij_json_keep_indents_on_empty_lines = false +ij_json_keep_blank_lines_in_code = 1 + +[*.{htm,html,js,php,phtml}] +ij_html_add_new_line_before_tags = body,div,p,form,h1,h2,h3 +ij_html_align_text = false +ij_html_block_comment_add_space = true +ij_html_block_comment_at_first_column = false +ij_html_do_not_break_if_inline_tags = h1,h2,h3,h4,h5,h6,p,title +ij_html_do_not_indent_children_of_tags = html,body,thead,tbody,tfoot +ij_html_inline_tags = a,abbr,acronym,b,basefont,bdo,big,br,cite,cite,code,dfn,em,font,i,img,input,kbd,label,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var +ij_html_keep_whitespaces = false +ij_html_keep_whitespaces_inside = code,pre,textarea,tt +ij_html_line_comment_at_first_column = false +ij_html_remove_new_line_before_tags = br +# More TBD + +;[*.{php,sql}] +; TBD + +[*.{yml,yaml}] +ij_yaml_align_values_properties = do_not_align +ij_yaml_autoinsert_sequence_marker = true +ij_yaml_indent_size = 4 +ij_yaml_keep_indents_on_empty_lines = false +ij_yaml_keep_line_breaks = true +ij_yaml_sequence_on_new_line = true +ij_yaml_space_before_colon = false +ij_yaml_spaces_within_braces = false +ij_yaml_spaces_within_brackets = false + +[*.http] +ij_http-request_call_parameters_wrap = off +ij_http-request_continuation_indent_size = 4 +ij_http-request_indent_size = 4 +ij_http-request_method_parameters_wrap = split_into_lines +ij_http-request_space_before_comma = false +ij_http-request_spaces_around_assignment_operators = false diff --git a/README.md b/README.md index 0a70f4a..9886e1e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,17 @@ Fuzz HTTP Exception A library containing a set of RESTful HTTP exceptions that use a consistent interface, built upon the ideas set by [symfony/http-kernel](https://github.com/symfony/http-kernel) +This code precedes the formation of inter-op standards, and is best suited for similar legacy code. You can use +these classes to handle data you want to send back with semantically correct error messaging, but it's probably not +the best solution for new projects. + +This library _can_ be used as error handling middleware, but it's _not recommended_. Most contemporary PHP +frameworks implement the PSR-7 and PSR-15 standards for HTTP Messages and supporting middleware. As such, you'll be +required to do some data juggling from Request/Response streams into "solid" data passed through the Exceptions. + +Don't expect a lot of radical movement here - it's already an outdated design for handling HTTP errors, but it's small +enough for me to learn about maintaining open libraries. + ## Usage ```php =7.0" - }, - "require-dev": { - "phpunit/phpunit": "~5.6" - }, - "autoload": { - "psr-4": { - "Fuzz\\HttpException\\": "src/", - "Fuzz\\HttpException\\Tests\\": "tests/" - } - }, - "scripts": { - "test": [ - "vendor/bin/phpunit" - ], - "test-coverage": [ - "vendor/bin/phpunit --coverage-html tests/coverage" - ], - "open-coverage": [ - "open -a \"Google Chrome\" tests/coverage/index.html" - ] - } + "name": "jtheuerkauf/php-http-exception", + "description": "A NON-PSR-7 library containing a set of RESTful HTTP exceptions that use a consistent interface.", + "license": "MIT", + "authors": [ + { + "name": "Joe Theuerkauf", + "email": "joe@theuerkauf.dev" + }, + { + "name": "Fuzz Web", + "email": "opensource@fuzzproductions.com" + } + ], + "replace": { + "fuzz/http-exception": "1.0.4" + }, + "require": { + "php": ">=7.0" + }, + "require-dev": { + "roave/security-advisories": "dev-latest", + "phpunit/phpunit": "^6.5" + }, + "autoload": { + "psr-4": { + "Fuzz\\HttpException\\": "src/", + "Fuzz\\HttpException\\Tests\\": "tests/" + } + }, + "config": { + "platform": { + "php": "7.0" + } + }, + "scripts": { + "test": [ + "vendor/bin/phpunit" + ], + "test-coverage": [ + "vendor/bin/phpunit --coverage-html tests/coverage" + ] + }, + "keywords": [ + "error", + "exception", + "general", + "generic", + "http" + ] } diff --git a/src/AccessDeniedHttpException.php b/src/AccessDeniedHttpException.php index 22c78c6..198ca7b 100644 --- a/src/AccessDeniedHttpException.php +++ b/src/AccessDeniedHttpException.php @@ -1,35 +1,18 @@ statusCode = $statusCode ?? 500; - $this->error = $error ?? 'internal_server_error'; - $this->errorDescription = $errorDescription ?? 'Internal Server Error'; - $this->errorData = $errorData; - $this->userTitle = $userTitle ?? 'Ooops!!!'; - $this->userMessage = $userMessage ?? 'Seems one of our developers unplugged the server again!'; - $this->httpHeaders = $httpHeaders; - - $originalMessage = $errorDescription; - $originalCode = $statusCode; - - parent::__construct($originalMessage, $originalCode, $previous); - } - - /** - * Get the HTTP status code. - * - * @return int - */ - public function getStatusCode(): int - { - return $this->statusCode; - } - - /** - * Set the HTTP status code. - * - * @param int $statusCode - * - * @return HttpException - */ - public function setStatusCode(int $statusCode): HttpException - { - $this->statusCode = $statusCode; - - return $this; - } - - /** - * Return HTTP headers. - * - * @return array - */ - public function getHttpHeaders() - { - return $this->httpHeaders; - } - - /** - * Set the HTTP headers. - * - * @param array $httpHeaders - * - * @return HttpException - */ - public function setHttpHeaders(array $httpHeaders): HttpException - { - $this->httpHeaders = $httpHeaders; - - return $this; - } - - /** - * Get the error code. - * - * @return string - */ - public function getError(): string - { - return $this->error; - } - - /** - * Set the error code. - * - * @param string $error - * - * @return HttpException - */ - public function setError(string $error): HttpException - { - $this->error = $error; - - return $this; - } - - /** - * Get the error description. - * - * @return string - */ - public function getErrorDescription(): string - { - return $this->errorDescription; - } - - /** - * Set the error description. - * - * @param string $errorDescription - * - * @return HttpException - */ - public function setErrorDescription(string $errorDescription): HttpException - { - $this->errorDescription = $errorDescription; - - return $this; - } - - /** - * Get error data. - * - * @return array|null|string - */ - public function getErrorData() - { - return $this->errorData; - } - - /** - * Set error data. - * - * @param array|null|string $errorData - * - * @return HttpException - */ - public function setErrorData($errorData) - { - $this->errorData = $errorData; - - return $this; - } - - /** - * Get user title. - * - * @return string - */ - public function getUserTitle(): string - { - return $this->userTitle; - } - - /** - * Set user title. - * - * @param string $userTitle - * - * @return HttpException - */ - public function setUserTitle(string $userTitle): HttpException - { - $this->userTitle = $userTitle; - - return $this; - } - - /** - * Get user message. - * - * @return array|null|string - */ - public function getUserMessage() - { - return $this->userMessage; - } - - /** - * Set user message. - * - * @param array|null|string $userMessage - * - * @return HttpException - */ - public function setUserMessage($userMessage) - { - $this->userMessage = $userMessage; - - return $this; - } + /** + * HTTP Status code. + * + * @var int + */ + protected $statusCode; + + /** + * Http headers to pass to the response. + * + * @var array + */ + protected $httpHeaders; + + /** + * An error code. + * + * @var string + */ + protected $error; + + /** + * The error description. + * + * @var string + */ + protected $errorDescription; + + /** + * Error data that an application can use to run logic. + * + * @var array|string|null + */ + protected $errorData; + + /** + * An error title that can be presented to the user. + * + * @var string + */ + protected $userTitle; + + /** + * A user friendly error message. + * + * If it is an array, the keys will be the field names, and the value the error for those fields. + * + * @var array|string|null + */ + protected $userMessage; + + /** + * HttpException constructor. + * + * @param int $statusCode + * @param array $httpHeaders + * @param string $error + * @param string $errorDescription + * @param array $errorData + * @param string $userTitle + * @param string $userMessage + * @param Throwable|null $previous + */ + public function __construct( + int $statusCode = null, + string $error = null, + string $errorDescription = null, + $errorData = [], + string $userTitle = null, + $userMessage = null, + array $httpHeaders = [], + Throwable $previous = null + ) { + $this->statusCode = $statusCode ?? 500; + $this->error = $error ?? 'internal_server_error'; + $this->errorDescription = $errorDescription ?? 'Internal Server Error'; + $this->errorData = $errorData; + $this->userTitle = $userTitle ?? 'Ooops!!!'; + $this->userMessage = $userMessage ?? 'Seems one of our developers unplugged the server again!'; + $this->httpHeaders = $httpHeaders; + + $originalMessage = $errorDescription; + $originalCode = $statusCode; + + parent::__construct($originalMessage, $originalCode, $previous); + } + + /** + * Get the HTTP status code. + * + * @return int + */ + public function getStatusCode(): int + { + return $this->statusCode; + } + + /** + * Set the HTTP status code. + * + * @param int $statusCode + * + * @return HttpException + */ + public function setStatusCode(int $statusCode): HttpException + { + $this->statusCode = $statusCode; + + return $this; + } + + /** + * Return HTTP headers. + * + * @return array + */ + public function getHttpHeaders() + { + return $this->httpHeaders; + } + + /** + * Set the HTTP headers. + * + * @param array $httpHeaders + * + * @return HttpException + */ + public function setHttpHeaders(array $httpHeaders): HttpException + { + $this->httpHeaders = $httpHeaders; + + return $this; + } + + /** + * Get the error code. + * + * @return string + */ + public function getError(): string + { + return $this->error; + } + + /** + * Set the error code. + * + * @param string $error + * + * @return HttpException + */ + public function setError(string $error): HttpException + { + $this->error = $error; + + return $this; + } + + /** + * Get the error description. + * + * @return string + */ + public function getErrorDescription(): string + { + return $this->errorDescription; + } + + /** + * Set the error description. + * + * @param string $errorDescription + * + * @return HttpException + */ + public function setErrorDescription(string $errorDescription): HttpException + { + $this->errorDescription = $errorDescription; + + return $this; + } + + /** + * Get error data. + * + * @return array|null|string + */ + public function getErrorData() + { + return $this->errorData; + } + + /** + * Set error data. + * + * @param array|null|string $errorData + * + * @return HttpException + */ + public function setErrorData($errorData) + { + $this->errorData = $errorData; + + return $this; + } + + /** + * Get user title. + * + * @return string + */ + public function getUserTitle(): string + { + return $this->userTitle; + } + + /** + * Set user title. + * + * @param string $userTitle + * + * @return HttpException + */ + public function setUserTitle(string $userTitle): HttpException + { + $this->userTitle = $userTitle; + + return $this; + } + + /** + * Get user message. + * + * @return array|null|string + */ + public function getUserMessage() + { + return $this->userMessage; + } + + /** + * Set user message. + * + * @param array|null|string $userMessage + * + * @return HttpException + */ + public function setUserMessage($userMessage) + { + $this->userMessage = $userMessage; + + return $this; + } } diff --git a/src/InternalServerErrorHttpException.php b/src/InternalServerErrorHttpException.php index c81e97a..4e6455d 100644 --- a/src/InternalServerErrorHttpException.php +++ b/src/InternalServerErrorHttpException.php @@ -1,35 +1,54 @@