1 | <?php |
||
2 | |||
3 | namespace Simply\Router; |
||
4 | |||
5 | /** |
||
6 | * Splits the given path into nonempty segments. |
||
7 | * @param string $path The path to split |
||
8 | * @return string[] The non empty segments from the path |
||
9 | */ |
||
10 | function split_segments(string $path): array |
||
11 | { |
||
12 | 30 | return string_split('#/#', $path); |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
13 | } |
||
14 | |||
15 | /** |
||
16 | * Splits the string into parts using regular expressions and returns nonempty parts. |
||
17 | * @param string $pattern The pattern to use for splitting |
||
18 | * @param string $subject The string to split |
||
19 | * @return string[] Split parts from the string |
||
20 | */ |
||
21 | function string_split(string $pattern, string $subject): array |
||
22 | { |
||
23 | 31 | $parts = preg_split($pattern, $subject, -1, \PREG_SPLIT_NO_EMPTY); |
|
24 | |||
25 | 31 | if (!\is_array($parts) || preg_last_error() !== \PREG_NO_ERROR) { |
|
26 | 1 | throw new \RuntimeException('Error splitting string'); |
|
27 | } |
||
28 | |||
29 | 30 | return $parts; |
|
0 ignored issues
–
show
|
|||
30 | } |
||
31 |