* 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)
| 71 | * Returns `null` for strings that don't look like a FQCN. |
| 72 | */ |
| 73 | function lastSegment(fqcn: string): string | null { |
| 74 | const clean = fqcn.replace(/^\\+/, '').trim(); |
| 75 | if (!clean.includes('\\')) return null; |
| 76 | const parts = clean.split('\\'); |
| 77 | return parts[parts.length - 1] ?? null; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Derive the Drupal module name from a file path. |