File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change 3939 "autoload" : {
4040 "psr-4" : {
4141 "Okapi\\ CodeTransformer\\ " : " src/"
42- }
42+ },
43+ "files" : [
44+ " src/functions.php"
45+ ]
4346 },
4447 "autoload-dev" : {
4548 "psr-4" : {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ if (!function_exists ('str_starts_with_any_but_not ' )) {
4+ /**
5+ * Determines if the given haystack starts with any of the provided needles,
6+ * but not with any of the provided negative needles.
7+ *
8+ * @param string $haystack The string to search in.
9+ * @param array $needles An array of strings to search for at the
10+ * beginning of the $haystack.
11+ * @param array $negativeNeedles An array of strings to ensure are not at
12+ * the beginning of $haystack.
13+ *
14+ * @return bool Returns {@link true} if $haystack starts with any string in
15+ * $needles, but not with any string in $negativeNeedles.
16+ * Returns {@link false} otherwise.
17+ */
18+ function str_starts_with_any_but_not (
19+ string $ haystack ,
20+ array $ needles ,
21+ array $ negativeNeedles = [],
22+ ): bool {
23+ // Check for negative needles first
24+ foreach ($ negativeNeedles as $ negativeNeedle ) {
25+ if (str_starts_with ($ haystack , $ negativeNeedle )) {
26+ return false ;
27+ }
28+ }
29+
30+ // Check for positive needles
31+ foreach ($ needles as $ needle ) {
32+ if (str_starts_with ($ haystack , $ needle )) {
33+ return true ;
34+ }
35+ }
36+
37+ return false ;
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments