mirror of
https://github.com/processwire/processwire.git
synced 2025-08-10 08:44:46 +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:
@@ -153,6 +153,7 @@ class WireHooks {
|
|||||||
// see if we can do a quick exit
|
// see if we can do a quick exit
|
||||||
if($method && $method !== '*' && !$this->isHookedOrParents($object, $method)) return $hooks;
|
if($method && $method !== '*' && !$this->isHookedOrParents($object, $method)) return $hooks;
|
||||||
|
|
||||||
|
|
||||||
// first determine which local hooks when should include
|
// first determine which local hooks when should include
|
||||||
if($type !== self::getHooksStatic) {
|
if($type !== self::getHooksStatic) {
|
||||||
$localHooks = $object->getLocalHooks();
|
$localHooks = $object->getLocalHooks();
|
||||||
@@ -174,6 +175,7 @@ class WireHooks {
|
|||||||
|
|
||||||
$needSort = false;
|
$needSort = false;
|
||||||
$namespace = __NAMESPACE__ ? __NAMESPACE__ . "\\" : "";
|
$namespace = __NAMESPACE__ ? __NAMESPACE__ . "\\" : "";
|
||||||
|
$objectParentNamespaces = array();
|
||||||
|
|
||||||
// join in static hooks
|
// join in static hooks
|
||||||
foreach($this->staticHooks as $className => $staticHooks) {
|
foreach($this->staticHooks as $className => $staticHooks) {
|
||||||
@@ -184,7 +186,21 @@ class WireHooks {
|
|||||||
// objects in other namespaces
|
// objects in other namespaces
|
||||||
$_className = $_namespace . $className;
|
$_className = $_namespace . $className;
|
||||||
if(!$object instanceof $_className && $method !== '*') {
|
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 {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
|
Reference in New Issue
Block a user