@@ -47,7 +47,7 @@ abstract class BlaspExpressionService
47
47
*
48
48
* @var array
49
49
*/
50
- protected array $ profanityExpressions ;
50
+ protected array $ profanityExpressions = [] ;
51
51
52
52
/**
53
53
* An array of separator expression profanities
@@ -82,24 +82,22 @@ abstract class BlaspExpressionService
82
82
*
83
83
* @var array
84
84
*/
85
- protected array $ falsePositives ;
85
+ protected array $ falsePositives = [] ;
86
86
87
87
/**
88
88
* @throws Exception
89
89
*/
90
- public function __construct (?string $ language = null )
90
+ public function __construct (?string $ language = null , ? array $ profanities = null , ? array $ falsePositives = null )
91
91
{
92
92
$ this ->chosenLanguage = $ language ;
93
93
94
- $ this ->loadConfiguration ();
94
+ $ this ->loadConfiguration ($ profanities , $ falsePositives );
95
95
96
96
$ this ->separatorExpression = $ this ->generateSeparatorExpression ();
97
97
98
98
$ this ->characterExpressions = $ this ->generateSubstitutionExpression ();
99
99
100
100
$ this ->generateProfanityExpressionArray ();
101
-
102
- $ this ->generateFalsePositiveExpressionArray ();
103
101
}
104
102
105
103
/**
@@ -108,7 +106,7 @@ public function __construct(?string $language = null)
108
106
*
109
107
* @throws Exception
110
108
*/
111
- private function loadConfiguration (): void
109
+ private function loadConfiguration (array $ profanities = null , array $ falsePositives = null ): void
112
110
{
113
111
$ this ->supportedLanguages = config ('blasp.languages ' );
114
112
@@ -117,10 +115,12 @@ private function loadConfiguration(): void
117
115
}
118
116
119
117
$ this ->validateChosenLanguage ();
120
-
121
- $ this ->profanities = config ('blasp.profanities ' );
118
+
119
+ $ this ->profanities = $ profanities ?? config ('blasp.profanities ' );
122
120
$ this ->separators = config ('blasp.separators ' );
123
121
$ this ->substitutions = config ('blasp.substitutions ' );
122
+
123
+ $ this ->generateFalsePositiveExpressionArray ($ falsePositives );
124
124
}
125
125
126
126
/**
@@ -211,9 +211,9 @@ private function generateProfanityExpression($profanity): string
211
211
*
212
212
* @return void
213
213
*/
214
- private function generateFalsePositiveExpressionArray (): void
214
+ private function generateFalsePositiveExpressionArray (array $ falsePositives = null ): void
215
215
{
216
- $ this ->falsePositives = array_map ('strtolower ' , config ('blasp.false_positives ' ));
216
+ $ this ->falsePositives = array_map ('strtolower ' , $ falsePositives ?? config ('blasp.false_positives ' ));
217
217
}
218
218
219
219
/**
0 commit comments