Get the content of a file by URI, trying open files first then disk. This replaces the repeated pattern of locking `open_files`, looking up the URI, and falling back to reading from disk via `Url::to_file_path` + `std::fs::read_to_string`. Three call sites in the definition modules used this exact sequence.
(&self, uri: &str)
| 1497 | /// `Url::to_file_path` + `std::fs::read_to_string`. Three call sites |
| 1498 | /// in the definition modules used this exact sequence. |
| 1499 | pub(crate) fn get_file_content(&self, uri: &str) -> Option<String> { |
| 1500 | if let Some(content) = self.open_files.read().get(uri) { |
| 1501 | return Some(String::clone(content)); |
| 1502 | } |
| 1503 | |
| 1504 | // Embedded class stubs live under synthetic `phpantom-stub://` |
| 1505 | // URIs and have no on-disk file. Retrieve the raw source from |
| 1506 | // the stub_index keyed by the class short name (the URI path). |
| 1507 | if let Some(class_name) = uri.strip_prefix("phpantom-stub://") { |
| 1508 | let stub_idx = self.stub_index.read(); |
| 1509 | return stub_idx.get(class_name).map(|s| s.to_string()); |
| 1510 | } |
| 1511 | |
| 1512 | // Embedded function stubs use `phpantom-stub-fn://` URIs. |
| 1513 | // The path component is the function name used as key in |
| 1514 | // stub_function_index. |
| 1515 | if let Some(func_name) = uri.strip_prefix("phpantom-stub-fn://") { |
| 1516 | let stub_fn_idx = self.stub_function_index.read(); |
| 1517 | return stub_fn_idx.get(func_name).map(|s| s.to_string()); |
| 1518 | } |
| 1519 | |
| 1520 | let path = Url::parse(uri).ok()?.to_file_path().ok()?; |
| 1521 | std::fs::read_to_string(path).ok() |
| 1522 | } |
| 1523 | |
| 1524 | /// Retrieve file content as a cheap `Arc<String>` reference when the |
| 1525 | /// file is in `open_files`. Falls back to reading from disk (which |
no test coverage detected