From e12f87ad38127bfc26931d4381650c5bcb1d8637 Mon Sep 17 00:00:00 2001 From: Mark Rickerby Date: Mon, 14 Apr 2008 04:49:08 +0000 Subject: [PATCH] When ClassInfo::dataClassesFor is passed an instance of the class, the method now automatically coerces the instance to a string of its name git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@52675 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/ClassInfo.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/ClassInfo.php b/core/ClassInfo.php index e632b6305..f58e94d13 100755 --- a/core/ClassInfo.php +++ b/core/ClassInfo.php @@ -64,9 +64,14 @@ class ClassInfo { * Return the database tables linked to this class. * Gets an array of the current class, it subclasses and its ancestors. It then filters that list * to those with DB tables + * + * @param mixed $class string of the classname or instance of the class + * @return array */ static function dataClassesFor($class) { global $_ALL_CLASSES; + if (is_object($class)) $class = get_class($class); + if(!$_ALL_CLASSES['parents'][$class]) user_error("ClassInfo::dataClassesFor() no parents for $class", E_USER_WARNING); foreach($_ALL_CLASSES['parents'][$class] as $subclass) { if(isset($_ALL_CLASSES['hastable'][$subclass])){ @@ -91,9 +96,13 @@ class ClassInfo { /** * Return the root data class for that class. * This root table has a lot of special use in the DataObject system. + * + * @param mixed $class string of the classname or instance of the class + * @return array */ static function baseDataClass($class) { global $_ALL_CLASSES; + if (is_object($class)) $class = get_class($class); reset($_ALL_CLASSES['parents'][$class]); while($val = next($_ALL_CLASSES['parents'][$class])) { if($val == 'DataObject') break; @@ -103,10 +112,14 @@ class ClassInfo { } /** - * @todo Improve documentation + * Returns a list of classes that inherit from the given class. + * + * @param mixed $class string of the classname or instance of the class + * @return array */ static function subclassesFor($class){ global $_ALL_CLASSES; + if (is_object($class)) $class = get_class($class); $subclasses = isset($_ALL_CLASSES['children'][$class]) ? $_ALL_CLASSES['children'][$class] : null; if(isset($subclasses)) array_unshift($subclasses, $class); else $subclasses[$class] = $class;