1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-11 01:04:16 +02:00

Update the new path hooks to support $wire->addHook('/foo/{bar}/baz', ...) where {bar} would match any segment and populate it to a $bar variable on the HookEvent. Plus add enforced trailing slash vs. non-trailing slash with redirect, depending on whether your match pattern uses a trailing slash.

This commit is contained in:
Ryan Cramer
2021-03-08 10:10:26 -05:00
parent cb9030a6ff
commit c0ffd35b7d
3 changed files with 92 additions and 22 deletions

View File

@@ -90,14 +90,14 @@ class HookEvent extends WireData {
*
*/
public function arguments($n = null, $value = null) {
if(is_null($n)) return $this->arguments;
if(!is_null($value)) {
if($n === null) return $this->data['arguments'];
if($value !== null) {
$this->setArgument($n, $value);
return $value;
}
if(isset($this->data['arguments'][$n])) return $this->data['arguments'][$n];
if(is_string($n)) return $this->argumentsByName($n);
$arguments = $this->arguments;
return isset($arguments[$n]) ? $arguments[$n] : null;
return null;
}
/**
@@ -119,7 +119,7 @@ class HookEvent extends WireData {
*/
public function argumentsByName($n = '') {
$arguments = $this->arguments();
$arguments = $this->data['arguments'];
if(isset($arguments[$n])) return $arguments[$n];
$names = $this->getArgumentNames();
@@ -165,9 +165,7 @@ class HookEvent extends WireData {
if($n === false) throw new WireException("Unknown argument name: $n");
}
$arguments = $this->arguments;
$arguments[(int)$n] = $value;
$this->set('arguments', $arguments);
$this->data['arguments'][(int)$n] = $value;
return $this;
}