class ClassInfo

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.

Methods

static 
allClasses()

Wrapper for classes getter.

static bool
exists(string $class)

Returns true if a class or interface name exists.

static 
hasTable($class)

No description

static 
reset_db_cache()

No description

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

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

static array
dataClassesFor(string|object $class)

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

static string
baseDataClass(string|object $class)

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

static array
subclassesFor(mixed $class)

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

static string
class_name(string|object $nameOrObject)

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

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.

static array
implementorsOf($interfaceName)

No description

static 
classImplements($className, $interfaceName)

Returns true if the given class implements the given interface

static array
classes_for_file(string $filePath)

Get all classes contained in a file.

static array
classes_for_folder(string $folderPath)

Returns all classes contained in a certain folder.

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

No description

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 {@link DataObject}. If the field does not exist, this will return null.

Details

at line 18
static allClasses()

Wrapper for classes getter.

at line 28
static bool exists(string $class)

Returns true if a class or interface name exists.

Parameters

string $class

Return Value

bool

at line 45
static hasTable($class)

Parameters

$class

at line 53
static reset_db_cache()

at line 66
static array getValidSubClasses(string $class = 'SiteTree', boolean $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
boolean $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

at line 83
static array dataClassesFor(string|object $class)

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

Parameters

string|object $class

Return Value

array

at line 109
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

at line 145
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.

at line 169
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

at line 193
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

at line 219
static array implementorsOf($interfaceName)

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.

at line 226
static classImplements($className, $interfaceName)

Returns true if the given class implements the given interface

Parameters

$className
$interfaceName

at line 240
static array classes_for_file(string $filePath)

Get all classes contained in a file.

Parameters

string $filePath Path to a PHP file (absolute or relative to webroot)

Return Value

array

at line 261
static array classes_for_folder(string $folderPath)

Returns all classes contained in a certain folder.

Parameters

string $folderPath Relative or absolute folder path

Return Value

array Array of class names

at line 275
static has_method_from($class, $method, $compclass)

Parameters

$class
$method
$compclass

at line 309
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 {@link 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