Refactor duplicate code in Object

This commit is contained in:
Loz Calver 2016-06-03 21:48:53 +01:00 committed by Loz Calver
parent 429ce55756
commit 0ad64387c7
No known key found for this signature in database
GPG Key ID: F91FFC2D7E0CAEDB

View File

@ -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];