Skip to content

Commit 8222f5d

Browse files
Handle standalone type registry config fallback
1 parent 0c87020 commit 8222f5d

2 files changed

Lines changed: 43 additions & 5 deletions

File tree

src/V2/Support/TypeRegistry.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public static function validateTypeMap(): void
137137
'activities' => Activity::class,
138138
] as $configKey => $baseClass) {
139139
/** @var array<string, class-string>|null $types */
140-
$types = config("workflows.v2.types.{$configKey}");
140+
$types = self::configuredTypeMap($configKey);
141141

142142
if (! is_array($types) || $types === []) {
143143
continue;
@@ -194,7 +194,7 @@ public static function validateTypeMap(): void
194194
private static function isRegisteredTypeKey(string $key): bool
195195
{
196196
foreach (['workflows', 'activities'] as $section) {
197-
$types = config("workflows.v2.types.{$section}");
197+
$types = self::configuredTypeMap($section);
198198
if (is_array($types) && array_key_exists($key, $types)) {
199199
return true;
200200
}
@@ -216,7 +216,7 @@ private static function configuredTypeForClass(string $class): ?string
216216
}
217217

218218
/** @var array<string, class-string>|null $types */
219-
$types = config("workflows.v2.types.{$configKey}");
219+
$types = self::configuredTypeMap($configKey);
220220

221221
if (! is_array($types)) {
222222
return null;
@@ -237,7 +237,7 @@ private static function configuredClassForType(string $type, string $configKey,
237237
// so that dotted durable type keys like "tests.external-greeting-workflow"
238238
// are matched as flat array keys instead of being interpreted as nested
239239
// config paths by Laravel's dot-notation config helper.
240-
$types = config("workflows.v2.types.{$configKey}");
240+
$types = self::configuredTypeMap($configKey);
241241

242242
if (! is_array($types)) {
243243
return null;
@@ -267,7 +267,7 @@ private static function configuredClassForType(string $type, string $configKey,
267267
private static function configuredThrowableClassAlias(string $storedClass): ?string
268268
{
269269
/** @var array<string, class-string>|null $aliases */
270-
$aliases = config('workflows.v2.types.exception_class_aliases');
270+
$aliases = self::configuredTypeMap('exception_class_aliases');
271271

272272
if (! is_array($aliases)) {
273273
return null;
@@ -324,4 +324,27 @@ private static function isValidClass(string $class, string $expectedBaseClass):
324324
{
325325
return class_exists($class) && is_subclass_of($class, $expectedBaseClass);
326326
}
327+
328+
/**
329+
* Standalone workers can use the type registry outside a booted Laravel
330+
* app, so missing config bindings must degrade to an empty type map rather
331+
* than crashing replay-time exception restoration.
332+
*
333+
* @return array<string, class-string>|null
334+
*/
335+
private static function configuredTypeMap(string $configKey): ?array
336+
{
337+
$types = self::configValue("workflows.v2.types.{$configKey}");
338+
339+
return is_array($types) ? $types : null;
340+
}
341+
342+
private static function configValue(string $key): mixed
343+
{
344+
try {
345+
return config($key);
346+
} catch (Throwable) {
347+
return null;
348+
}
349+
}
327350
}

tests/Unit/V2/TypeRegistryTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,19 @@ public function testResolveThrowableClassReturnsNullWhenUnresolvable(): void
301301

302302
$this->assertNull(TypeRegistry::resolveThrowableClass('App\\Missing\\Exception', null));
303303
}
304+
305+
public function testResolveThrowableClassFallsBackToRecordedClassWithoutConfigBinding(): void
306+
{
307+
$config = $this->app->make('config');
308+
unset($this->app['config']);
309+
310+
try {
311+
$this->assertSame(
312+
\RuntimeException::class,
313+
TypeRegistry::resolveThrowableClass(\RuntimeException::class, 'external.python-failure'),
314+
);
315+
} finally {
316+
$this->app->instance('config', $config);
317+
}
318+
}
304319
}

0 commit comments

Comments
 (0)