* Helper: derive the parent folder key ("root" -> null, "foo/bar" -> "foo"). */
(string $key)
| 938 | * Helper: derive the parent folder key ("root" -> null, "foo/bar" -> "foo"). |
| 939 | */ |
| 940 | private static function parentKeyOf(string $key): ?string |
| 941 | { |
| 942 | if ($key === 'root' || $key === '') { |
| 943 | return null; |
| 944 | } |
| 945 | $key = trim($key, '/'); |
| 946 | if ($key === '') { |
| 947 | return null; |
| 948 | } |
| 949 | $pos = strrpos($key, '/'); |
| 950 | if ($pos === false) { |
| 951 | return 'root'; |
| 952 | } |
| 953 | $parent = substr($key, 0, $pos); |
| 954 | return ($parent === '' ? 'root' : $parent); |
| 955 | } |
| 956 | |
| 957 | /** |
| 958 | * Helper: basename of a folder key. "root" -> "root", "foo/bar" -> "bar". |