├── .editorconfig ├── LICENSE ├── README.md ├── composer.json └── src ├── Commands ├── ClearCache.php └── UpdateCache.php ├── Exceptions ├── CacheException.php ├── Exception.php └── FileReadException.php ├── Facades └── Sensitive.php ├── Sensitive.php ├── SensitiveCache.php ├── SensitiveCacheInterface.php ├── ServiceProvider.php └── config └── sensitive.php /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | charset = utf-8 3 | end_of_line = lf 4 | indent_size = 4 5 | indent_style = space 6 | insert_final_newline = true 7 | max_line_length = 120 8 | tab_width = 4 9 | trim_trailing_whitespace = true 10 | ij_continuation_indent_size = 8 11 | ij_formatter_off_tag = @formatter : off 12 | ij_formatter_on_tag = @formatter : on 13 | ij_formatter_tags_enabled = false 14 | ij_smart_tabs = false 15 | ij_wrap_on_typing = false 16 | 17 | [*.blade.php] 18 | ij_blade_keep_indents_on_empty_lines = false 19 | 20 | [*.css] 21 | indent_size = 2 22 | tab_width = 2 23 | ij_continuation_indent_size = 2 24 | ij_css_align_closing_brace_with_properties = false 25 | ij_css_blank_lines_around_nested_selector = 0 26 | ij_css_blank_lines_between_blocks = 0 27 | ij_css_brace_placement = 0 28 | ij_css_hex_color_long_format = false 29 | ij_css_hex_color_lower_case = true 30 | ij_css_hex_color_short_format = true 31 | ij_css_hex_color_upper_case = false 32 | ij_css_keep_blank_lines_in_code = 2 33 | ij_css_keep_indents_on_empty_lines = false 34 | ij_css_keep_single_line_blocks = true 35 | ij_css_properties_order = font, font-family, font-size, font-weight, font-style, font-variant, font-size-adjust, font-stretch, line-height, position, z-index, top, right, bottom, left, display, visibility, float, clear, overflow, overflow-x, overflow-y, clip, zoom, align-content, align-items, align-self, flex, flex-flow, flex-basis, flex-direction, flex-grow, flex-shrink, flex-wrap, justify-content, order, box-sizing, width, min-width, max-width, height, min-height, max-height, margin, margin-top, margin-right, margin-bottom, margin-left, padding, padding-top, padding-right, padding-bottom, padding-left, table-layout, empty-cells, caption-side, border-spacing, border-collapse, list-style, list-style-position, list-style-type, list-style-image, content, quotes, counter-reset, counter-increment, resize, cursor, user-select, nav-index, nav-up, nav-right, nav-down, nav-left, transition, transition-delay, transition-timing-function, transition-duration, transition-property, transform, transform-origin, animation, animation-name, animation-duration, animation-play-state, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, text-align, text-align-last, vertical-align, white-space, text-decoration, text-emphasis, text-emphasis-color, text-emphasis-style, text-emphasis-position, text-indent, text-justify, letter-spacing, word-spacing, text-outline, text-transform, text-wrap, text-overflow, text-overflow-ellipsis, text-overflow-mode, word-wrap, word-break, tab-size, hyphens, pointer-events, opacity, color, border, border-width, border-style, border-color, border-top, border-top-width, border-top-style, border-top-color, border-right, border-right-width, border-right-style, border-right-color, border-bottom, border-bottom-width, border-bottom-style, border-bottom-color, border-left, border-left-width, border-left-style, border-left-color, border-radius, border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius, border-image, border-image-source, border-image-slice, border-image-width, border-image-outset, border-image-repeat, outline, outline-width, outline-style, outline-color, outline-offset, background, background-color, background-image, background-repeat, background-attachment, background-position, background-position-x, background-position-y, background-clip, background-origin, background-size, box-decoration-break, box-shadow, text-shadow 36 | ij_css_space_after_colon = true 37 | ij_css_space_before_opening_brace = true 38 | ij_css_value_alignment = 0 39 | 40 | [*.feature] 41 | indent_size = 2 42 | ij_gherkin_keep_indents_on_empty_lines = false 43 | 44 | [*.haml] 45 | indent_size = 2 46 | ij_haml_keep_indents_on_empty_lines = false 47 | 48 | [*.less] 49 | indent_size = 2 50 | ij_less_align_closing_brace_with_properties = false 51 | ij_less_blank_lines_around_nested_selector = 1 52 | ij_less_blank_lines_between_blocks = 1 53 | ij_less_brace_placement = 0 54 | ij_less_hex_color_long_format = false 55 | ij_less_hex_color_lower_case = false 56 | ij_less_hex_color_short_format = false 57 | ij_less_hex_color_upper_case = false 58 | ij_less_keep_blank_lines_in_code = 2 59 | ij_less_keep_indents_on_empty_lines = false 60 | ij_less_keep_single_line_blocks = false 61 | ij_less_properties_order = font, font-family, font-size, font-weight, font-style, font-variant, font-size-adjust, font-stretch, line-height, position, z-index, top, right, bottom, left, display, visibility, float, clear, overflow, overflow-x, overflow-y, clip, zoom, align-content, align-items, align-self, flex, flex-flow, flex-basis, flex-direction, flex-grow, flex-shrink, flex-wrap, justify-content, order, box-sizing, width, min-width, max-width, height, min-height, max-height, margin, margin-top, margin-right, margin-bottom, margin-left, padding, padding-top, padding-right, padding-bottom, padding-left, table-layout, empty-cells, caption-side, border-spacing, border-collapse, list-style, list-style-position, list-style-type, list-style-image, content, quotes, counter-reset, counter-increment, resize, cursor, user-select, nav-index, nav-up, nav-right, nav-down, nav-left, transition, transition-delay, transition-timing-function, transition-duration, transition-property, transform, transform-origin, animation, animation-name, animation-duration, animation-play-state, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, text-align, text-align-last, vertical-align, white-space, text-decoration, text-emphasis, text-emphasis-color, text-emphasis-style, text-emphasis-position, text-indent, text-justify, letter-spacing, word-spacing, text-outline, text-transform, text-wrap, text-overflow, text-overflow-ellipsis, text-overflow-mode, word-wrap, word-break, tab-size, hyphens, pointer-events, opacity, color, border, border-width, border-style, border-color, border-top, border-top-width, border-top-style, border-top-color, border-right, border-right-width, border-right-style, border-right-color, border-bottom, border-bottom-width, border-bottom-style, border-bottom-color, border-left, border-left-width, border-left-style, border-left-color, border-radius, border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius, border-image, border-image-source, border-image-slice, border-image-width, border-image-outset, border-image-repeat, outline, outline-width, outline-style, outline-color, outline-offset, background, background-color, background-image, background-repeat, background-attachment, background-position, background-position-x, background-position-y, background-clip, background-origin, background-size, box-decoration-break, box-shadow, text-shadow 62 | ij_less_space_after_colon = true 63 | ij_less_space_before_opening_brace = true 64 | ij_less_value_alignment = 0 65 | 66 | [*.sass] 67 | indent_size = 2 68 | ij_sass_align_closing_brace_with_properties = false 69 | ij_sass_blank_lines_around_nested_selector = 1 70 | ij_sass_blank_lines_between_blocks = 1 71 | ij_sass_brace_placement = 0 72 | ij_sass_hex_color_long_format = false 73 | ij_sass_hex_color_lower_case = false 74 | ij_sass_hex_color_short_format = false 75 | ij_sass_hex_color_upper_case = false 76 | ij_sass_keep_blank_lines_in_code = 2 77 | ij_sass_keep_indents_on_empty_lines = false 78 | ij_sass_keep_single_line_blocks = false 79 | ij_sass_properties_order = font, font-family, font-size, font-weight, font-style, font-variant, font-size-adjust, font-stretch, line-height, position, z-index, top, right, bottom, left, display, visibility, float, clear, overflow, overflow-x, overflow-y, clip, zoom, align-content, align-items, align-self, flex, flex-flow, flex-basis, flex-direction, flex-grow, flex-shrink, flex-wrap, justify-content, order, box-sizing, width, min-width, max-width, height, min-height, max-height, margin, margin-top, margin-right, margin-bottom, margin-left, padding, padding-top, padding-right, padding-bottom, padding-left, table-layout, empty-cells, caption-side, border-spacing, border-collapse, list-style, list-style-position, list-style-type, list-style-image, content, quotes, counter-reset, counter-increment, resize, cursor, user-select, nav-index, nav-up, nav-right, nav-down, nav-left, transition, transition-delay, transition-timing-function, transition-duration, transition-property, transform, transform-origin, animation, animation-name, animation-duration, animation-play-state, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, text-align, text-align-last, vertical-align, white-space, text-decoration, text-emphasis, text-emphasis-color, text-emphasis-style, text-emphasis-position, text-indent, text-justify, letter-spacing, word-spacing, text-outline, text-transform, text-wrap, text-overflow, text-overflow-ellipsis, text-overflow-mode, word-wrap, word-break, tab-size, hyphens, pointer-events, opacity, color, border, border-width, border-style, border-color, border-top, border-top-width, border-top-style, border-top-color, border-right, border-right-width, border-right-style, border-right-color, border-bottom, border-bottom-width, border-bottom-style, border-bottom-color, border-left, border-left-width, border-left-style, border-left-color, border-radius, border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius, border-image, border-image-source, border-image-slice, border-image-width, border-image-outset, border-image-repeat, outline, outline-width, outline-style, outline-color, outline-offset, background, background-color, background-image, background-repeat, background-attachment, background-position, background-position-x, background-position-y, background-clip, background-origin, background-size, box-decoration-break, box-shadow, text-shadow 80 | ij_sass_space_after_colon = true 81 | ij_sass_space_before_opening_brace = true 82 | ij_sass_value_alignment = 0 83 | 84 | [*.scss] 85 | indent_size = 2 86 | ij_scss_align_closing_brace_with_properties = false 87 | ij_scss_blank_lines_around_nested_selector = 1 88 | ij_scss_blank_lines_between_blocks = 1 89 | ij_scss_brace_placement = 0 90 | ij_scss_hex_color_long_format = false 91 | ij_scss_hex_color_lower_case = false 92 | ij_scss_hex_color_short_format = false 93 | ij_scss_hex_color_upper_case = false 94 | ij_scss_keep_blank_lines_in_code = 2 95 | ij_scss_keep_indents_on_empty_lines = false 96 | ij_scss_keep_single_line_blocks = false 97 | ij_scss_properties_order = font, font-family, font-size, font-weight, font-style, font-variant, font-size-adjust, font-stretch, line-height, position, z-index, top, right, bottom, left, display, visibility, float, clear, overflow, overflow-x, overflow-y, clip, zoom, align-content, align-items, align-self, flex, flex-flow, flex-basis, flex-direction, flex-grow, flex-shrink, flex-wrap, justify-content, order, box-sizing, width, min-width, max-width, height, min-height, max-height, margin, margin-top, margin-right, margin-bottom, margin-left, padding, padding-top, padding-right, padding-bottom, padding-left, table-layout, empty-cells, caption-side, border-spacing, border-collapse, list-style, list-style-position, list-style-type, list-style-image, content, quotes, counter-reset, counter-increment, resize, cursor, user-select, nav-index, nav-up, nav-right, nav-down, nav-left, transition, transition-delay, transition-timing-function, transition-duration, transition-property, transform, transform-origin, animation, animation-name, animation-duration, animation-play-state, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, text-align, text-align-last, vertical-align, white-space, text-decoration, text-emphasis, text-emphasis-color, text-emphasis-style, text-emphasis-position, text-indent, text-justify, letter-spacing, word-spacing, text-outline, text-transform, text-wrap, text-overflow, text-overflow-ellipsis, text-overflow-mode, word-wrap, word-break, tab-size, hyphens, pointer-events, opacity, color, border, border-width, border-style, border-color, border-top, border-top-width, border-top-style, border-top-color, border-right, border-right-width, border-right-style, border-right-color, border-bottom, border-bottom-width, border-bottom-style, border-bottom-color, border-left, border-left-width, border-left-style, border-left-color, border-radius, border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius, border-image, border-image-source, border-image-slice, border-image-width, border-image-outset, border-image-repeat, outline, outline-width, outline-style, outline-color, outline-offset, background, background-color, background-image, background-repeat, background-attachment, background-position, background-position-x, background-position-y, background-clip, background-origin, background-size, box-decoration-break, box-shadow, text-shadow 98 | ij_scss_space_after_colon = true 99 | ij_scss_space_before_opening_brace = true 100 | ij_scss_value_alignment = 0 101 | 102 | [.editorconfig] 103 | ij_editorconfig_align_group_field_declarations = false 104 | ij_editorconfig_space_after_colon = true 105 | ij_editorconfig_space_after_comma = true 106 | ij_editorconfig_space_before_colon = true 107 | ij_editorconfig_space_before_comma = false 108 | ij_editorconfig_spaces_around_assignment_operators = true 109 | 110 | [{*.ats, *.ts}] 111 | ij_continuation_indent_size = 4 112 | ij_typescript_align_imports = false 113 | ij_typescript_align_multiline_array_initializer_expression = true 114 | ij_typescript_align_multiline_binary_operation = false 115 | ij_typescript_align_multiline_chained_methods = false 116 | ij_typescript_align_multiline_extends_list = false 117 | ij_typescript_align_multiline_for = true 118 | ij_typescript_align_multiline_parameters = false 119 | ij_typescript_align_multiline_parameters_in_calls = false 120 | ij_typescript_align_multiline_ternary_operation = false 121 | ij_typescript_align_object_properties = 0 122 | ij_typescript_align_union_types = false 123 | ij_typescript_align_var_statements = 0 124 | ij_typescript_array_initializer_new_line_after_left_brace = true 125 | ij_typescript_array_initializer_right_brace_on_new_line = true 126 | ij_typescript_array_initializer_wrap = on_every_item 127 | ij_typescript_assignment_wrap = off 128 | ij_typescript_binary_operation_sign_on_next_line = false 129 | ij_typescript_binary_operation_wrap = off 130 | ij_typescript_blacklist_imports = rxjs/Rx, node_modules/**/*, @angular/material, @angular/material/typings/** 131 | ij_typescript_blank_lines_after_imports = 1 132 | ij_typescript_blank_lines_around_class = 1 133 | ij_typescript_blank_lines_around_field = 0 134 | ij_typescript_blank_lines_around_field_in_interface = 0 135 | ij_typescript_blank_lines_around_function = 1 136 | ij_typescript_blank_lines_around_method = 1 137 | ij_typescript_blank_lines_around_method_in_interface = 1 138 | ij_typescript_block_brace_style = end_of_line 139 | ij_typescript_call_parameters_new_line_after_left_paren = false 140 | ij_typescript_call_parameters_right_paren_on_new_line = false 141 | ij_typescript_call_parameters_wrap = normal 142 | ij_typescript_catch_on_new_line = false 143 | ij_typescript_chained_call_dot_on_new_line = false 144 | ij_typescript_class_brace_style = next_line 145 | ij_typescript_comma_on_new_line = false 146 | ij_typescript_do_while_brace_force = always 147 | ij_typescript_else_on_new_line = false 148 | ij_typescript_enforce_trailing_comma = whenmultiline 149 | ij_typescript_extends_keyword_wrap = off 150 | ij_typescript_extends_list_wrap = off 151 | ij_typescript_field_prefix = _ 152 | ij_typescript_file_name_style = relaxed 153 | ij_typescript_finally_on_new_line = false 154 | ij_typescript_for_brace_force = always 155 | ij_typescript_for_statement_new_line_after_left_paren = false 156 | ij_typescript_for_statement_right_paren_on_new_line = false 157 | ij_typescript_for_statement_wrap = off 158 | ij_typescript_force_quote_style = true 159 | ij_typescript_force_semicolon_style = true 160 | ij_typescript_function_expression_brace_style = end_of_line 161 | ij_typescript_if_brace_force = always 162 | ij_typescript_import_merge_members = global 163 | ij_typescript_import_prefer_absolute_path = global 164 | ij_typescript_import_sort_members = true 165 | ij_typescript_import_sort_module_name = false 166 | ij_typescript_import_use_node_resolution = true 167 | ij_typescript_imports_wrap = on_every_item 168 | ij_typescript_indent_case_from_switch = true 169 | ij_typescript_indent_chained_calls = true 170 | ij_typescript_indent_package_children = 0 171 | ij_typescript_jsdoc_include_types = false 172 | ij_typescript_jsx_attribute_value = braces 173 | ij_typescript_keep_blank_lines_in_code = 2 174 | ij_typescript_keep_first_column_comment = false 175 | ij_typescript_keep_indents_on_empty_lines = false 176 | ij_typescript_keep_line_breaks = true 177 | ij_typescript_keep_simple_blocks_in_one_line = false 178 | ij_typescript_keep_simple_methods_in_one_line = false 179 | ij_typescript_line_comment_add_space = true 180 | ij_typescript_line_comment_at_first_column = false 181 | ij_typescript_method_brace_style = next_line 182 | ij_typescript_method_call_chain_wrap = off 183 | ij_typescript_method_parameters_new_line_after_left_paren = true 184 | ij_typescript_method_parameters_right_paren_on_new_line = true 185 | ij_typescript_method_parameters_wrap = on_every_item 186 | ij_typescript_object_literal_wrap = on_every_item 187 | ij_typescript_parentheses_expression_new_line_after_left_paren = false 188 | ij_typescript_parentheses_expression_right_paren_on_new_line = false 189 | ij_typescript_place_assignment_sign_on_next_line = false 190 | ij_typescript_prefer_as_type_cast = false 191 | ij_typescript_prefer_parameters_wrap = false 192 | ij_typescript_reformat_c_style_comments = false 193 | ij_typescript_space_after_colon = true 194 | ij_typescript_space_after_comma = true 195 | ij_typescript_space_after_dots_in_rest_parameter = false 196 | ij_typescript_space_after_generator_mult = true 197 | ij_typescript_space_after_property_colon = true 198 | ij_typescript_space_after_quest = true 199 | ij_typescript_space_after_type_colon = true 200 | ij_typescript_space_after_unary_not = false 201 | ij_typescript_space_before_async_arrow_lparen = true 202 | ij_typescript_space_before_catch_keyword = true 203 | ij_typescript_space_before_catch_left_brace = true 204 | ij_typescript_space_before_catch_parentheses = true 205 | ij_typescript_space_before_class_lbrace = true 206 | ij_typescript_space_before_class_left_brace = true 207 | ij_typescript_space_before_colon = true 208 | ij_typescript_space_before_comma = false 209 | ij_typescript_space_before_do_left_brace = true 210 | ij_typescript_space_before_else_keyword = true 211 | ij_typescript_space_before_else_left_brace = true 212 | ij_typescript_space_before_finally_keyword = true 213 | ij_typescript_space_before_finally_left_brace = true 214 | ij_typescript_space_before_for_left_brace = true 215 | ij_typescript_space_before_for_parentheses = true 216 | ij_typescript_space_before_for_semicolon = false 217 | ij_typescript_space_before_function_left_parenth = false 218 | ij_typescript_space_before_generator_mult = false 219 | ij_typescript_space_before_if_left_brace = true 220 | ij_typescript_space_before_if_parentheses = true 221 | ij_typescript_space_before_method_call_parentheses = false 222 | ij_typescript_space_before_method_left_brace = true 223 | ij_typescript_space_before_method_parentheses = false 224 | ij_typescript_space_before_property_colon = false 225 | ij_typescript_space_before_quest = true 226 | ij_typescript_space_before_switch_left_brace = true 227 | ij_typescript_space_before_switch_parentheses = true 228 | ij_typescript_space_before_try_left_brace = true 229 | ij_typescript_space_before_type_colon = false 230 | ij_typescript_space_before_unary_not = false 231 | ij_typescript_space_before_while_keyword = true 232 | ij_typescript_space_before_while_left_brace = true 233 | ij_typescript_space_before_while_parentheses = true 234 | ij_typescript_spaces_around_additive_operators = true 235 | ij_typescript_spaces_around_arrow_function_operator = true 236 | ij_typescript_spaces_around_assignment_operators = true 237 | ij_typescript_spaces_around_bitwise_operators = true 238 | ij_typescript_spaces_around_equality_operators = true 239 | ij_typescript_spaces_around_logical_operators = true 240 | ij_typescript_spaces_around_multiplicative_operators = true 241 | ij_typescript_spaces_around_relational_operators = true 242 | ij_typescript_spaces_around_shift_operators = true 243 | ij_typescript_spaces_around_unary_operator = false 244 | ij_typescript_spaces_within_array_initializer_brackets = false 245 | ij_typescript_spaces_within_brackets = false 246 | ij_typescript_spaces_within_catch_parentheses = false 247 | ij_typescript_spaces_within_for_parentheses = false 248 | ij_typescript_spaces_within_if_parentheses = false 249 | ij_typescript_spaces_within_imports = false 250 | ij_typescript_spaces_within_interpolation_expressions = false 251 | ij_typescript_spaces_within_method_call_parentheses = false 252 | ij_typescript_spaces_within_method_parentheses = false 253 | ij_typescript_spaces_within_object_literal_braces = false 254 | ij_typescript_spaces_within_object_type_braces = true 255 | ij_typescript_spaces_within_parentheses = false 256 | ij_typescript_spaces_within_switch_parentheses = false 257 | ij_typescript_spaces_within_type_assertion = false 258 | ij_typescript_spaces_within_union_types = true 259 | ij_typescript_spaces_within_while_parentheses = false 260 | ij_typescript_special_else_if_treatment = false 261 | ij_typescript_ternary_operation_signs_on_next_line = false 262 | ij_typescript_ternary_operation_wrap = off 263 | ij_typescript_union_types_wrap = on_every_item 264 | ij_typescript_use_chained_calls_group_indents = false 265 | ij_typescript_use_double_quotes = false 266 | ij_typescript_use_explicit_js_extension = global 267 | ij_typescript_use_path_mapping = always 268 | ij_typescript_use_public_modifier = false 269 | ij_typescript_use_semicolon_after_statement = true 270 | ij_typescript_var_declaration_wrap = normal 271 | ij_typescript_while_brace_force = always 272 | ij_typescript_while_on_new_line = false 273 | ij_typescript_wrap_comments = false 274 | 275 | [{*.ctp, *.phtml, *.module, *.php, *.php5, *.php4, *.hphp, *.inc}] 276 | ij_continuation_indent_size = 4 277 | ij_php_align_assignments = false 278 | ij_php_align_class_constants = false 279 | ij_php_align_group_field_declarations = false 280 | ij_php_align_inline_comments = false 281 | ij_php_align_key_value_pairs = false 282 | ij_php_align_multiline_array_initializer_expression = true 283 | ij_php_align_multiline_binary_operation = false 284 | ij_php_align_multiline_chained_methods = false 285 | ij_php_align_multiline_extends_list = false 286 | ij_php_align_multiline_for = true 287 | ij_php_align_multiline_parameters = false 288 | ij_php_align_multiline_parameters_in_calls = false 289 | ij_php_align_multiline_ternary_operation = false 290 | ij_php_align_phpdoc_comments = true 291 | ij_php_align_phpdoc_param_names = true 292 | ij_php_api_weight = 1 293 | ij_php_array_initializer_new_line_after_left_brace = true 294 | ij_php_array_initializer_right_brace_on_new_line = true 295 | ij_php_array_initializer_wrap = on_every_item 296 | ij_php_assignment_wrap = off 297 | ij_php_author_weight = 28 298 | ij_php_binary_operation_sign_on_next_line = false 299 | ij_php_binary_operation_wrap = off 300 | ij_php_blank_lines_after_class_header = 0 301 | ij_php_blank_lines_after_function = 1 302 | ij_php_blank_lines_after_imports = 1 303 | ij_php_blank_lines_after_opening_tag = 0 304 | ij_php_blank_lines_after_package = 1 305 | ij_php_blank_lines_around_class = 1 306 | ij_php_blank_lines_around_constants = 0 307 | ij_php_blank_lines_around_field = 0 308 | ij_php_blank_lines_around_method = 1 309 | ij_php_blank_lines_before_class_end = 0 310 | ij_php_blank_lines_before_imports = 1 311 | ij_php_blank_lines_before_method_body = 0 312 | ij_php_blank_lines_before_package = 1 313 | ij_php_blank_lines_before_return_statement = 0 314 | ij_php_block_brace_style = end_of_line 315 | ij_php_call_parameters_new_line_after_left_paren = false 316 | ij_php_call_parameters_right_paren_on_new_line = false 317 | ij_php_call_parameters_wrap = normal 318 | ij_php_catch_on_new_line = false 319 | ij_php_category_weight = 28 320 | ij_php_class_brace_style = next_line 321 | ij_php_comma_after_last_array_element = true 322 | ij_php_concat_spaces = true 323 | ij_php_copyright_weight = 28 324 | ij_php_deprecated_weight = 28 325 | ij_php_do_while_brace_force = always 326 | ij_php_else_if_style = combine 327 | ij_php_else_on_new_line = false 328 | ij_php_example_weight = 3 329 | ij_php_extends_keyword_wrap = off 330 | ij_php_extends_list_wrap = off 331 | ij_php_fields_default_visibility = private 332 | ij_php_filesource_weight = 28 333 | ij_php_finally_on_new_line = false 334 | ij_php_for_brace_force = always 335 | ij_php_for_statement_new_line_after_left_paren = false 336 | ij_php_for_statement_right_paren_on_new_line = false 337 | ij_php_for_statement_wrap = off 338 | ij_php_force_short_declaration_array_style = true 339 | ij_php_global_weight = 28 340 | ij_php_group_use_wrap = on_every_item 341 | ij_php_if_brace_force = always 342 | ij_php_if_lparen_on_next_line = false 343 | ij_php_if_rparen_on_next_line = false 344 | ij_php_ignore_weight = 28 345 | ij_php_import_sorting = alphabetic 346 | ij_php_indent_break_from_case = true 347 | ij_php_indent_case_from_switch = true 348 | ij_php_indent_code_in_php_tags = false 349 | ij_php_internal_weight = 28 350 | ij_php_keep_blank_lines_after_lbrace = 1 351 | ij_php_keep_blank_lines_before_right_brace = 1 352 | ij_php_keep_blank_lines_in_code = 2 353 | ij_php_keep_blank_lines_in_declarations = 2 354 | ij_php_keep_control_statement_in_one_line = false 355 | ij_php_keep_first_column_comment = false 356 | ij_php_keep_indents_on_empty_lines = false 357 | ij_php_keep_line_breaks = true 358 | ij_php_keep_rparen_and_lbrace_on_one_line = true 359 | ij_php_keep_simple_methods_in_one_line = false 360 | ij_php_lambda_brace_style = end_of_line 361 | ij_php_license_weight = 28 362 | ij_php_line_comment_add_space = true 363 | ij_php_line_comment_at_first_column = false 364 | ij_php_link_weight = 0 365 | ij_php_lower_case_boolean_const = true 366 | ij_php_lower_case_null_const = true 367 | ij_php_method_brace_style = next_line 368 | ij_php_method_call_chain_wrap = off 369 | ij_php_method_parameters_new_line_after_left_paren = true 370 | ij_php_method_parameters_right_paren_on_new_line = true 371 | ij_php_method_parameters_wrap = on_every_item 372 | ij_php_method_weight = 2 373 | ij_php_modifier_list_wrap = false 374 | ij_php_multiline_chained_calls_semicolon_on_new_line = false 375 | ij_php_namespace_brace_style = 1 376 | ij_php_null_type_position = in_the_end 377 | ij_php_package_weight = 28 378 | ij_php_param_weight = 4 379 | ij_php_parentheses_expression_new_line_after_left_paren = false 380 | ij_php_parentheses_expression_right_paren_on_new_line = false 381 | ij_php_phpdoc_blank_line_before_tags = true 382 | ij_php_phpdoc_blank_lines_around_parameters = true 383 | ij_php_phpdoc_keep_blank_lines = true 384 | ij_php_phpdoc_param_spaces_between_name_and_description = 1 385 | ij_php_phpdoc_param_spaces_between_tag_and_type = 1 386 | ij_php_phpdoc_param_spaces_between_type_and_name = 1 387 | ij_php_phpdoc_use_fqcn = false 388 | ij_php_phpdoc_wrap_long_lines = true 389 | ij_php_place_assignment_sign_on_next_line = false 390 | ij_php_place_parens_for_constructor = 0 391 | ij_php_property_read_weight = 28 392 | ij_php_property_weight = 28 393 | ij_php_property_write_weight = 28 394 | ij_php_return_type_on_new_line = false 395 | ij_php_return_weight = 5 396 | ij_php_see_weight = 28 397 | ij_php_since_weight = 28 398 | ij_php_sort_phpdoc_elements = true 399 | ij_php_space_after_colon = true 400 | ij_php_space_after_colon_in_return_type = true 401 | ij_php_space_after_comma = true 402 | ij_php_space_after_for_semicolon = true 403 | ij_php_space_after_quest = true 404 | ij_php_space_after_type_cast = false 405 | ij_php_space_after_unary_not = false 406 | ij_php_space_before_array_initializer_left_brace = false 407 | ij_php_space_before_catch_keyword = true 408 | ij_php_space_before_catch_left_brace = true 409 | ij_php_space_before_catch_parentheses = true 410 | ij_php_space_before_class_left_brace = true 411 | ij_php_space_before_closure_left_parenthesis = true 412 | ij_php_space_before_colon = true 413 | ij_php_space_before_colon_in_return_type = false 414 | ij_php_space_before_comma = false 415 | ij_php_space_before_do_left_brace = true 416 | ij_php_space_before_else_keyword = true 417 | ij_php_space_before_else_left_brace = true 418 | ij_php_space_before_finally_keyword = true 419 | ij_php_space_before_finally_left_brace = true 420 | ij_php_space_before_for_left_brace = true 421 | ij_php_space_before_for_parentheses = true 422 | ij_php_space_before_for_semicolon = false 423 | ij_php_space_before_if_left_brace = true 424 | ij_php_space_before_if_parentheses = true 425 | ij_php_space_before_method_call_parentheses = false 426 | ij_php_space_before_method_left_brace = true 427 | ij_php_space_before_method_parentheses = false 428 | ij_php_space_before_quest = true 429 | ij_php_space_before_switch_left_brace = true 430 | ij_php_space_before_switch_parentheses = true 431 | ij_php_space_before_try_left_brace = true 432 | ij_php_space_before_unary_not = false 433 | ij_php_space_before_while_keyword = true 434 | ij_php_space_before_while_left_brace = true 435 | ij_php_space_before_while_parentheses = true 436 | ij_php_space_between_ternary_quest_and_colon = false 437 | ij_php_spaces_around_additive_operators = true 438 | ij_php_spaces_around_arrow = false 439 | ij_php_spaces_around_assignment_in_declare = false 440 | ij_php_spaces_around_assignment_operators = true 441 | ij_php_spaces_around_bitwise_operators = true 442 | ij_php_spaces_around_equality_operators = true 443 | ij_php_spaces_around_logical_operators = true 444 | ij_php_spaces_around_multiplicative_operators = true 445 | ij_php_spaces_around_null_coalesce_operator = true 446 | ij_php_spaces_around_relational_operators = true 447 | ij_php_spaces_around_shift_operators = true 448 | ij_php_spaces_around_unary_operator = false 449 | ij_php_spaces_around_var_within_brackets = false 450 | ij_php_spaces_within_array_initializer_braces = false 451 | ij_php_spaces_within_brackets = false 452 | ij_php_spaces_within_catch_parentheses = false 453 | ij_php_spaces_within_for_parentheses = false 454 | ij_php_spaces_within_if_parentheses = false 455 | ij_php_spaces_within_method_call_parentheses = false 456 | ij_php_spaces_within_method_parentheses = false 457 | ij_php_spaces_within_parentheses = false 458 | ij_php_spaces_within_short_echo_tags = true 459 | ij_php_spaces_within_switch_parentheses = false 460 | ij_php_spaces_within_while_parentheses = false 461 | ij_php_special_else_if_treatment = false 462 | ij_php_subpackage_weight = 28 463 | ij_php_ternary_operation_signs_on_next_line = false 464 | ij_php_ternary_operation_wrap = off 465 | ij_php_throws_weight = 6 466 | ij_php_todo_weight = 28 467 | ij_php_unknown_tag_weight = 28 468 | ij_php_upper_case_boolean_const = false 469 | ij_php_upper_case_null_const = false 470 | ij_php_uses_weight = 28 471 | ij_php_var_weight = 28 472 | ij_php_variable_naming_style = camel_case 473 | ij_php_version_weight = 28 474 | ij_php_while_brace_force = always 475 | ij_php_while_on_new_line = false 476 | 477 | [{*.js, *.cjs}] 478 | ij_continuation_indent_size = 4 479 | ij_javascript_align_imports = false 480 | ij_javascript_align_multiline_array_initializer_expression = true 481 | ij_javascript_align_multiline_binary_operation = false 482 | ij_javascript_align_multiline_chained_methods = false 483 | ij_javascript_align_multiline_extends_list = false 484 | ij_javascript_align_multiline_for = true 485 | ij_javascript_align_multiline_parameters = false 486 | ij_javascript_align_multiline_parameters_in_calls = false 487 | ij_javascript_align_multiline_ternary_operation = false 488 | ij_javascript_align_object_properties = 0 489 | ij_javascript_align_union_types = false 490 | ij_javascript_align_var_statements = 0 491 | ij_javascript_array_initializer_new_line_after_left_brace = true 492 | ij_javascript_array_initializer_right_brace_on_new_line = true 493 | ij_javascript_array_initializer_wrap = on_every_item 494 | ij_javascript_assignment_wrap = off 495 | ij_javascript_binary_operation_sign_on_next_line = false 496 | ij_javascript_binary_operation_wrap = off 497 | ij_javascript_blacklist_imports = rxjs/Rx, node_modules/**/*, @angular/material, @angular/material/typings/** 498 | ij_javascript_blank_lines_after_imports = 1 499 | ij_javascript_blank_lines_around_class = 1 500 | ij_javascript_blank_lines_around_field = 0 501 | ij_javascript_blank_lines_around_function = 1 502 | ij_javascript_blank_lines_around_method = 1 503 | ij_javascript_block_brace_style = end_of_line 504 | ij_javascript_call_parameters_new_line_after_left_paren = false 505 | ij_javascript_call_parameters_right_paren_on_new_line = false 506 | ij_javascript_call_parameters_wrap = normal 507 | ij_javascript_catch_on_new_line = false 508 | ij_javascript_chained_call_dot_on_new_line = false 509 | ij_javascript_class_brace_style = next_line 510 | ij_javascript_comma_on_new_line = false 511 | ij_javascript_do_while_brace_force = always 512 | ij_javascript_else_on_new_line = false 513 | ij_javascript_enforce_trailing_comma = whenmultiline 514 | ij_javascript_extends_keyword_wrap = off 515 | ij_javascript_extends_list_wrap = off 516 | ij_javascript_field_prefix = _ 517 | ij_javascript_file_name_style = relaxed 518 | ij_javascript_finally_on_new_line = false 519 | ij_javascript_for_brace_force = always 520 | ij_javascript_for_statement_new_line_after_left_paren = false 521 | ij_javascript_for_statement_right_paren_on_new_line = false 522 | ij_javascript_for_statement_wrap = off 523 | ij_javascript_force_quote_style = true 524 | ij_javascript_force_semicolon_style = true 525 | ij_javascript_function_expression_brace_style = end_of_line 526 | ij_javascript_if_brace_force = always 527 | ij_javascript_import_merge_members = global 528 | ij_javascript_import_prefer_absolute_path = global 529 | ij_javascript_import_sort_members = true 530 | ij_javascript_import_sort_module_name = false 531 | ij_javascript_import_use_node_resolution = true 532 | ij_javascript_imports_wrap = on_every_item 533 | ij_javascript_indent_case_from_switch = true 534 | ij_javascript_indent_chained_calls = true 535 | ij_javascript_indent_package_children = 0 536 | ij_javascript_jsx_attribute_value = braces 537 | ij_javascript_keep_blank_lines_in_code = 2 538 | ij_javascript_keep_first_column_comment = false 539 | ij_javascript_keep_indents_on_empty_lines = false 540 | ij_javascript_keep_line_breaks = true 541 | ij_javascript_keep_simple_blocks_in_one_line = false 542 | ij_javascript_keep_simple_methods_in_one_line = false 543 | ij_javascript_line_comment_add_space = true 544 | ij_javascript_line_comment_at_first_column = false 545 | ij_javascript_method_brace_style = next_line 546 | ij_javascript_method_call_chain_wrap = off 547 | ij_javascript_method_parameters_new_line_after_left_paren = true 548 | ij_javascript_method_parameters_right_paren_on_new_line = true 549 | ij_javascript_method_parameters_wrap = on_every_item 550 | ij_javascript_object_literal_wrap = on_every_item 551 | ij_javascript_parentheses_expression_new_line_after_left_paren = false 552 | ij_javascript_parentheses_expression_right_paren_on_new_line = false 553 | ij_javascript_place_assignment_sign_on_next_line = false 554 | ij_javascript_prefer_as_type_cast = false 555 | ij_javascript_prefer_parameters_wrap = false 556 | ij_javascript_reformat_c_style_comments = false 557 | ij_javascript_space_after_colon = true 558 | ij_javascript_space_after_comma = true 559 | ij_javascript_space_after_dots_in_rest_parameter = false 560 | ij_javascript_space_after_generator_mult = true 561 | ij_javascript_space_after_property_colon = true 562 | ij_javascript_space_after_quest = true 563 | ij_javascript_space_after_type_colon = true 564 | ij_javascript_space_after_unary_not = false 565 | ij_javascript_space_before_async_arrow_lparen = true 566 | ij_javascript_space_before_catch_keyword = true 567 | ij_javascript_space_before_catch_left_brace = true 568 | ij_javascript_space_before_catch_parentheses = true 569 | ij_javascript_space_before_class_lbrace = true 570 | ij_javascript_space_before_class_left_brace = true 571 | ij_javascript_space_before_colon = true 572 | ij_javascript_space_before_comma = false 573 | ij_javascript_space_before_do_left_brace = true 574 | ij_javascript_space_before_else_keyword = true 575 | ij_javascript_space_before_else_left_brace = true 576 | ij_javascript_space_before_finally_keyword = true 577 | ij_javascript_space_before_finally_left_brace = true 578 | ij_javascript_space_before_for_left_brace = true 579 | ij_javascript_space_before_for_parentheses = true 580 | ij_javascript_space_before_for_semicolon = false 581 | ij_javascript_space_before_function_left_parenth = false 582 | ij_javascript_space_before_generator_mult = false 583 | ij_javascript_space_before_if_left_brace = true 584 | ij_javascript_space_before_if_parentheses = true 585 | ij_javascript_space_before_method_call_parentheses = false 586 | ij_javascript_space_before_method_left_brace = true 587 | ij_javascript_space_before_method_parentheses = false 588 | ij_javascript_space_before_property_colon = false 589 | ij_javascript_space_before_quest = true 590 | ij_javascript_space_before_switch_left_brace = true 591 | ij_javascript_space_before_switch_parentheses = true 592 | ij_javascript_space_before_try_left_brace = true 593 | ij_javascript_space_before_type_colon = false 594 | ij_javascript_space_before_unary_not = false 595 | ij_javascript_space_before_while_keyword = true 596 | ij_javascript_space_before_while_left_brace = true 597 | ij_javascript_space_before_while_parentheses = true 598 | ij_javascript_spaces_around_additive_operators = true 599 | ij_javascript_spaces_around_arrow_function_operator = true 600 | ij_javascript_spaces_around_assignment_operators = true 601 | ij_javascript_spaces_around_bitwise_operators = true 602 | ij_javascript_spaces_around_equality_operators = true 603 | ij_javascript_spaces_around_logical_operators = true 604 | ij_javascript_spaces_around_multiplicative_operators = true 605 | ij_javascript_spaces_around_relational_operators = true 606 | ij_javascript_spaces_around_shift_operators = true 607 | ij_javascript_spaces_around_unary_operator = false 608 | ij_javascript_spaces_within_array_initializer_brackets = false 609 | ij_javascript_spaces_within_brackets = false 610 | ij_javascript_spaces_within_catch_parentheses = false 611 | ij_javascript_spaces_within_for_parentheses = false 612 | ij_javascript_spaces_within_if_parentheses = false 613 | ij_javascript_spaces_within_imports = false 614 | ij_javascript_spaces_within_interpolation_expressions = false 615 | ij_javascript_spaces_within_method_call_parentheses = false 616 | ij_javascript_spaces_within_method_parentheses = false 617 | ij_javascript_spaces_within_object_literal_braces = false 618 | ij_javascript_spaces_within_object_type_braces = true 619 | ij_javascript_spaces_within_parentheses = false 620 | ij_javascript_spaces_within_switch_parentheses = false 621 | ij_javascript_spaces_within_type_assertion = false 622 | ij_javascript_spaces_within_union_types = true 623 | ij_javascript_spaces_within_while_parentheses = false 624 | ij_javascript_special_else_if_treatment = false 625 | ij_javascript_ternary_operation_signs_on_next_line = false 626 | ij_javascript_ternary_operation_wrap = off 627 | ij_javascript_union_types_wrap = on_every_item 628 | ij_javascript_use_chained_calls_group_indents = false 629 | ij_javascript_use_double_quotes = false 630 | ij_javascript_use_explicit_js_extension = global 631 | ij_javascript_use_path_mapping = always 632 | ij_javascript_use_public_modifier = false 633 | ij_javascript_use_semicolon_after_statement = true 634 | ij_javascript_var_declaration_wrap = normal 635 | ij_javascript_while_brace_force = always 636 | ij_javascript_while_on_new_line = false 637 | ij_javascript_wrap_comments = false 638 | 639 | [{*.sht, *.html, *.shtm, *.shtml, *.htm}] 640 | ij_continuation_indent_size = 4 641 | ij_html_add_new_line_before_tags = body, div, p, form, h1, h2, h3 642 | ij_html_align_attributes = true 643 | ij_html_align_text = false 644 | ij_html_attribute_wrap = normal 645 | ij_html_block_comment_at_first_column = true 646 | ij_html_do_not_align_children_of_min_lines = 0 647 | ij_html_do_not_break_if_inline_tags = title, h1, h2, h3, h4, h5, h6, p 648 | ij_html_do_not_indent_children_of_tags = html, body, thead, tbody, tfoot 649 | ij_html_enforce_quotes = false 650 | 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 651 | ij_html_keep_blank_lines = 2 652 | ij_html_keep_indents_on_empty_lines = false 653 | ij_html_keep_line_breaks = true 654 | ij_html_keep_line_breaks_in_text = true 655 | ij_html_keep_whitespaces = false 656 | ij_html_keep_whitespaces_inside = span, pre, textarea 657 | ij_html_line_comment_at_first_column = true 658 | ij_html_new_line_after_last_attribute = never 659 | ij_html_new_line_before_first_attribute = never 660 | ij_html_quote_style = double 661 | ij_html_remove_new_line_before_tags = br 662 | ij_html_space_after_tag_name = false 663 | ij_html_space_around_equality_in_attribute = false 664 | ij_html_space_inside_empty_tag = false 665 | ij_html_text_wrap = normal 666 | 667 | [{*.yml, *.yaml}] 668 | indent_size = 2 669 | ij_continuation_indent_size = 2 670 | ij_yaml_keep_indents_on_empty_lines = false 671 | ij_yaml_keep_line_breaks = true 672 | 673 | [{*.zsh, *.sh, *.bash}] 674 | ij_shell_binary_ops_start_line = false 675 | ij_shell_keep_column_alignment_padding = false 676 | ij_shell_minify_program = false 677 | ij_shell_redirect_followed_by_space = false 678 | ij_shell_switch_cases_indented = false 679 | 680 | [{.babelrc, .stylelintrc, .eslintrc, jest.config, *.json, *.jsb3, *.jsb2, *.bowerrc}] 681 | ij_continuation_indent_size = 4 682 | ij_json_keep_blank_lines_in_code = 2 683 | ij_json_keep_indents_on_empty_lines = false 684 | ij_json_keep_line_breaks = true 685 | ij_json_space_after_colon = true 686 | ij_json_space_after_comma = true 687 | ij_json_space_before_colon = true 688 | ij_json_space_before_comma = false 689 | ij_json_spaces_within_braces = false 690 | ij_json_spaces_within_brackets = false 691 | ij_json_wrap_long_lines = false 692 | 693 | [{phpunit.xml.dist, *.xslt, *.xul, *.rng, *.xsl, *.xsd, *.ant, *.jhm, *.xml, *.tld, *.fxml, *.wsdl, *.jrxml, *.jnlp}] 694 | ij_xml_block_comment_at_first_column = true 695 | ij_xml_keep_indents_on_empty_lines = false 696 | ij_xml_line_comment_at_first_column = true 697 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Yao 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # laravel-sensitive 2 | 3 | 敏感词检查及过滤扩展包 4 | 5 | 6 | ## 特点 7 | 8 | - 采用 DFA 算法 9 | - **可配置使用缓存**,减少重复构建敏感词库集合,减少资源占用 10 | - **支持非 Laravel 框架**(不使用缓存功能,或者自定义缓存类) 11 | - 可通过配置文件管理配置,也可动态修改配置 12 | - 使用缓存时,修改配置后可通过命令行更新缓存 13 | - 使用 Facade 时,IDE 也能完美提示 14 | 15 | 16 | ## 系统要求 17 | 18 | - php 7.1 及以上版本 19 | - mbstring 扩展 20 | - composer 21 | 22 | 23 | ## 安装 24 | 25 | 通过 composer 安装 26 | 27 | ```bash 28 | composer require sydante/laravel-sensitive 29 | ``` 30 | 31 | 32 | ## 初始 33 | 34 | #### Laravel 35 | 36 | Laravel 使用包自动发现,所以不需要手动添加服务提供器 37 | 38 | 如果你没有使用自动发现,就必须手动添加服务提供器到 `config/app.php` 的 providers 数组中: 39 | 40 | ```php 41 | 'providers' => [ 42 | //... 43 | Sydante\LaravelSensitive\ServiceProvider::class, 44 | ], 45 | ``` 46 | 47 | 如果你想使用 facade,添加如下代码到 `config/app.php` 的 aliases 数组中: 48 | 49 | ```php 50 | 'aliases' => [ 51 | //... 52 | 'Sensitive' => Sydante\LaravelSensitive\Facades\Sensitive::class, 53 | ], 54 | ``` 55 | 56 | 57 | ## 添加配置 58 | 59 | #### Laravel 60 | 61 | 在项目目录下,使用如下命令发布配置: 62 | 63 | ```bash 64 | php artisan vendor:publish --provider="Sydante\LaravelSensitive\ServiceProvider" 65 | ``` 66 | 67 | 之后可以在 `.env` 中设置 `SENSITIVE_CACHE` 为 `true` 来开启缓存功能 68 | 69 | #### 其他框架 70 | 71 | 可在实例化 `Sydante\LaravelSensitive\Sensitive` 时自行传入配置 72 | 73 | 74 | ## 更新缓存 75 | 76 | 在使用缓存时,如果修改了敏感词配置 `words` 或 `file` 或者修改了 `file` 配置的文件的内容时,需要通过如下命令更新缓存: 77 | 78 | > 如果缓存了配置,需先更新配置缓存:`php artisan config:cache` 79 | 80 | ```bash 81 | # 更新缓存 82 | php artisan sensitive:cache 83 | ``` 84 | 85 | 也可清理缓存,缓存被清理后,在下次被使用时会根据配置自动重建缓存 86 | 87 | ```bash 88 | php artisan sensitive:clear 89 | ``` 90 | 91 | 92 | ## 使用 93 | 94 | #### 示例代码 95 | ```php 96 | // Laravel 可直接通过如下方式获取实例 97 | $sensitive = app(Sydante\LaravelSensitive\Sensitive::class); 98 | 99 | $sensitive->filter('这是一个示例'); 100 | 101 | // 或者使用 Facade 102 | \Sydante\LaravelSensitive\Facades\Sensitive::filter('这是一个示例'); 103 | 104 | 105 | // 其他骚操作: 106 | 107 | // 1、动态修改敏感词,并在使用缓存时缓存 108 | $sensitive->emptyTrieTreeMap() 109 | ->addWords(['test']) 110 | ->saveTrieTreeMap(); 111 | 112 | // 2、重置敏感词为初始化时的默认设置,并在使用缓存时缓存 113 | $sensitive->resetTrieTreeMap() 114 | ->saveTrieTreeMap(); 115 | ``` 116 | 117 | #### 可用方法包括: 118 | 119 | * `replaceCode(string $replaceCode): self` 设置替换字符串 120 | * `setDisturbs(array $disturbList = []): self` 设置干扰因子 121 | * `saveTrieTreeMap(): bool` 如果使用缓存的话,保存当前敏感词库集合到缓存中 122 | * `resetTrieTreeMap(): self` 使用配置中的设置重置当前的敏感词库集合 123 | * `emptyTrieTreeMap(): self` 清空敏感词库集合 124 | * `clearCache(): bool` 清理敏感词库集合缓存 125 | * `addWords(array $wordsList): self` 添加敏感词 126 | * `addWordsFromFile(string $filename): self` 从文件中读取并添加敏感词 127 | * `filter(string $text): string` 过滤敏感词 128 | * `search(string $text): array` 查找对应敏感词 129 | 130 | 131 | ## 在其他框架中使用 132 | 133 | #### 不使用缓存 134 | 135 | 在不使用缓存时,可以直接在其他框架中直接使用 `Sydante\LaravelSensitive\Sensitive`。 136 | 137 | #### 使用缓存 138 | 139 | 如果需要使用缓存功能,请自行编写实现了 `Sydante\LaravelSensitive\SensitiveCacheInterface` 接口的缓存类,在初始化 `implements SensitiveCacheInterface` 时传入类名到 `cache_class` 键中: 140 | 141 | ```php 142 | use Sydante\LaravelSensitive\Sensitive; 143 | use Sydante\LaravelSensitive\SensitiveCacheInterface; 144 | 145 | // 编写自定义的缓存类 146 | class CustomSensitiveCache implements SensitiveCacheInterface 147 | { 148 | // ... 149 | } 150 | 151 | // 使用 152 | $sensitive = new Sensitive([ 153 | 'cache' => true, 154 | 'words' => ['test'], 155 | // 使用自定义缓存类 156 | 'cache_class' => CustomSensitiveCache::class, 157 | ]); 158 | 159 | $sensitive->filter('我们来一个test'); // 我们来一个**** 160 | ``` 161 | 162 | 163 | ## 为什么要写这个包 164 | 165 | 在写这个包之前,我使用的是 [yankewei/laravel-sensitive](https://github.com/yankewei/laravel-sensitive),在此感谢此包提供的敏感词处理思路。不过在实际使用中,压测发现此包 IO 占用太高,且函数调用频繁: 166 | 167 | | 函数 | 调用次数 | 执行耗时 | CPU时间 | 内存占用 | 内存巅峰 | 168 | |---------------------------------------------------|-------|--------|--------|---------|---------| 169 | | mb_substr | 21099 | 13.9ms | 28μs | 660.0KB | 161.4KB | 170 | | str_replace | 5858 | 4.2ms | 10μs | 213.9KB | 136.0KB | 171 | | mb_strlen | 5771 | 3.4ms | 2μs | 1.1KB | 112Bit | 172 | | Yankewei\LaravelSensitive\Sensitive::getGeneretor | 5771 | 0μs | 56.4ms | 0Bit | 0Bit | 173 | | feof | 5770 | 0μs | 9.4ms | 0Bit | 0Bit | 174 | | fgets | 5769 | 0μs | 9.9ms | 0Bit | 0Bit | 175 | 176 | 遂打算自己重写,将生成的敏感词库集合缓存起来,优化掉读敏感词文件和生成敏感词集合的部分,一次生成,即可重复使用。 177 | 178 | 179 | ## Tips 180 | 181 | 可使用如下方式,来使干扰因子支持使用 `SENSITIVE_DISTURBS` 配置 182 | 183 | ```php 184 | // in config/sensitive.php 185 | 186 | // 获取设置的干扰因子 187 | $disturbs = env('SENSITIVE_DISTURBS'); 188 | 189 | if ($disturbs !== null) { 190 | // 将干扰因子解析成单个字符的列表 191 | $disturbs = array_values(array_unique( 192 | preg_split('//u', $disturbs) 193 | )); 194 | } 195 | 196 | return [ 197 | // 是否使用缓存,默认 false 198 | 'cache' => env('SENSITIVE_CACHE', false), 199 | 200 | // 干扰因子列表 201 | 'disturbs' => $disturbs, 202 | 203 | // ... 204 | ]; 205 | ``` 206 | 207 | > 如果缓存了配置,调整了 `SENSITIVE_DISTURBS` 后需要更新配置缓存:`php artisan config:cache` 208 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sydante/laravel-sensitive", 3 | "description": "敏感词检查及过滤扩展包,采用 DFA 算法;可配置使用缓存,减少运行时 IO 占用;支持任意框架", 4 | "type": "library", 5 | "require": { 6 | "php": ">=7.1", 7 | "ext-mbstring": "*" 8 | }, 9 | "license": "MIT", 10 | "authors": [ 11 | { 12 | "name": "Sy-Dante", 13 | "email": "sy40520@gmail.com" 14 | } 15 | ], 16 | "autoload": { 17 | "psr-4": { 18 | "Sydante\\LaravelSensitive\\": "src" 19 | } 20 | }, 21 | "extra": { 22 | "laravel": { 23 | "providers": [ 24 | "Sydante\\LaravelSensitive\\ServiceProvider" 25 | ], 26 | "aliases": { 27 | "Sensitive": "Sydante\\LaravelSensitive\\Facades\\Sensitive" 28 | } 29 | } 30 | }, 31 | "minimum-stability": "stable", 32 | "require-dev": { 33 | "phpunit/phpunit": "^9.3", 34 | "orchestra/testbench": "^5.5" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Commands/ClearCache.php: -------------------------------------------------------------------------------- 1 | clearCache()) { 36 | $this->info('Clear cache success.'); 37 | } else { 38 | $this->error('Please configure the cache value to true!'); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Commands/UpdateCache.php: -------------------------------------------------------------------------------- 1 | resetTrieTreeMap()->saveTrieTreeMap()) { 38 | $this->info('Cache success.'); 39 | } else { 40 | $this->error('Please configure the cache value to true!'); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Exceptions/CacheException.php: -------------------------------------------------------------------------------- 1 | config = $config; 69 | 70 | $this->useCache = $config['cache'] ?? false; 71 | 72 | if (isset($config['replace_code'])) { 73 | $this->setReplaceCode($config['replace_code']); 74 | } 75 | 76 | if (isset($config['disturbs'])) { 77 | $this->setDisturbs($config['disturbs']); 78 | } 79 | 80 | // 是否使用缓存 81 | if ($this->useCache) { 82 | // 缓存类 83 | $cacheCls = $config['cache_class'] ?? SensitiveCache::class; 84 | 85 | if (!class_exists($cacheCls)) { 86 | throw new CacheException('cache class not exists'); 87 | } 88 | 89 | $cache = new $cacheCls(); 90 | 91 | if ($cache instanceof SensitiveCacheInterface) { 92 | $cache->setKey($config['cache_key'] ?? md5(__CLASS__)); 93 | 94 | $this->cache = $cache; 95 | 96 | // 有缓存就使用缓存 97 | if ($trieTreeMap = $cache->get()) { 98 | $this->trieTreeMap = $trieTreeMap; 99 | return; 100 | } 101 | } else { 102 | throw new CacheException( 103 | 'cache not implement SensitiveCacheInterface' 104 | ); 105 | } 106 | } 107 | 108 | // 没缓存就加载配置中的敏感词设置,并在使用缓存时更新缓存 109 | $this->resetTrieTreeMap() 110 | ->saveTrieTreeMap(); 111 | } 112 | 113 | /** 114 | * 设置替换字符串 115 | * 116 | * @param string $replaceCode 117 | * 118 | * @return Sensitive 119 | */ 120 | public function setReplaceCode(string $replaceCode): self 121 | { 122 | $this->replaceCode = $replaceCode; 123 | 124 | return $this; 125 | } 126 | 127 | /** 128 | * 设置干扰因子 129 | * 130 | * @param array $disturbList 131 | * 132 | * @return Sensitive 133 | */ 134 | public function setDisturbs(array $disturbList = []): self 135 | { 136 | $this->disturbList = $disturbList; 137 | 138 | return $this; 139 | } 140 | 141 | /** 142 | * 如果使用缓存的话,保存当前敏感词库集合到缓存中 143 | * 144 | * @throws CacheException 145 | */ 146 | public function saveTrieTreeMap(): bool 147 | { 148 | if ($this->useCache) { 149 | if ($this->cache->set($this->trieTreeMap)) { 150 | return true; 151 | } 152 | 153 | throw new CacheException('save cache failed'); 154 | } 155 | 156 | return false; 157 | } 158 | 159 | /** 160 | * 使用配置中的设置重置当前的敏感词库集合 161 | * 162 | * @return Sensitive 163 | * @throws FileReadException 164 | */ 165 | public function resetTrieTreeMap(): Sensitive 166 | { 167 | $this->emptyTrieTreeMap(); 168 | 169 | $config = $this->config; 170 | 171 | if (isset($config['words'])) { 172 | $this->addWords($config['words']); 173 | } 174 | 175 | if (isset($config['file'])) { 176 | $this->addWordsFromFile($config['file']); 177 | } 178 | 179 | return $this; 180 | } 181 | 182 | /** 183 | * 清空敏感词库集合 184 | */ 185 | public function emptyTrieTreeMap(): Sensitive 186 | { 187 | $this->trieTreeMap = []; 188 | 189 | return $this; 190 | } 191 | 192 | /** 193 | * 清理敏感词库集合缓存 194 | * 195 | * @return bool 196 | * @throws CacheException 197 | */ 198 | public function clearCache(): bool 199 | { 200 | if ($this->useCache) { 201 | if ($this->cache->clear()) { 202 | return true; 203 | } 204 | 205 | throw new CacheException('clear cache failed'); 206 | } 207 | 208 | return false; 209 | } 210 | 211 | /** 212 | * 添加敏感词 213 | * 214 | * @param array $wordsList 215 | * 216 | * @return Sensitive 217 | */ 218 | public function addWords(array $wordsList): Sensitive 219 | { 220 | foreach ($wordsList as $words) { 221 | $this->addToTree($words); 222 | } 223 | 224 | return $this; 225 | } 226 | 227 | /** 228 | * 将敏感词加入敏感词库集合中 229 | * 230 | * @param string $words 231 | */ 232 | private function addToTree(string $words): void 233 | { 234 | $words = trim($words, " \t\n\r\0\x0B'\"`"); 235 | 236 | if (!$words) { 237 | return; 238 | } 239 | 240 | $nowWords = &$this->trieTreeMap; 241 | 242 | $len = mb_strlen($words); 243 | for ($i = 0; $i < $len; $i++) { 244 | $word = mb_substr($words, $i, 1); 245 | 246 | if (!isset($nowWords[$word])) { 247 | $nowWords[$word] = false; 248 | } 249 | 250 | $nowWords = &$nowWords[$word]; 251 | } 252 | } 253 | 254 | /** 255 | * 从文件中读取并添加敏感词 256 | * 257 | * @param string $filename 258 | * 259 | * @return Sensitive 260 | * @throws FileReadException 261 | */ 262 | public function addWordsFromFile(string $filename): Sensitive 263 | { 264 | foreach ($this->getWordsFromFile($filename) as $words) { 265 | $this->addToTree($words); 266 | } 267 | 268 | return $this; 269 | } 270 | 271 | /** 272 | * 使用生成器方式读取文件 273 | * 274 | * @param $filename 275 | * 276 | * @return Generator 277 | * @throws FileReadException 278 | */ 279 | private function getWordsFromFile(string $filename): Generator 280 | { 281 | if (!file_exists($filename)) { 282 | throw new FileReadException("file [{$filename}] not exists"); 283 | } 284 | 285 | $handle = fopen($filename, 'rb'); 286 | 287 | if (!$handle) { 288 | throw new FileReadException('read file failed'); 289 | } 290 | 291 | while (!feof($handle)) { 292 | yield fgets($handle); 293 | } 294 | 295 | fclose($handle); 296 | } 297 | 298 | /** 299 | * 过滤敏感词 300 | * 301 | * @param string $text 302 | * 303 | * @return string 304 | */ 305 | public function filter(string $text): string 306 | { 307 | $replaceCodeList = []; 308 | $wordsList = $this->search($text, true, $replaceCodeList); 309 | 310 | if (empty($wordsList)) { 311 | return $text; 312 | } 313 | 314 | return str_replace($wordsList, $replaceCodeList, $text); 315 | } 316 | 317 | /** 318 | * 查找对应敏感词 319 | * 320 | * @param string $text 321 | * @param bool $hasReplace 322 | * @param array $replaceCodeList 323 | * 324 | * @return array 325 | */ 326 | public function search( 327 | string $text, 328 | bool $hasReplace = false, 329 | array &$replaceCodeList = [] 330 | ): array { 331 | $wordsList = []; 332 | $textLength = mb_strlen($text); 333 | 334 | for ($i = 0; $i < $textLength; $i++) { 335 | $wordLength = $this->checkWord($text, $i, $textLength); 336 | 337 | if ($wordLength > 0) { 338 | $words = mb_substr($text, $i, $wordLength); 339 | $wordsList[] = $words; 340 | 341 | if ($hasReplace) { 342 | $replaceCodeList[] = str_repeat($this->replaceCode, mb_strlen($words)); 343 | } 344 | 345 | $i += $wordLength - 1; 346 | } 347 | } 348 | 349 | return $wordsList; 350 | } 351 | 352 | /** 353 | * 敏感词检测 354 | * 355 | * @param string $text 356 | * @param int $beginIndex 357 | * @param int $length 358 | * 359 | * @return int 360 | */ 361 | private function checkWord(string $text, int $beginIndex, int $length): int 362 | { 363 | $flag = false; 364 | $wordLength = 0; 365 | $trieTree = &$this->trieTreeMap; 366 | 367 | for ($i = $beginIndex; $i < $length; $i++) { 368 | $word = mb_substr($text, $i, 1); 369 | 370 | if ($this->isDisturb($word)) { 371 | $wordLength++; 372 | continue; 373 | } 374 | 375 | if (!isset($trieTree[$word])) { 376 | break; 377 | } 378 | 379 | $wordLength++; 380 | 381 | if ($trieTree[$word] !== false) { 382 | $trieTree = &$trieTree[$word]; 383 | } else { 384 | $flag = true; 385 | } 386 | } 387 | 388 | $flag || $wordLength = 0; 389 | 390 | return $wordLength; 391 | } 392 | 393 | /** 394 | * 是否为干扰因子 395 | * 396 | * @param string $word 397 | * 398 | * @return bool 399 | */ 400 | private function isDisturb(string $word): bool 401 | { 402 | return in_array($word, $this->disturbList, true); 403 | } 404 | } 405 | -------------------------------------------------------------------------------- /src/SensitiveCache.php: -------------------------------------------------------------------------------- 1 | key = $key; 14 | } 15 | 16 | public function get(): ?array 17 | { 18 | return Cache::get($this->key); 19 | } 20 | 21 | public function set(array $trieTreeMap): bool 22 | { 23 | return Cache::forever($this->key, $trieTreeMap); 24 | } 25 | 26 | public function clear(): bool 27 | { 28 | return Cache::forget($this->key); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/SensitiveCacheInterface.php: -------------------------------------------------------------------------------- 1 | publishes([ 25 | __DIR__ . '/config/sensitive.php' => config_path('sensitive.php'), 26 | ]); 27 | 28 | if ($this->app->runningInConsole()) { 29 | $this->commands([ 30 | UpdateCache::class, 31 | ClearCache::class, 32 | ]); 33 | } 34 | } 35 | 36 | /** 37 | * Register the application services. 38 | * 39 | * @return void 40 | */ 41 | public function register(): void 42 | { 43 | $this->app->singleton(Sensitive::class, function () { 44 | return new Sensitive(config('sensitive')); 45 | }); 46 | } 47 | 48 | /** 49 | * Get the services provided by the provider. 50 | * 51 | * @return array 52 | */ 53 | public function provides(): array 54 | { 55 | return [Sensitive::class, 'sensitive']; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/config/sensitive.php: -------------------------------------------------------------------------------- 1 | env('SENSITIVE_CACHE', false), 6 | 7 | // string|null 缓存类,需继承 SensitiveCacheInterface 8 | // 不设置时,使用默认缓存类 9 | 'cache_class' => null, 10 | 11 | // string|null 过滤时的替换字符,默认:* 12 | 'replace_code' => env('SENSITIVE_REPLACE_CODE'), 13 | 14 | // array|null 干扰因子列表 15 | 'disturbs' => null, 16 | 17 | // array|null 敏感词列表 18 | 'words' => null, 19 | 20 | // string|null 敏感词文件路径,文件内容必须是一行一个敏感词 21 | 'file' => null, 22 | ]; 23 | --------------------------------------------------------------------------------