Skip to content

Commit 1ac4ce7

Browse files
committed
Fix ReflectionUnionType handling in SlideFactory
Handle union types (e.g., callable|array) properly when using reflection to inspect constructor parameters. ReflectionUnionType doesn't have a getName() method, so we check if the type is ReflectionNamedType first.
1 parent 72fb012 commit 1ac4ce7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Support/SlideFactory.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,18 @@ public static function create(string $slideClass, array $data): BaseSlide
3737
$args = [];
3838
foreach ($params as $param) {
3939
$paramName = $param->getName();
40-
$paramType = $param->getType()?->getName();
40+
$reflectionType = $param->getType();
41+
42+
// Get type name, handling union types
43+
$paramType = null;
44+
if ($reflectionType instanceof \ReflectionNamedType) {
45+
$paramType = $reflectionType->getName();
46+
}
47+
// For union types (e.g., callable|array), we can't get a single type name
48+
// so we'll just leave $paramType as null and skip type-specific handling
4149

4250
// Special handling for ChartComponent parameters
43-
if ($paramType === ChartComponent::class || is_subclass_of($paramType, ChartComponent::class)) {
51+
if ($paramType && ($paramType === ChartComponent::class || is_subclass_of($paramType, ChartComponent::class))) {
4452
// Handle multiple chart parameters using naming convention
4553
// e.g., leftChart -> leftChartType + leftChartData
4654
$chartTypeKey = $paramName.'Type';

0 commit comments

Comments
 (0)