mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Refactor duplicate code in Object
This commit is contained in:
parent
429ce55756
commit
0ad64387c7
@ -800,6 +800,25 @@ abstract class Object {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param object $extension
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function findMethodsFromExtension($extension) {
|
||||||
|
if (method_exists($extension, 'allMethodNames')) {
|
||||||
|
if ($extension instanceof Extension) $extension->setOwner($this);
|
||||||
|
$methods = $extension->allMethodNames(true);
|
||||||
|
if ($extension instanceof Extension) $extension->clearOwner();
|
||||||
|
} else {
|
||||||
|
if (!isset(self::$built_in_methods[$extension->class])) {
|
||||||
|
self::$built_in_methods[$extension->class] = array_map('strtolower', get_class_methods($extension));
|
||||||
|
}
|
||||||
|
$methods = self::$built_in_methods[$extension->class];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $methods;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add all the methods from an object property (which is an {@link Extension}) to this object.
|
* Add all the methods from an object property (which is an {@link Extension}) to this object.
|
||||||
*
|
*
|
||||||
@ -815,19 +834,8 @@ abstract class Object {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(method_exists($extension, 'allMethodNames')) {
|
$methods = $this->findMethodsFromExtension($extension);
|
||||||
if ($extension instanceof Extension) $extension->setOwner($this);
|
if ($methods) {
|
||||||
$methods = $extension->allMethodNames(true);
|
|
||||||
if ($extension instanceof Extension) $extension->clearOwner();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if(!isset(self::$built_in_methods[$extension->class])) {
|
|
||||||
self::$built_in_methods[$extension->class] = array_map('strtolower', get_class_methods($extension));
|
|
||||||
}
|
|
||||||
$methods = self::$built_in_methods[$extension->class];
|
|
||||||
}
|
|
||||||
|
|
||||||
if($methods) {
|
|
||||||
$methodInfo = array(
|
$methodInfo = array(
|
||||||
'property' => $property,
|
'property' => $property,
|
||||||
'index' => $index,
|
'index' => $index,
|
||||||
@ -860,19 +868,8 @@ abstract class Object {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(method_exists($extension, 'allMethodNames')) {
|
$methods = $this->findMethodsFromExtension($extension);
|
||||||
if ($extension instanceof Extension) $extension->setOwner($this);
|
if ($methods) {
|
||||||
$methods = $extension->allMethodNames(true);
|
|
||||||
if ($extension instanceof Extension) $extension->clearOwner();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if(!isset(self::$built_in_methods[$extension->class])) {
|
|
||||||
self::$built_in_methods[$extension->class] = array_map('strtolower', get_class_methods($extension));
|
|
||||||
}
|
|
||||||
$methods = self::$built_in_methods[$extension->class];
|
|
||||||
}
|
|
||||||
|
|
||||||
if($methods) {
|
|
||||||
foreach ($methods as $method) {
|
foreach ($methods as $method) {
|
||||||
$methodInfo = self::$extra_methods[$this->class][$method];
|
$methodInfo = self::$extra_methods[$this->class][$method];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user