1414use Temporal \Support \Internal \Attribute \AttributeReader ;
1515use Temporal \Support \Internal \RetryOptions ;
1616use Temporal \Workflow ;
17+ use Temporal \Workflow \ActivityStubInterface ;
1718use Throwable ;
1819
1920final class ActivityStub
@@ -23,7 +24,7 @@ final class ActivityStub
2324 *
2425 * @template T of object
2526 *
26- * @param class-string<T> $class
27+ * @param class-string<T>|null $class Activity class name. When not set, an untyped activity stub is created.
2728 * @param non-empty-string|null $taskQueue
2829 * @param int<0, max>|null $retryAttempts Maximum number of attempts. When exceeded the retries stop even
2930 * if not expired yet. If not set or set to 0, it means unlimited, and rely on activity
@@ -57,10 +58,10 @@ final class ActivityStub
5758 * @param int $cancellationType Whether to wait for canceled activity to be completed (activity can be failed,
5859 * completed, cancel accepted). {@see \Temporal\Activity\ActivityCancellationType}
5960 *
60- * @return T|ActivityProxy
61+ * @return ($class is class-string ? T|ActivityProxy : ActivityStubInterface)
6162 */
6263 public static function activity (
63- string $ class ,
64+ ? string $ class = null ,
6465 ?string $ taskQueue = null ,
6566 ?int $ retryAttempts = null ,
6667 \DateInterval |string |int |null $ retryInitInterval = null ,
@@ -74,7 +75,7 @@ public static function activity(
7475 \Stringable |string |null $ activityId = null ,
7576 int $ cancellationType = 0 ,
7677 ): object {
77- $ attributes = self ::readAttributes ($ class );
78+ $ attributes = $ class !== null ? self ::readAttributes ($ class) : new AttributeCollection ([] );
7879
7980 // Retry options
8081 $ retryOptions = RetryOptions::create (
@@ -99,7 +100,9 @@ public static function activity(
99100 $ activityId === null or $ options = $ options ->withActivityId ((string )$ activityId );
100101 $ cancellationType === null or $ options = $ options ->withCancellationType ($ cancellationType );
101102
102- return Workflow::newActivityStub ($ class , $ options );
103+ return $ class === null
104+ ? Workflow::newUntypedActivityStub ($ options )
105+ : Workflow::newActivityStub ($ class , $ options );
103106 }
104107
105108 /**
0 commit comments