aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/json/json_file.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-02 20:11:51 +0900
committernsfisis <nsfisis@gmail.com>2026-08-02 20:11:51 +0900
commitc2a2bd3a2573f585c902c39bd28b8c3cad10c317 (patch)
treeaa8138a0570966f26e3708b500041258074dcd24 /crates/shirabe/src/json/json_file.rs
parent7db937af313d857d0f66bebaf8ac72d518559bac (diff)
downloadphp-shirabe-c2a2bd3a2573f585c902c39bd28b8c3cad10c317.tar.gz
php-shirabe-c2a2bd3a2573f585c902c39bd28b8c3cad10c317.tar.zst
php-shirabe-c2a2bd3a2573f585c902c39bd28b8c3cad10c317.zip
fix(repository): resolve remaining late-binding hazards from the audit
Three fixes for the ComposerRepository/FilesystemRepository/PlatformRepository hazards where inner-composition delegation skipped PHP's late-bound virtual dispatch: - ComposerRepository::has_package now builds its packageMap through the late-bound getPackages() equivalent, so lazy-providers repos surface the LogicException and available-packages repos load their package list, as in PHP, instead of silently answering false from the raw array. - RepositoryInterface::get_repo_name returns anyhow::Result<String>: PHP's getRepoName() counts through the late-bound initialize(), which is fallible in file-reading subclasses. FilesystemRepository and PackageRepository now run that initialization instead of freezing the inner array repository to an empty state (which also made a later write() truncate installed.json). Supporting changes keep the initialization chain callable from &self: JsonFile::read takes &self (indent moved into a RefCell), FilesystemRepository dev_mode became a Cell, and WritableArrayRepository dev_package_names a RefCell. - PlatformRepository::new routes constructor packages through its own add_package so the override handling and full platform initialization run as they do via PHP's parent constructor; the inner find_package/add_package delegations inside add_package (and ComposerRepository::add_package) gained the same is_initialized guard, since the constructor path would otherwise freeze the repository. Same defect class as 7db937af, 97b5211a and 3e367f78. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/json/json_file.rs')
-rw-r--r--crates/shirabe/src/json/json_file.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs
index 632519a7..e37ba10c 100644
--- a/crates/shirabe/src/json/json_file.rs
+++ b/crates/shirabe/src/json/json_file.rs
@@ -72,7 +72,9 @@ pub struct JsonFile {
/// @var ?IOInterface
io: Option<std::rc::Rc<std::cell::RefCell<dyn IOInterface>>>,
/// @var string
- indent: String,
+ // RefCell so that read() can stay `&self`: PHP's late-bound repository initialize()
+ // chains (getRepoName -> count -> initialize -> file read) run from shared contexts.
+ indent: std::cell::RefCell<String>,
}
impl JsonFile {
@@ -116,7 +118,7 @@ impl JsonFile {
path,
http_downloader,
io,
- indent: Self::INDENT_DEFAULT.to_string(),
+ indent: std::cell::RefCell::new(Self::INDENT_DEFAULT.to_string()),
})
}
@@ -134,7 +136,7 @@ impl JsonFile {
/// @throws ParsingException
/// @throws \RuntimeException
/// @return mixed
- pub fn read(&mut self) -> anyhow::Result<PhpMixed> {
+ pub fn read(&self) -> anyhow::Result<PhpMixed> {
let json: Option<String> = match (|| -> anyhow::Result<Option<String>> {
if let Some(http_downloader) = &self.http_downloader {
Ok(http_downloader
@@ -198,7 +200,7 @@ impl JsonFile {
}
};
- self.indent = Self::detect_indenting(Some(&json));
+ *self.indent.borrow_mut() = Self::detect_indenting(Some(&json));
Self::parse_json(Some(&json), Some(&self.path))
}
@@ -213,7 +215,7 @@ impl JsonFile {
options: JsonEncodeOptions,
) -> anyhow::Result<()> {
let options = JsonEncodeOptions {
- indent: self.indent.clone(),
+ indent: self.indent.borrow().clone(),
..options
};