Skip to content

Commit

Permalink
ENHANCEMENT: Added ClassInfo::is_subclass_of() for better performance
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@83789 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
Sam Minnee committed Aug 5, 2009
1 parent a39ec17 commit a72f7b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions core/ClassInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ static function classImplements($className, $interfaceName) {
global $_ALL_CLASSES;
return isset($_ALL_CLASSES['implementors'][$interfaceName][$className]);
}

/**
* Returns true if $subclass is a subclass of $parentClass.
* Identical to the PHP built-in function, but faster.
*/
static function is_subclass_of($subclass, $parentClass) {
global $_ALL_CLASSES;
return isset($_ALL_CLASSES['parents'][$subclass][$parentClass]);
}

/**
* Get all classes contained in a file.
Expand Down
4 changes: 2 additions & 2 deletions core/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public static function add_extension($class, $extension) {
user_error(sprintf('Object::add_extension() - Can\'t find extension class for "%s"', $extensionClass), E_USER_ERROR);
}

if(!is_subclass_of($extensionClass, 'Extension')) {
if(!ClassInfo::is_subclass_of($extensionClass, 'Extension')) {
user_error(sprintf('Object::add_extension() - Extension "%s" is not a subclass of Extension', $extensionClass), E_USER_ERROR);
}

Expand All @@ -407,7 +407,7 @@ public static function add_extension($class, $extension) {
self::add_static_var($class, 'extensions', array($extension));

// load statics now for DataObject classes
if(is_subclass_of($class, 'DataObject')) {
if(ClassInfo::is_subclass_of($class, 'DataObject')) {
DataObjectDecorator::load_extra_statics($class, $extensionClass);
}
}
Expand Down

0 comments on commit a72f7b2

Please sign in to comment.