1717use Temporal \DataConverter \Type ;
1818use Temporal \DataConverter \ValuesInterface ;
1919use Temporal \Exception \OutOfContextException ;
20+ use Temporal \Internal \Activity \ActivityContext ;
2021use Temporal \Internal \Support \Facade ;
2122
22- /**
23- * @template-extends Facade<ActivityContextInterface>
24- */
2523final class Activity extends Facade
2624{
25+ /**
26+ * Get the current Activity context.
27+ * @throws OutOfContextException
28+ */
29+ public static function getCurrentContext (): ActivityContextInterface
30+ {
31+ $ ctx = parent ::getCurrentContext ();
32+ /** @var ActivityContext $ctx */
33+ $ ctx ::class === ActivityContext::class or throw new OutOfContextException (
34+ 'The Activity facade can only be used in the context of an activity execution. ' ,
35+ );
36+ return $ ctx ;
37+ }
38+
2739 /**
2840 * Returns information about current activity execution.
2941 *
3042 * @throws OutOfContextException in the absence of the activity execution context.
3143 */
3244 public static function getInfo (): ActivityInfo
3345 {
34- /** @var ActivityContextInterface $context */
3546 $ context = self ::getCurrentContext ();
3647
3748 return $ context ->getInfo ();
@@ -57,7 +68,6 @@ public static function getInfo(): ActivityInfo
5768 */
5869 public static function getInput (): ValuesInterface
5970 {
60- /** @var ActivityContextInterface $context */
6171 $ context = self ::getCurrentContext ();
6272
6373 return $ context ->getInput ();
@@ -72,7 +82,6 @@ public static function getInput(): ValuesInterface
7282 */
7383 public static function hasHeartbeatDetails (): bool
7484 {
75- /** @var ActivityContextInterface $context */
7685 $ context = self ::getCurrentContext ();
7786
7887 return $ context ->hasHeartbeatDetails ();
@@ -88,7 +97,6 @@ public static function hasHeartbeatDetails(): bool
8897 */
8998 public static function getHeartbeatDetails ($ type = null ): mixed
9099 {
91- /** @var ActivityContextInterface $context */
92100 $ context = self ::getCurrentContext ();
93101
94102 return $ context ->getLastHeartbeatDetails ($ type );
@@ -101,7 +109,6 @@ public static function getHeartbeatDetails($type = null): mixed
101109 */
102110 public static function getCancellationDetails (): ?ActivityCancellationDetails
103111 {
104- /** @var ActivityContextInterface $context */
105112 $ context = self ::getCurrentContext ();
106113
107114 return $ context ->getCancellationDetails ();
@@ -118,7 +125,6 @@ public static function getCancellationDetails(): ?ActivityCancellationDetails
118125 */
119126 public static function doNotCompleteOnReturn (): void
120127 {
121- /** @var ActivityContextInterface $context */
122128 $ context = self ::getCurrentContext ();
123129
124130 $ context ->doNotCompleteOnReturn ();
@@ -150,7 +156,6 @@ public static function doNotCompleteOnReturn(): void
150156 */
151157 public static function heartbeat ($ details ): void
152158 {
153- /** @var ActivityContextInterface $context */
154159 $ context = self ::getCurrentContext ();
155160
156161 $ context ->heartbeat ($ details );
@@ -161,7 +166,6 @@ public static function heartbeat($details): void
161166 */
162167 public static function getInstance (): object
163168 {
164- /** @var ActivityContextInterface $context */
165169 $ context = self ::getCurrentContext ();
166170
167171 return $ context ->getInstance ();
0 commit comments