mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT: Improved performance of Object::allMethodNames() and Object::addMethodsFrom()
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@84158 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
01640b32ae
commit
70dc433d38
@ -611,7 +611,9 @@ abstract class Object {
|
||||
* @return array
|
||||
*/
|
||||
public function allMethodNames($custom = false) {
|
||||
if(!isset(self::$built_in_methods['_set'][$this->class])) $this->buildMethodList();
|
||||
if(!isset(self::$built_in_methods[$this->class])) {
|
||||
self::$built_in_methods[$this->class] = array_map('strtolower', get_class_methods($this));
|
||||
}
|
||||
|
||||
if($custom && isset(self::$extra_methods[$this->class])) {
|
||||
return array_merge(self::$built_in_methods[$this->class], array_keys(self::$extra_methods[$this->class]));
|
||||
@ -620,14 +622,6 @@ abstract class Object {
|
||||
}
|
||||
}
|
||||
|
||||
protected function buildMethodList() {
|
||||
foreach(get_class_methods($this) as $method) {
|
||||
self::$built_in_methods[$this->class][strtolower($method)] = strtolower($method);
|
||||
}
|
||||
|
||||
self::$built_in_methods['_set'][$this->class] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds any methods from {@link Extension} instances attached to this object.
|
||||
* All these methods can then be called directly on the instance (transparently
|
||||
@ -667,12 +661,19 @@ abstract class Object {
|
||||
}
|
||||
|
||||
if(method_exists($extension, 'allMethodNames')) {
|
||||
foreach($extension->allMethodNames(true) as $method) {
|
||||
self::$extra_methods[$this->class][$method] = array (
|
||||
'property' => $property,
|
||||
'index' => $index,
|
||||
'callSetOwnerFirst' => $extension instanceof Extension,
|
||||
);
|
||||
$methodInfo = array(
|
||||
'property' => $property,
|
||||
'index' => $index,
|
||||
'callSetOwnerFirst' => $extension instanceof Extension,
|
||||
);
|
||||
|
||||
$newMethods = array_fill_keys($extension->allMethodNames(true), $methodInfo);
|
||||
|
||||
if(isset(self::$extra_methods[$this->class])) {
|
||||
self::$extra_methods[$this->class] =
|
||||
array_merge(self::$extra_methods[$this->class], $newMethods);
|
||||
} else {
|
||||
self::$extra_methods[$this->class] = $newMethods;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user