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

public static 
array
allClasses()

Wrapper for classes getter.

public static 
bool
exists(string $class)

Returns true if a class or interface name exists.

public static 
bool
hasTable(string $tableName)

No description

public static 
reset_db_cache()

No description

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

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

public static 
array
dataClassesFor(string|object $nameOrObject)

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

public static 
string
baseDataClass(string $class) deprecated

No description

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

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|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.

public static 
array
implementorsOf(string $interfaceName)

No description

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

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

public static 
table_for_object_field($candidateClass, $fieldName) deprecated

No description

public static 
string
shortName(string|object $nameOrObject)

Strip namespace from class

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

Helper to determine if the given object has a method

public static 
array
parse_class_spec(string $classSpec)

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

public static 
array
classesWithExtension(string $extensionClass, string $baseClassOrObject = DataObject::class, bool $includeBaseClass = false)

Returns a list of classes with a particular extension applied

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)

No description

Move this to SS_Database or DB

Parameters

string $tableName

Return Value

bool

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.

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.

Move this into {@see \SilverStripe\Core\DataObjectSchema}

Parameters

string|object $nameOrObject

Class or object instance

Return Value

array

static string baseDataClass(string $class) deprecated

deprecated 4.0.1 Use DataObject::getSchema()->baseDataClass()

No description

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)

No description

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.1 Use DataObject::getSchema()->tableForField()

No description

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

static array classesWithExtension(string $extensionClass, string $baseClassOrObject = DataObject::class, bool $includeBaseClass = false)

Returns a list of classes with a particular extension applied

This reflects all extensions added (or removed) both via the configuration API as well as dynamically using Extensible::add_extension() and Extensible::remove_extension().

Parameters

string $extensionClass

Extension class name

string $baseClassOrObject

Class or object to find subclasses of with the extension applied

bool $includeBaseClass

Include the base class itself if it has the extension applied?

Return Value

array

Class names with the extension applied

Exceptions

ReflectionException