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 array
allClasses()

Wrapper for classes getter.

static bool
exists(string $class)

Returns true if a class or interface name exists.

static bool
hasTable(string $tableName)

No description

static 
reset_db_cache()

No description

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

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

static array
dataClassesFor(string|object $nameOrObject)

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

static string
baseDataClass(string $class) deprecated

No description

static array
subclassesFor(string|object $nameOrObject, bool $includeBaseClass = true)

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|object $nameOrObject, 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(string $interfaceName)

No description

static bool
classImplements(string $className, string $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 bool
has_method_from(string $class, string $method, string $compclass)

Determine if the given class method is implemented at the given comparison class

static 
table_for_object_field($candidateClass, $fieldName) deprecated

No description

static string
shortName(string|object $nameOrObject)

Strip namespace from class

static bool
hasMethod(object $object, string $method)

Helper to determine if the given object has a method

static array
parse_class_spec(string $classSpec)

Parses a class-spec, such as "Versioned('Stage','Live')", as passed to create_from_string().

Details

at line 66
static array allClasses()

Wrapper for classes getter.

Return Value

array List of all class names

at line 77
static bool exists(string $class)

Returns true if a class or interface name exists.

Parameters

string $class

Return Value

bool

at line 90
static bool hasTable(string $tableName)

Parameters

string $tableName

Return Value

bool

at line 99
static reset_db_cache()

at line 113
static array getValidSubClasses(string $class = SiteTree::class, 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 138
static array dataClassesFor(string|object $nameOrObject)

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

Parameters

string|object $nameOrObject Class or object instance

Return Value

array

at line 162
static string baseDataClass(string $class) deprecated

deprecated 4.0.0:5.0.0

Parameters

string $class

Return Value

string

at line 189
static array subclassesFor(string|object $nameOrObject, bool $includeBaseClass = true)

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. Note that keys are lowercase, while the values are correct case.

Example usage: ClassInfo::subclassesFor('BaseClass'); array( 'baseclass' => 'BaseClass', 'childclass' => 'ChildClass', 'grandchildclass' => 'GrandChildClass' )

Parameters

string|object $nameOrObject The classname or object
bool $includeBaseClass Whether to include the base class or not. Defaults to true.

Return Value

array List of class names with lowercase keys and correct-case values

Exceptions

ReflectionException

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

Exceptions

ReflectionException

at line 246
static array ancestry(string|object $nameOrObject, 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|object $nameOrObject Class or object instance
bool $tablesOnly Only return classes that have a table in the db.

Return Value

array List of class names with lowercase keys and correct-case values

at line 276
static array implementorsOf(string $interfaceName)

Parameters

string $interfaceName

Return Value

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

at line 288
static bool classImplements(string $className, string $interfaceName)

Returns true if the given class implements the given interface

Parameters

string $className
string $interfaceName

Return Value

bool

at line 301
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 Map of lowercase class names to correct class name

at line 324
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 Map of lowercase class names to correct class name

at line 349
static bool has_method_from(string $class, string $method, string $compclass)

Determine if the given class method is implemented at the given comparison class

Parameters

string $class Class to get methods from
string $method Method name to lookup
string $compclass Parent class to test if this is the implementor

Return Value

bool True if $class::$method is declared in $compclass

at line 375
static table_for_object_field($candidateClass, $fieldName) deprecated

deprecated 4.0.0:5.0.0

Parameters

$candidateClass
$fieldName

at line 387
static string shortName(string|object $nameOrObject)

Strip namespace from class

Parameters

string|object $nameOrObject Name of class, or instance

Return Value

string Name of class without namespace

at line 401
static bool hasMethod(object $object, string $method)

Helper to determine if the given object has a method

Parameters

object $object
string $method

Return Value

bool

at line 420
static array parse_class_spec(string $classSpec)

Parses a class-spec, such as "Versioned('Stage','Live')", as passed to create_from_string().

Returns a 2-element array, with classname and arguments

Parameters

string $classSpec

Return Value

array

Exceptions

Exception