1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 16:26:59 +02:00

Enhancement processwire/processwire-issues#405 add support for hooks to be used in classes that extend Wire-derived classes that aren't in the ProcessWire namespace.

This commit is contained in:
Ryan Cramer
2017-10-17 10:00:55 -04:00
parent b0f37a306e
commit a48f4038c8

View File

@@ -152,6 +152,7 @@ class WireHooks {
// see if we can do a quick exit
if($method && $method !== '*' && !$this->isHookedOrParents($object, $method)) return $hooks;
// first determine which local hooks when should include
if($type !== self::getHooksStatic) {
@@ -174,6 +175,7 @@ class WireHooks {
$needSort = false;
$namespace = __NAMESPACE__ ? __NAMESPACE__ . "\\" : "";
$objectParentNamespaces = array();
// join in static hooks
foreach($this->staticHooks as $className => $staticHooks) {
@@ -184,7 +186,21 @@ class WireHooks {
// objects in other namespaces
$_className = $_namespace . $className;
if(!$object instanceof $_className && $method !== '*') {
continue;
// object likely extends a class not in PW namespace, so check class parents instead
if(empty($objectParentNamespaces)) {
foreach(wireClassParents($object) as $nscn => $cn) {
list($ns,) = explode("\\", $nscn);
$objectParentNamespaces[$ns] = $ns;
}
}
$nsok = false;
foreach($objectParentNamespaces as $ns) {
$_className = "$ns\\$className";
if(!$object instanceof $_className) continue;
$nsok = true;
break;
}
if(!$nsok) continue;
}
} else {
continue;