diff --git a/typo3/sysext/extbase/Classes/Reflection/ReflectionService.php b/typo3/sysext/extbase/Classes/Reflection/ReflectionService.php index 400a3c9978d7fda6a277201238a154c2a00632ff..b6ecbfdb99cb6398c463cef9621c4ae0de276d87 100644 --- a/typo3/sysext/extbase/Classes/Reflection/ReflectionService.php +++ b/typo3/sysext/extbase/Classes/Reflection/ReflectionService.php @@ -61,14 +61,14 @@ class ReflectionService implements SingletonInterface * * @param CacheManager $cacheManager */ - public function __construct(\TYPO3\CMS\Core\Cache\CacheManager $cacheManager = null) + public function __construct(CacheManager $cacheManager = null) { if ($cacheManager instanceof CacheManager && $cacheManager->hasCache(static::CACHE_IDENTIFIER)) { $this->cachingEnabled = true; $this->dataCache = $cacheManager->getCache(static::CACHE_IDENTIFIER); - if (($classSchemata = $this->dataCache->has(static::CACHE_ENTRY_IDENTIFIER)) !== false) { - $this->classSchemata = $this->dataCache->get(static::CACHE_ENTRY_IDENTIFIER); + if (($classSchemata = $this->dataCache->get(static::CACHE_ENTRY_IDENTIFIER)) !== false) { + $this->classSchemata = $classSchemata; } } } @@ -112,7 +112,7 @@ class ReflectionService implements SingletonInterface return []; } - return $classSchema->getTags()[$tag]; + return $classSchema->getTags()[$tag] ?? []; } /** @@ -183,7 +183,7 @@ class ReflectionService implements SingletonInterface return []; } - return $classSchema->getMethod($methodName)['tags']; + return $classSchema->getMethod($methodName)['tags'] ?? []; } /** @@ -202,7 +202,7 @@ class ReflectionService implements SingletonInterface return []; } - return $classSchema->getMethod($methodName)['params']; + return $classSchema->getMethod($methodName)['params'] ?? []; } /** @@ -220,9 +220,7 @@ class ReflectionService implements SingletonInterface return []; } - $propertyDefinition = $classSchema->getProperty($propertyName); - - return isset($propertyDefinition['tags']) ? $propertyDefinition['tags'] : []; + return $classSchema->getProperty($propertyName)['tags'] ?? []; } /** @@ -235,11 +233,13 @@ class ReflectionService implements SingletonInterface */ public function getPropertyTagValues($className, $propertyName, $tag): array { - if (!$this->isPropertyTaggedWith($className, $propertyName, $tag)) { + try { + $classSchema = $this->getClassSchema($className); + } catch (\Exception $e) { return []; } - return $this->getClassSchema($className)->getProperty($propertyName)['tags'][$tag]; + return $classSchema->getProperty($propertyName)['tags'][$tag] ?? []; } /** @@ -297,15 +297,14 @@ class ReflectionService implements SingletonInterface * @param string $className * @throws Exception\UnknownClassException * @return ClassSchema The class schema - * @throws \ReflectionException */ protected function buildClassSchema($className): ClassSchema { - if (!class_exists($className)) { - throw new Exception\UnknownClassException('The classname "' . $className . '" was not found and thus can not be reflected.', 1278450972); + try { + $classSchema = new ClassSchema($className); + } catch (\ReflectionException $e) { + throw new Exception\UnknownClassException('The classname "' . $className . '" was not found and thus can not be reflected.', 1278450972, $e); } - - $classSchema = new ClassSchema($className); $this->classSchemata[$className] = $classSchema; $this->dataCacheNeedsUpdate = true; return $classSchema; diff --git a/typo3/sysext/extbase/Tests/Unit/Reflection/ReflectionServiceTest.php b/typo3/sysext/extbase/Tests/Unit/Reflection/ReflectionServiceTest.php index 538ef662fe1e55585e75b4b344502e76ae1d848f..680741acc6c863a17800b6f1a7df8d2c5de55d09 100644 --- a/typo3/sysext/extbase/Tests/Unit/Reflection/ReflectionServiceTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Reflection/ReflectionServiceTest.php @@ -70,6 +70,11 @@ class ReflectionServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCa 'test for reflection', ], $classValues); + $this->assertEquals( + [], + $service->getClassTagValues(static::class, 'nonExistantTag') + ); + $this->assertEquals( [], $service->getClassTagValues('NonExistantNamespace\\NonExistantClass', 'nonExistantTag') @@ -99,6 +104,11 @@ class ReflectionServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCa 'return' => ['string'] ], $tagsValues); + $this->assertEquals( + [], + $service->getMethodTagsValues(static::class, 'notExistentMethod') + ); + $this->assertEquals( [], $service->getMethodTagsValues('NonExistantNamespace\\NonExistantClass', 'notExistentMethod') @@ -129,6 +139,11 @@ class ReflectionServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCa ] ], $parameters); + $this->assertSame( + [], + $service->getMethodParameters(static::class, 'notExistentMethod') + ); + $this->assertSame( [], $service->getMethodParameters('NonExistantNamespace\\NonExistantClass', 'notExistentMethod')