@@ -218,12 +218,16 @@ public static function camel($value)
218
218
* Determine if a given string contains a given substring.
219
219
*
220
220
* @param string $haystack
221
- * @param string|string[] $needles
221
+ * @param string|string[]|Enumerable<array-key, string> $needles
222
222
* @param bool $ignoreCase
223
223
* @return bool
224
224
*/
225
225
public static function contains ($ haystack , $ needles , $ ignoreCase = false )
226
226
{
227
+ if ($ needles instanceof Enumerable) {
228
+ $ needles = $ needles ->toArray ();
229
+ }
230
+
227
231
if ($ ignoreCase ) {
228
232
$ haystack = mb_strtolower ($ haystack );
229
233
$ needles = array_map ('mb_strtolower ' , (array ) $ needles );
@@ -242,12 +246,16 @@ public static function contains($haystack, $needles, $ignoreCase = false)
242
246
* Determine if a given string contains all array values.
243
247
*
244
248
* @param string $haystack
245
- * @param string[] $needles
249
+ * @param string[]|Enumerable<array-key, string> $needles
246
250
* @param bool $ignoreCase
247
251
* @return bool
248
252
*/
249
- public static function containsAll ($ haystack , array $ needles , $ ignoreCase = false )
253
+ public static function containsAll ($ haystack , $ needles , $ ignoreCase = false )
250
254
{
255
+ if ($ needles instanceof Enumerable) {
256
+ $ needles = $ needles ->toArray ();
257
+ }
258
+
251
259
if ($ ignoreCase ) {
252
260
$ haystack = mb_strtolower ($ haystack );
253
261
$ needles = array_map ('mb_strtolower ' , $ needles );
@@ -266,7 +274,7 @@ public static function containsAll($haystack, array $needles, $ignoreCase = fals
266
274
* Determine if a given string ends with a given substring.
267
275
*
268
276
* @param string $haystack
269
- * @param string|string[] $needles
277
+ * @param string|string[]|Enumerable<array-key, string> $needles
270
278
* @return bool
271
279
*/
272
280
public static function endsWith ($ haystack , $ needles )
@@ -781,12 +789,16 @@ public static function repeat(string $string, int $times)
781
789
* Replace a given value in the string sequentially with an array.
782
790
*
783
791
* @param string $search
784
- * @param array<int| string, string> $replace
792
+ * @param string[]|Enumerable<array-key , string> $replace
785
793
* @param string $subject
786
794
* @return string
787
795
*/
788
- public static function replaceArray ($ search , array $ replace , $ subject )
796
+ public static function replaceArray ($ search , $ replace , $ subject )
789
797
{
798
+ if ($ replace instanceof Enumerable) {
799
+ $ replace = $ replace ->toArray ();
800
+ }
801
+
790
802
$ segments = explode ($ search , $ subject );
791
803
792
804
$ result = array_shift ($ segments );
@@ -801,13 +813,25 @@ public static function replaceArray($search, array $replace, $subject)
801
813
/**
802
814
* Replace the given value in the given string.
803
815
*
804
- * @param string|string[] $search
805
- * @param string|string[] $replace
806
- * @param string|string[] $subject
816
+ * @param string|string[]|Enumerable<array-key, string> $search
817
+ * @param string|string[]|Enumerable<array-key, string> $replace
818
+ * @param string|string[]|Enumerable<array-key, string> $subject
807
819
* @return string
808
820
*/
809
821
public static function replace ($ search , $ replace , $ subject )
810
822
{
823
+ if ($ search instanceof Enumerable) {
824
+ $ search = $ search ->toArray ();
825
+ }
826
+
827
+ if ($ replace instanceof Enumerable) {
828
+ $ replace = $ replace ->toArray ();
829
+ }
830
+
831
+ if ($ subject instanceof Enumerable) {
832
+ $ subject = $ subject ->toArray ();
833
+ }
834
+
811
835
return str_replace ($ search , $ replace , $ subject );
812
836
}
813
837
@@ -862,13 +886,17 @@ public static function replaceLast($search, $replace, $subject)
862
886
/**
863
887
* Remove any occurrence of the given string in the subject.
864
888
*
865
- * @param string|array< string> $search
889
+ * @param string|string[]|Enumerable<array-key, string> $search
866
890
* @param string $subject
867
891
* @param bool $caseSensitive
868
892
* @return string
869
893
*/
870
894
public static function remove ($ search , $ subject , $ caseSensitive = true )
871
895
{
896
+ if ($ search instanceof Enumerable) {
897
+ $ search = $ search ->toArray ();
898
+ }
899
+
872
900
$ subject = $ caseSensitive
873
901
? str_replace ($ search , '' , $ subject )
874
902
: str_ireplace ($ search , '' , $ subject );
@@ -1021,7 +1049,7 @@ public static function squish($value)
1021
1049
* Determine if a given string starts with a given substring.
1022
1050
*
1023
1051
* @param string $haystack
1024
- * @param string|string[] $needles
1052
+ * @param string|string[]|Enumerable<array-key, string> $needles
1025
1053
* @return bool
1026
1054
*/
1027
1055
public static function startsWith ($ haystack , $ needles )
0 commit comments