mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
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
This commit is contained in:
parent
b039104acc
commit
e12f87ad38
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user