* Parse the last PHP namespace segment from a FQCN like `\Drupal\mymodule\Controller\Foo`. * Returns `null` for strings that don't look like a FQCN.
(fqcn: string)
| 60 | * Returns `null` for strings that don't look like a FQCN. |
| 61 | */ |
| 62 | function lastSegment(fqcn: string): string | null { |
| 63 | const clean = fqcn.replace(/^\\+/, '').trim(); |
| 64 | if (!clean.includes('\\')) return null; |
| 65 | const parts = clean.split('\\'); |
| 66 | return parts[parts.length - 1] ?? null; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Derive the Drupal module name from a file path. |