|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of Temporal package. |
| 5 | + * |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | + |
| 10 | +declare(strict_types=1); |
| 11 | + |
| 12 | +namespace Temporal\Interceptor; |
| 13 | + |
| 14 | +use Temporal\Interceptor\NexusOperationOutbound\GetInfoInput; |
| 15 | +use Temporal\Interceptor\Trait\NexusOperationOutboundCallsInterceptorTrait; |
| 16 | +use Temporal\Internal\Interceptor\Interceptor; |
| 17 | +use Temporal\Nexus\NexusOperationContext; |
| 18 | + |
| 19 | +/** |
| 20 | + * Intercepts calls a Nexus operation handler makes back into the Temporal APIs, |
| 21 | + * counterpart to Java's {@code NexusOperationOutboundCallsInterceptor}. |
| 22 | + * |
| 23 | + * Java additionally intercepts {@code getMetricsScope()} and {@code getWorkflowClient()}; |
| 24 | + * neither has a clean PHP handler analogue (the metrics scope is RoadRunner-owned and the |
| 25 | + * WorkflowClient is kept on the internal channel), so only {@see self::getInfo()} is exposed. |
| 26 | + * |
| 27 | + * It's recommended to use `NexusOperationOutboundCallsInterceptorTrait` when implementing this |
| 28 | + * interface because the interface might be extended in the future. The trait will provide forward |
| 29 | + * compatibility. |
| 30 | + * |
| 31 | + * ```php |
| 32 | + * class MyNexusOperationOutboundCallsInterceptor implements NexusOperationOutboundCallsInterceptor |
| 33 | + * { |
| 34 | + * use NexusOperationOutboundCallsInterceptorTrait; |
| 35 | + * |
| 36 | + * public function getInfo(GetInfoInput $input, callable $next): NexusOperationContext |
| 37 | + * { |
| 38 | + * $info = $next($input); |
| 39 | + * // observe namespace/taskQueue, e.g. attach to a span |
| 40 | + * return $info; |
| 41 | + * } |
| 42 | + * } |
| 43 | + * ``` |
| 44 | + * |
| 45 | + * @see NexusOperationOutboundCallsInterceptorTrait |
| 46 | + */ |
| 47 | +interface NexusOperationOutboundCallsInterceptor extends Interceptor |
| 48 | +{ |
| 49 | + /** |
| 50 | + * Intercepts the call to read the Nexus operation info ({@see \Temporal\Nexus\Nexus::getOperationContext()}). |
| 51 | + * |
| 52 | + * @param callable(GetInfoInput): NexusOperationContext $next |
| 53 | + */ |
| 54 | + public function getInfo(GetInfoInput $input, callable $next): NexusOperationContext; |
| 55 | +} |
0 commit comments