|
12 | 12 | namespace Temporal\Client; |
13 | 13 |
|
14 | 14 | use Doctrine\Common\Annotations\Reader; |
| 15 | +use JetBrains\PhpStorm\Deprecated; |
15 | 16 | use Spiral\Attributes\AnnotationReader; |
16 | 17 | use Spiral\Attributes\AttributeReader; |
17 | 18 | use Spiral\Attributes\Composite\SelectiveReader; |
|
24 | 25 | use Temporal\Client\Common\ClientContextTrait; |
25 | 26 | use Temporal\Client\Common\Paginator; |
26 | 27 | use Temporal\Client\GRPC\ServiceClientInterface; |
| 28 | +use Temporal\Client\Update\LifecycleStage; |
| 29 | +use Temporal\Client\Update\UpdateHandle; |
| 30 | +use Temporal\Client\Update\UpdateOptions; |
27 | 31 | use Temporal\Client\Workflow\CountWorkflowExecutions; |
28 | 32 | use Temporal\Client\Workflow\WorkflowExecutionHistory; |
29 | 33 | use Temporal\DataConverter\DataConverter; |
@@ -144,10 +148,7 @@ public function start($workflow, ...$args): WorkflowRunInterface |
144 | 148 | ); |
145 | 149 | } |
146 | 150 |
|
147 | | - /** |
148 | | - * @param object|WorkflowStubInterface $workflow |
149 | | - */ |
150 | | - public function startWithSignal( |
| 151 | + public function signalWithStart( |
151 | 152 | $workflow, |
152 | 153 | string $signal, |
153 | 154 | array $signalArgs = [], |
@@ -205,6 +206,50 @@ public function startWithSignal( |
205 | 206 | ); |
206 | 207 | } |
207 | 208 |
|
| 209 | + #[Deprecated(replacement: '%class%->signalWithStart(%parametersList%)')] |
| 210 | + public function startWithSignal( |
| 211 | + $workflow, |
| 212 | + string $signal, |
| 213 | + array $signalArgs = [], |
| 214 | + array $startArgs = [], |
| 215 | + ): WorkflowRunInterface { |
| 216 | + return $this->signalWithStart($workflow, $signal, $signalArgs, $startArgs); |
| 217 | + } |
| 218 | + |
| 219 | + public function updateWithStart( |
| 220 | + $workflow, |
| 221 | + string|UpdateOptions $update, |
| 222 | + array $updateArgs = [], |
| 223 | + array $startArgs = [], |
| 224 | + ): UpdateHandle { |
| 225 | + $workflow instanceof WorkflowProxy && !$workflow->hasHandler() && throw new InvalidArgumentException( |
| 226 | + 'Unable to start workflow without workflow handler', |
| 227 | + ); |
| 228 | + |
| 229 | + $update = \is_string($update) ? UpdateOptions::new($update, LifecycleStage::StageAccepted) : $update; |
| 230 | + |
| 231 | + $workflowStub = WorkflowStubConverter::fromWorkflow($workflow); |
| 232 | + |
| 233 | + $workflowType = $workflowStub->getWorkflowType() ?? throw new InvalidArgumentException( |
| 234 | + 'Unable to start untyped workflow without given workflowType', |
| 235 | + ); |
| 236 | + $workflowStub->hasExecution() and throw new InvalidArgumentException(self::ERROR_WORKFLOW_START_DUPLICATION); |
| 237 | + |
| 238 | + [$execution, $handle] = $this->getStarter()->updateWithStart( |
| 239 | + $workflowType, |
| 240 | + $workflowStub->getOptions() ?? WorkflowOptions::new(), |
| 241 | + $update, |
| 242 | + $updateArgs, |
| 243 | + $startArgs, |
| 244 | + ); |
| 245 | + |
| 246 | + $workflowStub->setExecution($execution); |
| 247 | + |
| 248 | + return $handle instanceof \Throwable |
| 249 | + ? throw $handle |
| 250 | + : $handle; |
| 251 | + } |
| 252 | + |
208 | 253 | public function newWorkflowStub( |
209 | 254 | string $class, |
210 | 255 | ?WorkflowOptions $options = null, |
|
0 commit comments