mirror of
https://github.com/processwire/processwire.git
synced 2025-08-17 12:10:45 +02:00
Update WireHooks to allow for (and ignore) an empty argument string "()" after hook definition (first argument) in addHook() methods.
This commit is contained in:
@@ -546,35 +546,42 @@ class WireHooks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$argOpen = strpos($method, '(');
|
$argOpen = strpos($method, '(');
|
||||||
if($argOpen && strpos($method, ')') > $argOpen+1) {
|
if($argOpen) {
|
||||||
// extract argument selector match string(s), arg 0: Something::something(selector_string)
|
// arguments to match may be specified in method name
|
||||||
// or: Something::something(1:selector_string, 3:selector_string) matches arg 1 and 3.
|
$argClose = strpos($method, ')');
|
||||||
list($method, $argMatch) = explode('(', $method, 2);
|
if($argClose === $argOpen+1) {
|
||||||
$argMatch = trim($argMatch, ') ');
|
// method just has a "()" which can be discarded
|
||||||
if(strpos($argMatch, ':') !== false) {
|
$method = rtrim($method, '() ');
|
||||||
// zero-based argument indexes specified, i.e. 0:template=product, 1:order_status
|
} else if($argClose > $argOpen+1) {
|
||||||
$args = preg_split('/\b([0-9]):/', trim($argMatch), -1, PREG_SPLIT_DELIM_CAPTURE);
|
// extract argument selector match string(s), arg 0: Something::something(selector_string)
|
||||||
if(count($args)) {
|
// or: Something::something(1:selector_string, 3:selector_string) matches arg 1 and 3.
|
||||||
$argMatch = array();
|
list($method, $argMatch) = explode('(', $method, 2);
|
||||||
array_shift($args); // blank
|
$argMatch = trim($argMatch, ') ');
|
||||||
while(count($args)) {
|
if(strpos($argMatch, ':') !== false) {
|
||||||
$argKey = (int) trim(array_shift($args));
|
// zero-based argument indexes specified, i.e. 0:template=product, 1:order_status
|
||||||
$argVal = trim(array_shift($args), ', ');
|
$args = preg_split('/\b([0-9]):/', trim($argMatch), -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||||
$argMatch[$argKey] = $argVal;
|
if(count($args)) {
|
||||||
|
$argMatch = array();
|
||||||
|
array_shift($args); // blank
|
||||||
|
while(count($args)) {
|
||||||
|
$argKey = (int) trim(array_shift($args));
|
||||||
|
$argVal = trim(array_shift($args), ', ');
|
||||||
|
$argMatch[$argKey] = $argVal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// just single argument specified, so argument 0 is assumed
|
||||||
|
}
|
||||||
|
if(is_string($argMatch)) $argMatch = array(0 => $argMatch);
|
||||||
|
foreach($argMatch as $argKey => $argVal) {
|
||||||
|
if(Selectors::stringHasSelector($argVal)) {
|
||||||
|
$selectors = $this->wire->wire(new Selectors());
|
||||||
|
$selectors->init($argVal);
|
||||||
|
$argMatch[$argKey] = $selectors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
if(count($argMatch)) $options['argMatch'] = $argMatch;
|
||||||
// just single argument specified, so argument 0 is assumed
|
|
||||||
}
|
}
|
||||||
if(is_string($argMatch)) $argMatch = array(0 => $argMatch);
|
|
||||||
foreach($argMatch as $argKey => $argVal) {
|
|
||||||
if(Selectors::stringHasSelector($argVal)) {
|
|
||||||
$selectors = $this->wire->wire(new Selectors());
|
|
||||||
$selectors->init($argVal);
|
|
||||||
$argMatch[$argKey] = $selectors;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(count($argMatch)) $options['argMatch'] = $argMatch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$localHooks = $object->getLocalHooks();
|
$localHooks = $object->getLocalHooks();
|
||||||
|
Reference in New Issue
Block a user