From c772e00dfbe4dd10d06c2fe9cb2389158ddae744 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 12 May 2026 03:43:31 +0900 Subject: feat(port): port PlatformRequirementFilterFactory.php --- crates/shirabe-php-shim/src/lib.rs | 4 ++ .../platform_requirement_filter_factory.rs | 43 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs index ff9909d..42fb281 100644 --- a/crates/shirabe-php-shim/src/lib.rs +++ b/crates/shirabe-php-shim/src/lib.rs @@ -35,6 +35,10 @@ pub struct InvalidArgumentException { pub code: i64, } +pub fn get_debug_type(value: &PhpMixed) -> String { + todo!() +} + pub fn hash(algo: &str, data: &str) -> String { todo!() } diff --git a/crates/shirabe/src/filter/platform_requirement_filter/platform_requirement_filter_factory.rs b/crates/shirabe/src/filter/platform_requirement_filter/platform_requirement_filter_factory.rs index 4df8cde..8dda266 100644 --- a/crates/shirabe/src/filter/platform_requirement_filter/platform_requirement_filter_factory.rs +++ b/crates/shirabe/src/filter/platform_requirement_filter/platform_requirement_filter_factory.rs @@ -1 +1,44 @@ //! ref: composer/src/Composer/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactory.php + +use anyhow::Result; +use shirabe_php_shim::{InvalidArgumentException, PhpMixed}; +use crate::filter::platform_requirement_filter::{ + ignore_all_platform_requirement_filter::IgnoreAllPlatformRequirementFilter, + ignore_list_platform_requirement_filter::IgnoreListPlatformRequirementFilter, + ignore_nothing_platform_requirement_filter::IgnoreNothingPlatformRequirementFilter, + platform_requirement_filter_interface::PlatformRequirementFilterInterface, +}; + +pub struct PlatformRequirementFilterFactory; + +impl PlatformRequirementFilterFactory { + pub fn from_bool_or_list(bool_or_list: PhpMixed) -> Result> { + match bool_or_list { + PhpMixed::Bool(b) => { + if b { + Ok(Self::ignore_all()) + } else { + Ok(Self::ignore_nothing()) + } + } + list_or_array @ (PhpMixed::List(_) | PhpMixed::Array(_)) => { + Ok(Box::new(IgnoreListPlatformRequirementFilter::new(list_or_array))) + } + other => Err(anyhow::anyhow!(InvalidArgumentException { + message: format!( + "PlatformRequirementFilter: Unknown $boolOrList parameter {}. Please report at https://github.com/composer/composer/issues/new.", + shirabe_php_shim::get_debug_type(&other) + ), + code: 0, + })), + } + } + + pub fn ignore_all() -> Box { + Box::new(IgnoreAllPlatformRequirementFilter) + } + + pub fn ignore_nothing() -> Box { + Box::new(IgnoreNothingPlatformRequirementFilter) + } +} -- cgit v1.3.1