public static function Inspector::assertAllMatch in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Component/Assertion/Inspector.php \Drupal\Component\Assertion\Inspector::assertAllMatch()
Asserts that all members are strings that contain the specified string.
This runs faster than the regular expression equivalent.
Parameters
string $pattern: The needle to find.
mixed $traversable: Variable to examine.
bool $case_sensitive: TRUE to use strstr(), FALSE to use stristr() which is case insensitive.
Return value
bool TRUE if $traversable can be traversed and all members are strings containing $pattern.
1 call to Inspector::assertAllMatch()
- InspectorTest::testAssertAllMatch in core/
tests/ Drupal/ Tests/ Component/ Assertion/ InspectorTest.php - Tests asserting strstr() or stristr() match.
File
- core/
lib/ Drupal/ Component/ Assertion/ Inspector.php, line 313
Class
Namespace
Drupal\Component\AssertionCode
public static function assertAllMatch($pattern, $traversable, $case_sensitive = FALSE) {
if (static::assertTraversable($traversable)) {
if ($case_sensitive) {
foreach ($traversable as $member) {
if (!(is_string($member) && strstr($member, $pattern))) {
return FALSE;
}
}
}
else {
foreach ($traversable as $member) {
if (!(is_string($member) && stristr($member, $pattern))) {
return FALSE;
}
}
}
return TRUE;
}
return FALSE;
}