BUG Avoid trying to get singletons fon non-existan classes (#192)

BUG Avoid trying to get singletons for non-existant classes
This commit is contained in:
Maxime Rainville 2020-04-29 09:54:45 +12:00 committed by GitHub
parent a1d77988ce
commit 6df2a983e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 16 deletions

View File

@ -7,23 +7,16 @@ sudo: false
cache: cache:
directories: directories:
- $HOME/.composer/cache/files - $HOME/.composer/cache/files
php:
- 5.6
env:
matrix:
- PHPUNIT_TEST=1
- PHPCS_TEST=1
matrix: matrix:
include: include:
- php: 5.6 - php: 7.1
env: PHPUNIT_TEST=1 env: PHPUNIT_TEST=1
- php: 7.0 - php: 7.2
env: PHPUNIT_TEST=1
- php: 7.1.2
env: PHPUNIT_TEST=1 env: PHPUNIT_TEST=1
- php: 7.3
env: PHPUNIT_TEST=1 PHPCS_TEST=1
before_script: before_script:
- export PATH=~/.composer/vendor/bin:$PATH - export PATH=~/.composer/vendor/bin:$PATH

View File

@ -897,13 +897,13 @@ YAML;
// Try direct mapping // Try direct mapping
$class = str_replace(' ', '', ucwords($type)); $class = str_replace(' ', '', ucwords($type));
if (class_exists($class) && is_subclass_of($class, 'SilverStripe\\ORM\\DataObject')) { if (class_exists($class) && is_subclass_of($class, DataObject::class)) {
return ClassInfo::class_name($class); return ClassInfo::class_name($class);
} }
// Fall back to singular names // Fall back to singular names
foreach (array_values(ClassInfo::subclassesFor('SilverStripe\\ORM\\DataObject')) as $candidate) { foreach (array_values(ClassInfo::subclassesFor(DataObject::class)) as $candidate) {
if (strcasecmp(singleton($candidate)->singular_name(), $type) === 0) { if (class_exists($candidate) && strcasecmp(singleton($candidate)->singular_name(), $type) === 0) {
return $candidate; return $candidate;
} }
} }