Fix hook for Doctrine PDO class (#76)
diff --git a/src/plugin/plugin_pdo.rs b/src/plugin/plugin_pdo.rs
index 1f31b56..bbedfa3 100644
--- a/src/plugin/plugin_pdo.rs
+++ b/src/plugin/plugin_pdo.rs
@@ -25,6 +25,7 @@
use once_cell::sync::Lazy;
use phper::{
arrays::ZArr,
+ classes::ClassEntry,
objects::ZObj,
sys,
values::{ExecuteData, ZVal},
@@ -91,7 +92,7 @@
let dsn = execute_data.get_parameter(0);
let dsn = dsn.as_z_str().context("dsn isn't str")?.to_str()?;
- debug!(dsn, "construct PDO");
+ debug!(dsn, handle, "construct PDO");
let dsn: Dsn = dsn.parse()?;
debug!(?dsn, "parse PDO dsn");
@@ -198,8 +199,13 @@
);
}
} else if let Some(obj) = return_value.as_mut_z_obj() {
- if obj.get_class().get_name() == &"PDOStatement" {
+ let cls = obj.get_class();
+ let pdo_cls = ClassEntry::from_globals("PDOStatement").unwrap();
+ if cls.is_instance_of(pdo_cls) {
return after_hook_when_pdo_statement(get_this_mut(execute_data)?, obj);
+ } else {
+ let cls = cls.get_name().to_str()?;
+ debug!(cls, "not a subclass of PDOStatement");
}
}
@@ -235,7 +241,9 @@
.get(&pdo.handle())
.map(|r| r.value().clone())
.context("DSN not found")?;
- DSN_MAP.insert(pdo_statement.handle(), dsn);
+ let handle = pdo_statement.handle();
+ debug!(?dsn, handle, "Hook PDOStatement class");
+ DSN_MAP.insert(handle, dsn);
hack_dtor(pdo_statement, Some(pdo_statement_dtor));
Ok(())
}
@@ -267,7 +275,7 @@
DSN_MAP
.get(&handle)
.map(|r| f(r.value()))
- .context("dns not exists")?
+ .context("dsn not exists")?
}
#[derive(Debug, Clone)]