mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #4482 from kinglozzer/classinfo-nonexistant-class
Ensure ClassInfo is backwards compatible with non-existant classes
This commit is contained in:
commit
5c3bf3d0a2
@ -159,6 +159,13 @@ class ClassInfo {
|
||||
public static function class_name($nameOrObject) {
|
||||
if (is_object($nameOrObject)) {
|
||||
return get_class($nameOrObject);
|
||||
} elseif (!self::exists($nameOrObject)) {
|
||||
Deprecation::notice(
|
||||
'4.0',
|
||||
"ClassInfo::class_name() passed a class that doesn't exist. Support for this will be removed in 4.0",
|
||||
Deprecation::SCOPE_GLOBAL
|
||||
);
|
||||
return $nameOrObject;
|
||||
}
|
||||
$reflection = new ReflectionClass($nameOrObject);
|
||||
return $reflection->getName();
|
||||
|
@ -42,6 +42,15 @@ class ClassInfoTest extends SapphireTest {
|
||||
);
|
||||
}
|
||||
|
||||
public function testClassName() {
|
||||
$this->assertEquals('ClassInfoTest', ClassInfo::class_name($this));
|
||||
$this->assertEquals('ClassInfoTest', ClassInfo::class_name('ClassInfoTest'));
|
||||
$this->assertEquals('ClassInfoTest', ClassInfo::class_name('CLaSsInfOTEsT'));
|
||||
|
||||
// This is for backwards compatiblity and will be removed in 4.0
|
||||
$this->assertEquals('IAmAClassThatDoesNotExist', ClassInfo::class_name('IAmAClassThatDoesNotExist'));
|
||||
}
|
||||
|
||||
public function testClassesForFolder() {
|
||||
//$baseFolder = Director::baseFolder() . '/' . FRAMEWORK_DIR . '/tests/_ClassInfoTest';
|
||||
//$manifestInfo = ManifestBuilder::get_manifest_info($baseFolder);
|
||||
|
Loading…
Reference in New Issue
Block a user