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:
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user