mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Fix extend() failing on protected extend-prefixed methods
This commit is contained in:
parent
76fc8f1596
commit
f2211d690f
@ -419,7 +419,7 @@ trait Extensible
|
||||
* The extension methods are defined during {@link __construct()} in {@link defineMethods()}.
|
||||
*
|
||||
* @param string $method the name of the method to call on each extension
|
||||
* @param mixed ...$arguments
|
||||
* @param mixed &...$arguments
|
||||
* @return array
|
||||
*/
|
||||
public function extend($method, &...$arguments)
|
||||
@ -438,19 +438,9 @@ trait Extensible
|
||||
|
||||
foreach ($this->getExtensionInstances() as $instance) {
|
||||
// Prefer `extend` prefixed methods
|
||||
$instanceMethod = method_exists($instance, "extend{$method}")
|
||||
? "extend{$method}"
|
||||
: (method_exists($instance, $method) ? $method : null);
|
||||
if ($instanceMethod) {
|
||||
try {
|
||||
$instance->setOwner($this);
|
||||
$value = $instance->$instanceMethod(...$arguments);
|
||||
} finally {
|
||||
$instance->clearOwner();
|
||||
}
|
||||
if ($value !== null) {
|
||||
$values[] = $value;
|
||||
}
|
||||
$value = $instance->invokeExtension($this, $method, ...$arguments);
|
||||
if ($value !== null) {
|
||||
$values[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,4 +115,31 @@ abstract class Extension
|
||||
// Split out both args and service name
|
||||
return strtok(strtok($extensionStr ?? '', '(') ?? '', '.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke extension point. This will prefer explicit `extend` prefixed
|
||||
* methods.
|
||||
*
|
||||
* @param object $owner
|
||||
* @param string $method
|
||||
* @param array &...$arguments
|
||||
* @return mixed
|
||||
*/
|
||||
public function invokeExtension($owner, $method, &...$arguments)
|
||||
{
|
||||
// Prefer `extend` prefixed methods
|
||||
$instanceMethod = method_exists($this, "extend{$method}")
|
||||
? "extend{$method}"
|
||||
: (method_exists($this, $method) ? $method : null);
|
||||
if (!$instanceMethod) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->setOwner($owner);
|
||||
return $this->$instanceMethod(...$arguments);
|
||||
} finally {
|
||||
$this->clearOwner();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user