Retrieve file content as a cheap `Arc ` reference when the file is in `open_files`. Falls back to reading from disk (which wraps the result in a new `Arc`). Prefer this over [`get_file_content`] in hot paths where the content will be shared across tasks or stored for the duration of a request, since it avoids deep-cloning the file string.
(&self, uri: &str)
| 1529 | /// content will be shared across tasks or stored for the duration |
| 1530 | /// of a request, since it avoids deep-cloning the file string. |
| 1531 | pub(crate) fn get_file_content_arc(&self, uri: &str) -> Option<Arc<String>> { |
| 1532 | if let Some(content) = self.open_files.read().get(uri) { |
| 1533 | return Some(Arc::clone(content)); |
| 1534 | } |
| 1535 | |
| 1536 | // Embedded class stubs live under synthetic `phpantom-stub://` |
| 1537 | // URIs and have no on-disk file. |
| 1538 | if let Some(class_name) = uri.strip_prefix("phpantom-stub://") { |
| 1539 | let stub_idx = self.stub_index.read(); |
| 1540 | return stub_idx.get(class_name).map(|s| Arc::new(s.to_string())); |
| 1541 | } |
| 1542 | |
| 1543 | // Embedded function stubs use `phpantom-stub-fn://` URIs. |
| 1544 | if let Some(func_name) = uri.strip_prefix("phpantom-stub-fn://") { |
| 1545 | let stub_fn_idx = self.stub_function_index.read(); |
| 1546 | return stub_fn_idx.get(func_name).map(|s| Arc::new(s.to_string())); |
| 1547 | } |
| 1548 | |
| 1549 | let path = Url::parse(uri).ok()?.to_file_path().ok()?; |
| 1550 | std::fs::read_to_string(path).ok().map(Arc::new) |
| 1551 | } |
| 1552 | |
| 1553 | /// Public helper for tests: get the uri_classes_index entry for a given URI. |
| 1554 | pub fn get_classes_for_uri(&self, uri: &str) -> Option<Vec<ClassInfo>> { |
no test coverage detected