mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 08:17:12 +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:
@@ -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;
|
||||
|
Reference in New Issue
Block a user