Skip to content

Commit e80dff7

Browse files
committed
feat: add new method for check string contains all substr
1 parent 6c87e81 commit e80dff7

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

src/Str/Traits/StringCheckHelperTrait.php

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,40 @@ public static function has(string $string, $needle): bool
8888
}
8989
}
9090
}
91-
9291
return false;
9392
}
9493

94+
/**
95+
* @param string $string
96+
* @param string|array $needle
97+
* @return bool
98+
*/
99+
public static function containsAll(string $string, $needle): bool
100+
{
101+
return self::hasAll($string, $needle);
102+
}
103+
104+
/**
105+
* @param string $string
106+
* @param string|array $needle
107+
* @return bool
108+
*/
109+
public static function hasAll(string $string, $needle): bool
110+
{
111+
if (is_string($needle)) {
112+
return str_contains($string, $needle);
113+
}
114+
115+
if (is_array($needle)) {
116+
foreach ((array)$needle as $item) {
117+
if (!str_contains($string, $item)) {
118+
return false;
119+
}
120+
}
121+
}
122+
return true;
123+
}
124+
95125
/**
96126
* Alias of the `ihas()`
97127
*
@@ -124,10 +154,32 @@ public static function ihas(string $string, $needle): bool
124154
}
125155
}
126156
}
127-
128157
return false;
129158
}
130159

160+
/**
161+
* Check all substr must in the haystack, will ignore case
162+
*
163+
* @param string $haystack
164+
* @param string|array $needle
165+
* @return bool
166+
*/
167+
public static function iHasAll(string $haystack, $needle): bool
168+
{
169+
if (is_string($needle)) {
170+
return stripos($haystack, $needle) !== false;
171+
}
172+
173+
if (is_array($needle)) {
174+
foreach ((array)$needle as $item) {
175+
if (stripos($haystack, $item) === false) {
176+
return false;
177+
}
178+
}
179+
}
180+
return true;
181+
}
182+
131183
/**
132184
* Alias of the `self::strpos()`
133185
*

src/Util/BaseStream.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Toolkit\Stdlib\Util;
4+
5+
/**
6+
* class BaseStream
7+
*/
8+
class BaseStream
9+
{
10+
// todo
11+
}

0 commit comments

Comments
 (0)