class ClassInfo (View source)

Provides introspection information about the class tree.

It's a cached wrapper around the built-in class functions. SilverStripe uses class introspection heavily and without the caching it creates an unfortunate performance hit.

Properties

Methods

public static 
allClasses()

Wrapper for classes getter.

public static 
bool
exists(string $class)

Returns true if a class or interface name exists.

public static 
hasTable($class)

No description

public static 
reset_db_cache()

No description

public static 
array
getValidSubClasses(string $class = 'SiteTree', bool $includeUnbacked = false)

Returns the manifest of all classes which are present in the database.

public static 
array
dataClassesFor(string|object $class)

Returns an array of the current class and all its ancestors and children which require a DB table.

public static 
string
baseDataClass(string|object $class)

Returns the root class (the first to extend from DataObject) for the passed class.

public static 
array
subclassesFor(mixed $class)

Returns a list of classes that inherit from the given class.

public static 
string
class_name(string|object $nameOrObject)

Convert a class name in any case and return it as it was defined in PHP

public static 
array
ancestry(string $class, bool $tablesOnly = false)

Returns the passed class name along with all its parent class names in an array, sorted with the root class first.

public static 
array
implementorsOf($interfaceName)

No description

public static 
classImplements($className, $interfaceName)

Returns true if the given class implements the given interface

public static 
array
classes_for_file(string $filePath)

Get all classes contained in a file.

public static 
array
classes_for_folder(string $folderPath)

Returns all classes contained in a certain folder.

public static 
has_method_from($class, $method, $compclass)

No description

public static 
string
table_for_object_field(string $candidateClass, string $fieldName)

Returns the table name in the class hierarchy which contains a given field column for a DataObject. If the field does not exist, this will return null.

Details

static allClasses()

Wrapper for classes getter.

static bool exists(string $class)

Returns true if a class or interface name exists.

Parameters

string $class

Return Value

bool

static hasTable($class)

No description

Move this to SS_Database or DB

Parameters

$class

static reset_db_cache()

No description

static array getValidSubClasses(string $class = 'SiteTree', bool $includeUnbacked = false)

Returns the manifest of all classes which are present in the database.

Parameters

string $class

Class name to check enum values for ClassName field

bool $includeUnbacked

Flag indicating whether or not to include types that don't exist as implemented classes. By default these are excluded.

Return Value

array

List of subclasses

static array dataClassesFor(string|object $class)

Returns an array of the current class and all its ancestors and children which require a DB table.

Move this into data object

Parameters

string|object $class

Return Value

array

static string baseDataClass(string|object $class)

Returns the root class (the first to extend from DataObject) for the passed class.

Parameters

string|object $class

Return Value

string

static array subclassesFor(mixed $class)

Returns a list of classes that inherit from the given class.

The resulting array includes the base class passed through the $class parameter as the first array value.

Example usage:

ClassInfo::subclassesFor('BaseClass');
    array(
    'BaseClass' => 'BaseClass',
    'ChildClass' => 'ChildClass',
    'GrandChildClass' => 'GrandChildClass'
)

Parameters

mixed $class

string of the classname or instance of the class

Return Value

array

Names of all subclasses as an associative array.

static string class_name(string|object $nameOrObject)

Convert a class name in any case and return it as it was defined in PHP

eg: self::class_name('dataobJEct'); //returns 'DataObject'

Parameters

string|object $nameOrObject

The classname or object you want to normalise

Return Value

string

The normalised class name

static array ancestry(string $class, bool $tablesOnly = false)

Returns the passed class name along with all its parent class names in an array, sorted with the root class first.

Parameters

string $class
bool $tablesOnly

Only return classes that have a table in the db.

Return Value

array

static array implementorsOf($interfaceName)

No description

Parameters

$interfaceName

Return Value

array

A self-keyed array of class names. Note that this is only available with Silverstripe classes and not built-in PHP classes.

static classImplements($className, $interfaceName)

Returns true if the given class implements the given interface

Parameters

$className
$interfaceName

static array classes_for_file(string $filePath)

Get all classes contained in a file.

Doesn't return additional classes that only begin with the filename, and have additional naming separated through underscores.

Parameters

string $filePath

Path to a PHP file (absolute or relative to webroot)

Return Value

array

static array classes_for_folder(string $folderPath)

Returns all classes contained in a certain folder.

Doesn't return additional classes that only begin with the filename, and have additional naming separated through underscores.

Parameters

string $folderPath

Relative or absolute folder path

Return Value

array

Array of class names

static has_method_from($class, $method, $compclass)

No description

Parameters

$class
$method
$compclass

static string table_for_object_field(string $candidateClass, string $fieldName)

Returns the table name in the class hierarchy which contains a given field column for a DataObject. If the field does not exist, this will return null.

Note: In 3.x and below this method may return 'DataObject'. From 4.0 onwards null will be returned if a field is not a member of the object.

Parameters

string $candidateClass
string $fieldName

Return Value

string