27
27
use Temporal \Workflow \WorkflowInit ;
28
28
use Temporal \Workflow \WorkflowInterface ;
29
29
use Temporal \Workflow \WorkflowMethod ;
30
+ use Temporal \Workflow \WorkflowVersioningBehavior ;
30
31
31
32
/**
32
33
* @template-extends Reader<WorkflowPrototype>
@@ -292,14 +293,16 @@ private function getAttributedMethod(ClassNode $graph, \ReflectionMethod $handle
292
293
}
293
294
294
295
/**
296
+ * Walk through the method hierarchy and build the prototype for the workflow method.
297
+ *
295
298
* @throws \ReflectionException
296
299
*/
297
300
private function getPrototype (ClassNode $ graph , \ReflectionMethod $ handler ): ?WorkflowPrototype
298
301
{
299
- $ cronSchedule = $ previousRetry = $ prototype = $ returnType = null ;
302
+ $ cronSchedule = $ previousRetry = $ prototype = $ returnType = $ versionBehavior = null ;
300
303
304
+ /** @var \Traversable<class-string, \ReflectionMethod> $group */
301
305
foreach ($ graph ->getMethods ($ handler ->getName ()) as $ group ) {
302
- //
303
306
$ contextualRetry = $ previousRetry ;
304
307
305
308
foreach ($ group as $ method ) {
@@ -326,6 +329,11 @@ private function getPrototype(ClassNode $graph, \ReflectionMethod $handler): ?Wo
326
329
?? $ returnType
327
330
;
328
331
332
+ // Version Behavior
333
+ $ versionBehavior = $ this ->reader ->firstFunctionMetadata ($ method , WorkflowVersioningBehavior::class)
334
+ ?? $ versionBehavior
335
+ ;
336
+
329
337
//
330
338
// In the future, workflow methods are available only in
331
339
// those classes that contain the attribute:
@@ -347,27 +355,18 @@ private function getPrototype(ClassNode $graph, \ReflectionMethod $handler): ?Wo
347
355
}
348
356
}
349
357
350
- // In case
358
+ // Skip if no interface found
351
359
if ($ interface === null ) {
352
360
continue ;
353
361
}
354
362
355
363
\assert ($ context !== null );
356
- if ($ prototype === null ) {
357
- $ prototype = $ this ->findProto ($ handler , $ method , $ context , $ graph ->getReflection ());
358
- }
359
-
360
- if ($ prototype !== null && $ retry !== null ) {
361
- $ prototype ->setMethodRetry ($ retry );
362
- }
363
-
364
- if ($ prototype !== null && $ cronSchedule !== null ) {
365
- $ prototype ->setCronSchedule ($ cronSchedule );
366
- }
364
+ $ prototype ??= $ this ->findProto ($ handler , $ method , $ context , $ graph ->getReflection ());
367
365
368
- if ($ prototype !== null && $ returnType !== null ) {
369
- $ prototype ->setReturnType ($ returnType );
370
- }
366
+ $ retry === null or $ prototype ?->setMethodRetry($ retry );
367
+ $ cronSchedule === null or $ prototype ?->setCronSchedule($ cronSchedule );
368
+ $ returnType === null or $ prototype ?->setReturnType($ returnType );
369
+ $ versionBehavior === null or $ prototype ?->setVersioningBehavior($ versionBehavior ->value );
371
370
}
372
371
373
372
$ previousRetry = $ contextualRetry ;
0 commit comments