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.

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, bool $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

static array allClasses()

Wrapper for classes getter.

Return Value

array

List of all class names

static bool exists(string $class)

Returns true if a class or interface name exists.

Parameters

string $class

Return Value

bool

static bool hasTable(string $tableName)

Parameters

string $tableName

Return Value

bool

static reset_db_cache()

static array getValidSubClasses(string $class = SiteTree::class, 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 $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

static string baseDataClass(string $class) deprecated

deprecated 4.0.0:5.0.0

Parameters

string $class

Return Value

string

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

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

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

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.

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

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

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

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

static table_for_object_field($candidateClass, $fieldName) deprecated

deprecated 4.0.0:5.0.0

Parameters

$candidateClass
$fieldName

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

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

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