Extract file paths from `require_once` statements in PHP source content. Handles both the statement form and the function-like form: ```text require_once 'Trustly/exceptions.php'; require_once('Trustly/Data/data.php'); ``` Only bare string literals are supported — concatenations, variables, and other dynamic expressions are silently skipped. Returns the raw path strings exactly as written in th
(content: &str)
| 441 | /// `"Trustly/exceptions.php"`). The caller is responsible for resolving |
| 442 | /// them relative to the file's directory. |
| 443 | pub fn extract_require_once_paths(content: &str) -> Vec<String> { |
| 444 | let mut paths = Vec::new(); |
| 445 | |
| 446 | for line in content.lines() { |
| 447 | let trimmed = line.trim(); |
| 448 | |
| 449 | // Quick reject: line must start with `require_once`. |
| 450 | // (We don't support `require_once` buried in complex expressions.) |
| 451 | if !trimmed.starts_with("require_once") { |
| 452 | continue; |
| 453 | } |
| 454 | |
| 455 | let rest = trimmed["require_once".len()..].trim_start(); |
| 456 | |
| 457 | // Strip optional parentheses: `require_once('...')` → `'...'` |
| 458 | // Also handles `require_once '...'` without parens. |
| 459 | let rest = if let Some(inner) = rest.strip_prefix('(') { |
| 460 | // Find matching closing paren |
| 461 | if let Some(end) = inner.rfind(')') { |
| 462 | inner[..end].trim() |
| 463 | } else { |
| 464 | continue; |
| 465 | } |
| 466 | } else { |
| 467 | rest |
| 468 | }; |
| 469 | |
| 470 | // Strip trailing semicolon |
| 471 | let rest = rest.trim_end_matches(';').trim(); |
| 472 | |
| 473 | // Extract string literal — single or double quoted |
| 474 | let path = if (rest.starts_with('\'') && rest.ends_with('\'')) |
| 475 | || (rest.starts_with('"') && rest.ends_with('"')) |
| 476 | { |
| 477 | &rest[1..rest.len() - 1] |
| 478 | } else { |
| 479 | // Not a simple string literal — skip |
| 480 | continue; |
| 481 | }; |
| 482 | |
| 483 | if !path.is_empty() { |
| 484 | paths.push(path.to_string()); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | paths |
| 489 | } |
| 490 | |
| 491 | /// Parse `<vendor>/composer/autoload_namespaces.php` (PSR-0 map) and |
| 492 | /// scan the listed directories for PHP classes. |