aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/dependency_resolver
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-07-25 12:16:25 +0900
committernsfisis <nsfisis@gmail.com>2026-07-25 12:16:25 +0900
commit42b5f9e321c918cef542c120ad21ba8a7339eb29 (patch)
tree39f2b5a3cb856de9068f72fb670d170c09a2438f /crates/shirabe/src/dependency_resolver
parentf93d9b49382c8f79fcea4f03361d50bda534bcc4 (diff)
downloadphp-shirabe-42b5f9e321c918cef542c120ad21ba8a7339eb29.tar.gz
php-shirabe-42b5f9e321c918cef542c120ad21ba8a7339eb29.tar.zst
php-shirabe-42b5f9e321c918cef542c120ad21ba8a7339eb29.zip
refactor(operation): replace OperationInterface with AnyOperation enum
Operations are only ever constructed by the dependency resolver, so a plugin has no way to inject an implementation of its own and the set is closed. Modelling it as an enum, like AnyPackage, removes the OperationInterface trait together with its two parallel downcast mechanisms (as_any() + downcast_ref, and as_*_operation()) and the get_package() default method that panicked on UpdateOperation. The PHP idiom `$op instanceof UpdateOperation ? getTargetPackage() : getPackage()`, written out at six call sites, becomes AnyOperation::get_target_package(). InstallationManager's three blocks that matched on the type string and then recovered the type with expect() collapse into exhaustive matches. SolverOperation keeps only its TYPE constant; the shared getOperationType()/__toString() implementations move to AnyOperation, which also drops the five Self::TYPE.to_string() allocations. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/dependency_resolver')
-rw-r--r--crates/shirabe/src/dependency_resolver/local_repo_transaction.rs4
-rw-r--r--crates/shirabe/src/dependency_resolver/lock_transaction.rs4
-rw-r--r--crates/shirabe/src/dependency_resolver/operation.rs4
-rw-r--r--crates/shirabe/src/dependency_resolver/operation/any_operation.rs92
-rw-r--r--crates/shirabe/src/dependency_resolver/operation/install_operation.rs29
-rw-r--r--crates/shirabe/src/dependency_resolver/operation/mark_alias_installed_operation.rs25
-rw-r--r--crates/shirabe/src/dependency_resolver/operation/mark_alias_uninstalled_operation.rs25
-rw-r--r--crates/shirabe/src/dependency_resolver/operation/operation_interface.rs31
-rw-r--r--crates/shirabe/src/dependency_resolver/operation/solver_operation.rs12
-rw-r--r--crates/shirabe/src/dependency_resolver/operation/uninstall_operation.rs29
-rw-r--r--crates/shirabe/src/dependency_resolver/operation/update_operation.rs33
-rw-r--r--crates/shirabe/src/dependency_resolver/transaction.rs80
12 files changed, 159 insertions, 209 deletions
diff --git a/crates/shirabe/src/dependency_resolver/local_repo_transaction.rs b/crates/shirabe/src/dependency_resolver/local_repo_transaction.rs
index e592741e..a3443b93 100644
--- a/crates/shirabe/src/dependency_resolver/local_repo_transaction.rs
+++ b/crates/shirabe/src/dependency_resolver/local_repo_transaction.rs
@@ -1,7 +1,7 @@
//! ref: composer/src/Composer/DependencyResolver/LocalRepoTransaction.php
use super::Transaction;
-use crate::dependency_resolver::operation::OperationInterface;
+use crate::dependency_resolver::operation::AnyOperation;
use crate::repository::InstalledRepositoryInterface;
use crate::repository::RepositoryInterface;
@@ -23,7 +23,7 @@ impl LocalRepoTransaction {
})
}
- pub fn get_operations(&self) -> &Vec<std::rc::Rc<dyn OperationInterface>> {
+ pub fn get_operations(&self) -> &Vec<AnyOperation> {
self.inner.get_operations()
}
diff --git a/crates/shirabe/src/dependency_resolver/lock_transaction.rs b/crates/shirabe/src/dependency_resolver/lock_transaction.rs
index d78db851..a9086983 100644
--- a/crates/shirabe/src/dependency_resolver/lock_transaction.rs
+++ b/crates/shirabe/src/dependency_resolver/lock_transaction.rs
@@ -235,9 +235,7 @@ impl LockTransaction {
used_aliases
}
- pub fn get_operations(
- &self,
- ) -> &Vec<std::rc::Rc<dyn crate::dependency_resolver::operation::OperationInterface>> {
+ pub fn get_operations(&self) -> &Vec<crate::dependency_resolver::operation::AnyOperation> {
self.inner.get_operations()
}
}
diff --git a/crates/shirabe/src/dependency_resolver/operation.rs b/crates/shirabe/src/dependency_resolver/operation.rs
index 720c5a0a..b0db094a 100644
--- a/crates/shirabe/src/dependency_resolver/operation.rs
+++ b/crates/shirabe/src/dependency_resolver/operation.rs
@@ -1,15 +1,15 @@
+pub mod any_operation;
pub mod install_operation;
pub mod mark_alias_installed_operation;
pub mod mark_alias_uninstalled_operation;
-pub mod operation_interface;
pub mod solver_operation;
pub mod uninstall_operation;
pub mod update_operation;
+pub use any_operation::*;
pub use install_operation::*;
pub use mark_alias_installed_operation::*;
pub use mark_alias_uninstalled_operation::*;
-pub use operation_interface::*;
pub use solver_operation::*;
pub use uninstall_operation::*;
pub use update_operation::*;
diff --git a/crates/shirabe/src/dependency_resolver/operation/any_operation.rs b/crates/shirabe/src/dependency_resolver/operation/any_operation.rs
new file mode 100644
index 00000000..6675b280
--- /dev/null
+++ b/crates/shirabe/src/dependency_resolver/operation/any_operation.rs
@@ -0,0 +1,92 @@
+//! ref: composer/src/Composer/DependencyResolver/Operation/OperationInterface.php
+//!
+//! PHP's `OperationInterface` is not ported as a trait. Operations are only ever constructed by the
+//! dependency resolver, so a plugin has no way to inject an implementation of its own and the set is
+//! closed. The shared implementations PHP puts on `SolverOperation` (`getOperationType()`,
+//! `__toString()`) live here.
+
+use crate::dependency_resolver::operation::{
+ InstallOperation, MarkAliasInstalledOperation, MarkAliasUninstalledOperation, SolverOperation,
+ UninstallOperation, UpdateOperation,
+};
+use crate::package::PackageInterfaceHandle;
+
+/// Any solver operation.
+#[derive(Debug, Clone)]
+pub enum AnyOperation {
+ Install(InstallOperation),
+ Update(UpdateOperation),
+ Uninstall(UninstallOperation),
+ MarkAliasInstalled(MarkAliasInstalledOperation),
+ MarkAliasUninstalled(MarkAliasUninstalledOperation),
+}
+
+impl AnyOperation {
+ pub fn get_operation_type(&self) -> &'static str {
+ match self {
+ Self::Install(_) => InstallOperation::TYPE,
+ Self::Update(_) => UpdateOperation::TYPE,
+ Self::Uninstall(_) => UninstallOperation::TYPE,
+ Self::MarkAliasInstalled(_) => MarkAliasInstalledOperation::TYPE,
+ Self::MarkAliasUninstalled(_) => MarkAliasUninstalledOperation::TYPE,
+ }
+ }
+
+ pub fn show(&self, lock: bool) -> String {
+ match self {
+ Self::Install(op) => op.show(lock),
+ Self::Update(op) => op.show(lock),
+ Self::Uninstall(op) => op.show(lock),
+ Self::MarkAliasInstalled(op) => op.show(lock),
+ Self::MarkAliasUninstalled(op) => op.show(lock),
+ }
+ }
+
+ /// The package the operation results in. PHP spells this out at every call site as
+ /// `$op instanceof UpdateOperation ? $op->getTargetPackage() : $op->getPackage()`.
+ pub fn get_target_package(&self) -> PackageInterfaceHandle {
+ match self {
+ Self::Install(op) => op.get_package(),
+ Self::Update(op) => op.get_target_package(),
+ Self::Uninstall(op) => op.get_package(),
+ Self::MarkAliasInstalled(op) => op.get_package().into(),
+ Self::MarkAliasUninstalled(op) => op.get_package().into(),
+ }
+ }
+}
+
+impl std::fmt::Display for AnyOperation {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "{}", self.show(false))
+ }
+}
+
+impl From<InstallOperation> for AnyOperation {
+ fn from(op: InstallOperation) -> Self {
+ Self::Install(op)
+ }
+}
+
+impl From<UpdateOperation> for AnyOperation {
+ fn from(op: UpdateOperation) -> Self {
+ Self::Update(op)
+ }
+}
+
+impl From<UninstallOperation> for AnyOperation {
+ fn from(op: UninstallOperation) -> Self {
+ Self::Uninstall(op)
+ }
+}
+
+impl From<MarkAliasInstalledOperation> for AnyOperation {
+ fn from(op: MarkAliasInstalledOperation) -> Self {
+ Self::MarkAliasInstalled(op)
+ }
+}
+
+impl From<MarkAliasUninstalledOperation> for AnyOperation {
+ fn from(op: MarkAliasUninstalledOperation) -> Self {
+ Self::MarkAliasUninstalled(op)
+ }
+}
diff --git a/crates/shirabe/src/dependency_resolver/operation/install_operation.rs b/crates/shirabe/src/dependency_resolver/operation/install_operation.rs
index ef492393..05349c2d 100644
--- a/crates/shirabe/src/dependency_resolver/operation/install_operation.rs
+++ b/crates/shirabe/src/dependency_resolver/operation/install_operation.rs
@@ -1,10 +1,9 @@
//! ref: composer/src/Composer/DependencyResolver/Operation/InstallOperation.php
-use crate::dependency_resolver::operation::OperationInterface;
use crate::dependency_resolver::operation::SolverOperation;
use crate::package::PackageInterfaceHandle;
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub struct InstallOperation {
pub(crate) package: PackageInterfaceHandle,
}
@@ -18,6 +17,10 @@ impl InstallOperation {
self.package.clone()
}
+ pub fn show(&self, lock: bool) -> String {
+ Self::format(self.package.clone(), lock)
+ }
+
pub fn format(package: PackageInterfaceHandle, lock: bool) -> String {
format!(
"{}<info>{}</info> (<comment>{}</comment>)",
@@ -32,28 +35,6 @@ impl SolverOperation for InstallOperation {
const TYPE: &'static str = "install";
}
-impl OperationInterface for InstallOperation {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
- fn get_operation_type(&self) -> String {
- Self::TYPE.to_string()
- }
-
- fn show(&self, lock: bool) -> String {
- Self::format(self.package.clone(), lock)
- }
-
- fn as_install_operation(&self) -> Option<&InstallOperation> {
- Some(self)
- }
-
- fn get_package(&self) -> PackageInterfaceHandle {
- self.package.clone()
- }
-}
-
impl std::fmt::Display for InstallOperation {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.show(false))
diff --git a/crates/shirabe/src/dependency_resolver/operation/mark_alias_installed_operation.rs b/crates/shirabe/src/dependency_resolver/operation/mark_alias_installed_operation.rs
index 28bf511a..72066204 100644
--- a/crates/shirabe/src/dependency_resolver/operation/mark_alias_installed_operation.rs
+++ b/crates/shirabe/src/dependency_resolver/operation/mark_alias_installed_operation.rs
@@ -1,10 +1,9 @@
//! ref: composer/src/Composer/DependencyResolver/Operation/MarkAliasInstalledOperation.php
-use crate::dependency_resolver::operation::OperationInterface;
use crate::dependency_resolver::operation::SolverOperation;
use crate::package::AliasPackageHandle;
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub struct MarkAliasInstalledOperation {
pub(crate) package: AliasPackageHandle,
}
@@ -17,22 +16,8 @@ impl MarkAliasInstalledOperation {
pub fn get_package(&self) -> AliasPackageHandle {
self.package.clone()
}
-}
-
-impl SolverOperation for MarkAliasInstalledOperation {
- const TYPE: &'static str = "markAliasInstalled";
-}
-
-impl OperationInterface for MarkAliasInstalledOperation {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
- fn get_operation_type(&self) -> String {
- Self::TYPE.to_string()
- }
-
- fn show(&self, _lock: bool) -> String {
+ pub fn show(&self, _lock: bool) -> String {
format!(
"Marking <info>{}</info> (<comment>{}</comment>) as installed, alias of <info>{}</info> (<comment>{}</comment>)",
self.package.get_pretty_name(),
@@ -44,10 +29,10 @@ impl OperationInterface for MarkAliasInstalledOperation {
.get_full_pretty_version(true, crate::package::DisplayMode::SourceRefIfDev),
)
}
+}
- fn get_package(&self) -> crate::package::PackageInterfaceHandle {
- self.package.clone().into()
- }
+impl SolverOperation for MarkAliasInstalledOperation {
+ const TYPE: &'static str = "markAliasInstalled";
}
impl std::fmt::Display for MarkAliasInstalledOperation {
diff --git a/crates/shirabe/src/dependency_resolver/operation/mark_alias_uninstalled_operation.rs b/crates/shirabe/src/dependency_resolver/operation/mark_alias_uninstalled_operation.rs
index 3c0de332..4e4000df 100644
--- a/crates/shirabe/src/dependency_resolver/operation/mark_alias_uninstalled_operation.rs
+++ b/crates/shirabe/src/dependency_resolver/operation/mark_alias_uninstalled_operation.rs
@@ -1,10 +1,9 @@
//! ref: composer/src/Composer/DependencyResolver/Operation/MarkAliasUninstalledOperation.php
-use crate::dependency_resolver::operation::OperationInterface;
use crate::dependency_resolver::operation::SolverOperation;
use crate::package::AliasPackageHandle;
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub struct MarkAliasUninstalledOperation {
pub(crate) package: AliasPackageHandle,
}
@@ -17,22 +16,8 @@ impl MarkAliasUninstalledOperation {
pub fn get_package(&self) -> AliasPackageHandle {
self.package.clone()
}
-}
-
-impl SolverOperation for MarkAliasUninstalledOperation {
- const TYPE: &'static str = "markAliasUninstalled";
-}
-
-impl OperationInterface for MarkAliasUninstalledOperation {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
- fn get_operation_type(&self) -> String {
- Self::TYPE.to_string()
- }
-
- fn show(&self, _lock: bool) -> String {
+ pub fn show(&self, _lock: bool) -> String {
format!(
"Marking <info>{}</info> (<comment>{}</comment>) as uninstalled, alias of <info>{}</info> (<comment>{}</comment>)",
self.package.get_pretty_name(),
@@ -44,10 +29,10 @@ impl OperationInterface for MarkAliasUninstalledOperation {
.get_full_pretty_version(true, crate::package::DisplayMode::SourceRefIfDev),
)
}
+}
- fn get_package(&self) -> crate::package::PackageInterfaceHandle {
- self.package.clone().into()
- }
+impl SolverOperation for MarkAliasUninstalledOperation {
+ const TYPE: &'static str = "markAliasUninstalled";
}
impl std::fmt::Display for MarkAliasUninstalledOperation {
diff --git a/crates/shirabe/src/dependency_resolver/operation/operation_interface.rs b/crates/shirabe/src/dependency_resolver/operation/operation_interface.rs
deleted file mode 100644
index 30ed8eb5..00000000
--- a/crates/shirabe/src/dependency_resolver/operation/operation_interface.rs
+++ /dev/null
@@ -1,31 +0,0 @@
-//! ref: composer/src/Composer/DependencyResolver/Operation/OperationInterface.php
-
-use crate::dependency_resolver::operation::InstallOperation;
-use crate::dependency_resolver::operation::UninstallOperation;
-use crate::dependency_resolver::operation::UpdateOperation;
-
-pub trait OperationInterface: std::fmt::Display + std::fmt::Debug {
- fn as_any(&self) -> &dyn std::any::Any;
-
- fn get_operation_type(&self) -> String;
-
- fn show(&self, lock: bool) -> String;
-
- fn as_install_operation(&self) -> Option<&InstallOperation> {
- None
- }
-
- fn as_update_operation(&self) -> Option<&UpdateOperation> {
- None
- }
-
- fn as_uninstall_operation(&self) -> Option<&UninstallOperation> {
- None
- }
-
- /// PHP duck-typed accessor. Only InstallOperation/UninstallOperation/MarkAlias*Operation
- /// expose this; UpdateOperation has getInitialPackage()/getTargetPackage() instead.
- fn get_package(&self) -> crate::package::PackageInterfaceHandle {
- todo!("get_package is not available on this operation type")
- }
-}
diff --git a/crates/shirabe/src/dependency_resolver/operation/solver_operation.rs b/crates/shirabe/src/dependency_resolver/operation/solver_operation.rs
index 2710ec50..eb9c6315 100644
--- a/crates/shirabe/src/dependency_resolver/operation/solver_operation.rs
+++ b/crates/shirabe/src/dependency_resolver/operation/solver_operation.rs
@@ -1,11 +1,9 @@
//! ref: composer/src/Composer/DependencyResolver/Operation/SolverOperation.php
-use crate::dependency_resolver::operation::OperationInterface;
-
-pub trait SolverOperation: OperationInterface {
+/// PHP's abstract `SolverOperation` carries the per-class `TYPE` constant and the
+/// `getOperationType()` / `__toString()` implementations shared by every operation. Only the
+/// constant remains here; the shared implementations live on
+/// [`AnyOperation`](crate::dependency_resolver::operation::AnyOperation).
+pub trait SolverOperation {
const TYPE: &'static str;
-
- fn get_operation_type(&self) -> &str {
- Self::TYPE
- }
}
diff --git a/crates/shirabe/src/dependency_resolver/operation/uninstall_operation.rs b/crates/shirabe/src/dependency_resolver/operation/uninstall_operation.rs
index d2dd6651..2fd35af5 100644
--- a/crates/shirabe/src/dependency_resolver/operation/uninstall_operation.rs
+++ b/crates/shirabe/src/dependency_resolver/operation/uninstall_operation.rs
@@ -1,10 +1,9 @@
//! ref: composer/src/Composer/DependencyResolver/Operation/UninstallOperation.php
-use crate::dependency_resolver::operation::OperationInterface;
use crate::dependency_resolver::operation::SolverOperation;
use crate::package::PackageInterfaceHandle;
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub struct UninstallOperation {
pub(crate) package: PackageInterfaceHandle,
}
@@ -18,6 +17,10 @@ impl UninstallOperation {
self.package.clone()
}
+ pub fn show(&self, lock: bool) -> String {
+ Self::format(self.package.clone(), lock)
+ }
+
pub fn format(package: PackageInterfaceHandle, _lock: bool) -> String {
format!(
"Removing <info>{}</info> (<comment>{}</comment>)",
@@ -31,28 +34,6 @@ impl SolverOperation for UninstallOperation {
const TYPE: &'static str = "uninstall";
}
-impl OperationInterface for UninstallOperation {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
- fn get_operation_type(&self) -> String {
- Self::TYPE.to_string()
- }
-
- fn show(&self, lock: bool) -> String {
- Self::format(self.package.clone(), lock)
- }
-
- fn as_uninstall_operation(&self) -> Option<&UninstallOperation> {
- Some(self)
- }
-
- fn get_package(&self) -> PackageInterfaceHandle {
- self.package.clone()
- }
-}
-
impl std::fmt::Display for UninstallOperation {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.show(false))
diff --git a/crates/shirabe/src/dependency_resolver/operation/update_operation.rs b/crates/shirabe/src/dependency_resolver/operation/update_operation.rs
index 76b17189..a06a9cdc 100644
--- a/crates/shirabe/src/dependency_resolver/operation/update_operation.rs
+++ b/crates/shirabe/src/dependency_resolver/operation/update_operation.rs
@@ -1,11 +1,10 @@
//! ref: composer/src/Composer/DependencyResolver/Operation/UpdateOperation.php
-use crate::dependency_resolver::operation::OperationInterface;
use crate::dependency_resolver::operation::SolverOperation;
use crate::package::PackageInterfaceHandle;
use crate::package::version::VersionParser;
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub struct UpdateOperation {
pub(crate) initial_package: PackageInterfaceHandle,
pub(crate) target_package: PackageInterfaceHandle,
@@ -27,6 +26,14 @@ impl UpdateOperation {
self.target_package.clone()
}
+ pub fn show(&self, lock: bool) -> String {
+ Self::format(
+ self.initial_package.clone(),
+ self.target_package.clone(),
+ lock,
+ )
+ }
+
pub fn format(
initial_package: PackageInterfaceHandle,
target_package: PackageInterfaceHandle,
@@ -78,28 +85,6 @@ impl SolverOperation for UpdateOperation {
const TYPE: &'static str = "update";
}
-impl OperationInterface for UpdateOperation {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
- fn get_operation_type(&self) -> String {
- Self::TYPE.to_string()
- }
-
- fn show(&self, lock: bool) -> String {
- Self::format(
- self.initial_package.clone(),
- self.target_package.clone(),
- lock,
- )
- }
-
- fn as_update_operation(&self) -> Option<&UpdateOperation> {
- Some(self)
- }
-}
-
impl std::fmt::Display for UpdateOperation {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.show(false))
diff --git a/crates/shirabe/src/dependency_resolver/transaction.rs b/crates/shirabe/src/dependency_resolver/transaction.rs
index 07564ed0..4abe85d4 100644
--- a/crates/shirabe/src/dependency_resolver/transaction.rs
+++ b/crates/shirabe/src/dependency_resolver/transaction.rs
@@ -1,9 +1,9 @@
//! ref: composer/src/Composer/DependencyResolver/Transaction.php
+use crate::dependency_resolver::operation::AnyOperation;
use crate::dependency_resolver::operation::InstallOperation;
use crate::dependency_resolver::operation::MarkAliasInstalledOperation;
use crate::dependency_resolver::operation::MarkAliasUninstalledOperation;
-use crate::dependency_resolver::operation::OperationInterface;
use crate::dependency_resolver::operation::UninstallOperation;
use crate::dependency_resolver::operation::UpdateOperation;
use crate::package::AliasPackageHandle;
@@ -21,7 +21,7 @@ use shirabe_php_shim::{
#[derive(Debug, Clone)]
pub struct Transaction {
/// @var OperationInterface[]
- pub(crate) operations: Vec<std::rc::Rc<dyn OperationInterface>>,
+ pub(crate) operations: Vec<AnyOperation>,
/// Packages present at the beginning of the transaction
/// @var PackageInterface[]
@@ -64,7 +64,7 @@ impl Transaction {
this
}
- pub fn get_operations(&self) -> &Vec<std::rc::Rc<dyn OperationInterface>> {
+ pub fn get_operations(&self) -> &Vec<AnyOperation> {
&self.operations
}
@@ -108,8 +108,8 @@ impl Transaction {
}
/// @return OperationInterface[]
- pub(crate) fn calculate_operations(&mut self) -> Vec<std::rc::Rc<dyn OperationInterface>> {
- let mut operations: Vec<std::rc::Rc<dyn OperationInterface>> = vec![];
+ pub(crate) fn calculate_operations(&mut self) -> Vec<AnyOperation> {
+ let mut operations: Vec<AnyOperation> = vec![];
let mut present_package_map: IndexMap<String, PackageInterfaceHandle> = IndexMap::new();
let mut remove_map: IndexMap<String, PackageInterfaceHandle> = IndexMap::new();
@@ -163,7 +163,7 @@ impl Transaction {
if present_alias_map.contains(&alias_key) {
remove_alias_map.shift_remove(&alias_key);
} else {
- operations.push(std::rc::Rc::new(MarkAliasInstalledOperation::new(alias)));
+ operations.push(MarkAliasInstalledOperation::new(alias).into());
}
} else if let Some(source) = present_package_map.get(&package.get_name()).cloned() {
// do we need to update?
@@ -187,14 +187,12 @@ impl Transaction {
|| package.get_source_reference() != present.get_source_reference()
|| abandoned_or_replacement_changed
{
- operations.push(std::rc::Rc::new(UpdateOperation::new(
- source.clone(),
- package.clone(),
- )));
+ operations
+ .push(UpdateOperation::new(source.clone(), package.clone()).into());
}
remove_map.shift_remove(&package.get_name());
} else {
- operations.push(std::rc::Rc::new(InstallOperation::new(package.clone())));
+ operations.push(InstallOperation::new(package.clone()).into());
remove_map.shift_remove(&package.get_name());
}
}
@@ -202,16 +200,10 @@ impl Transaction {
for (_name, package) in remove_map {
// PHP: array_unshift($operations, new Operation\UninstallOperation($package));
- array_unshift(
- &mut operations,
- std::rc::Rc::new(UninstallOperation::new(package))
- as std::rc::Rc<dyn OperationInterface>,
- );
+ array_unshift(&mut operations, UninstallOperation::new(package).into());
}
for (_name_version, package) in remove_alias_map {
- operations.push(std::rc::Rc::new(MarkAliasUninstalledOperation::new(
- package,
- )));
+ operations.push(MarkAliasUninstalledOperation::new(package).into());
}
let operations = self.move_plugins_to_front(operations);
@@ -279,29 +271,22 @@ impl Transaction {
///
/// @param OperationInterface[] $operations
/// @return OperationInterface[] reordered operation list
- fn move_plugins_to_front(
- &self,
- mut operations: Vec<std::rc::Rc<dyn OperationInterface>>,
- ) -> Vec<std::rc::Rc<dyn OperationInterface>> {
- let mut dl_modifying_plugins_no_deps: Vec<std::rc::Rc<dyn OperationInterface>> = vec![];
- let mut dl_modifying_plugins_with_deps: Vec<std::rc::Rc<dyn OperationInterface>> = vec![];
+ fn move_plugins_to_front(&self, mut operations: Vec<AnyOperation>) -> Vec<AnyOperation> {
+ let mut dl_modifying_plugins_no_deps: Vec<AnyOperation> = vec![];
+ let mut dl_modifying_plugins_with_deps: Vec<AnyOperation> = vec![];
let mut dl_modifying_plugin_requires: Vec<String> = vec![];
- let mut plugins_no_deps: Vec<std::rc::Rc<dyn OperationInterface>> = vec![];
- let mut plugins_with_deps: Vec<std::rc::Rc<dyn OperationInterface>> = vec![];
+ let mut plugins_no_deps: Vec<AnyOperation> = vec![];
+ let mut plugins_with_deps: Vec<AnyOperation> = vec![];
let mut plugin_requires: Vec<String> = vec![];
let mut to_remove: Vec<usize> = vec![];
for idx in (0..operations.len()).rev() {
let op = &operations[idx];
- let package: PackageInterfaceHandle = if let Some(install_op) =
- op.as_ref().as_any().downcast_ref::<InstallOperation>()
- {
- install_op.get_package().clone()
- } else if let Some(update_op) = op.as_ref().as_any().downcast_ref::<UpdateOperation>() {
- update_op.get_target_package().clone()
- } else {
- continue;
+ let package: PackageInterfaceHandle = match op {
+ AnyOperation::Install(install_op) => install_op.get_package(),
+ AnyOperation::Update(update_op) => update_op.get_target_package(),
+ _ => continue,
};
let extra = package.get_extra();
@@ -373,7 +358,7 @@ impl Transaction {
}
// PHP: array_merge($dlModifyingPluginsNoDeps, $dlModifyingPluginsWithDeps, $pluginsNoDeps, $pluginsWithDeps, $operations)
- let mut result: Vec<std::rc::Rc<dyn OperationInterface>> = vec![];
+ let mut result: Vec<AnyOperation> = vec![];
result.extend(dl_modifying_plugins_no_deps);
result.extend(dl_modifying_plugins_with_deps);
result.extend(plugins_no_deps);
@@ -387,23 +372,14 @@ impl Transaction {
///
/// @param OperationInterface[] $operations
/// @return OperationInterface[] reordered operation list
- fn move_uninstalls_to_front(
- &self,
- mut operations: Vec<std::rc::Rc<dyn OperationInterface>>,
- ) -> Vec<std::rc::Rc<dyn OperationInterface>> {
- let mut uninst_ops: Vec<std::rc::Rc<dyn OperationInterface>> = vec![];
+ fn move_uninstalls_to_front(&self, mut operations: Vec<AnyOperation>) -> Vec<AnyOperation> {
+ let mut uninst_ops: Vec<AnyOperation> = vec![];
let mut to_remove: Vec<usize> = vec![];
for (idx, op) in operations.iter().enumerate() {
- let is_uninstall = op
- .as_ref()
- .as_any()
- .downcast_ref::<UninstallOperation>()
- .is_some()
- || op
- .as_ref()
- .as_any()
- .downcast_ref::<MarkAliasUninstalledOperation>()
- .is_some();
+ let is_uninstall = matches!(
+ op,
+ AnyOperation::Uninstall(_) | AnyOperation::MarkAliasUninstalled(_)
+ );
if is_uninstall {
uninst_ops.push(op.clone());
to_remove.push(idx);
@@ -415,7 +391,7 @@ impl Transaction {
operations.remove(idx);
}
- let mut result: Vec<std::rc::Rc<dyn OperationInterface>> = vec![];
+ let mut result: Vec<AnyOperation> = vec![];
result.extend(uninst_ops);
result.extend(operations);
result